function! ToggleComment()
  let s:commentChar = '#'
  if &filetype == 'cpp' || &filetype == 'h' 
    let s:commentChar = '//'
  elseif &filetype == 'py'
    let s:commentChar = '#'
  elseif &filetype == 'vim'
    let s:commentChar = '"'
  endif
  
  let currentLine = getline('.')
  let variablePattern = '^\s*\V\k\+\>'
  let s:isCommentLine = !(match(currentLine, variablePattern) != -1)
  let s:isEmpty = (currentLine == '')

  if s:isEmpty
    echo "empty line"
    return
  elseif s:isCommentLine
    echo "uncomment"
    execute 's/^[ ]*' . escape(s:commentChar, '\/')
  else
    echo "comment"
    execute 's/^/' . escape(s:commentChar, '\/')
  endif
endfunction
