1 " Commenting of lines! Stolen & modified from vim.org's ToggleCommentify
2 map <C-c> :call ToggleCommentify()<CR>j
3 imap <C-c> <ESC>:call ToggleCommentify()<CR>j
4 " The nice thing about these mapping is that you don't have to select a visual block to comment
5 " ... just keep the CTRL-key pressed down and tap on 'c' as often as you need.
7 function! ToggleCommentify()
8 let lineString = getline(".")
9 if lineString != $ " don't comment empty lines
10 let isCommented = strpart(lineString,0,3) " getting the first 3 symbols
11 let commentSymbol = ''
13 let commentMapping = {
14 \'###': ['python', 'sh', 'muttrc', 'sshconfig', 'make'],
15 \'///': ['ox', 'java', 'cpp', 'c', 'php'],
20 for commentChar in keys(commentMapping)
21 for name in commentMapping[commentChar]
23 let commentSymbol = commentChar
28 if commentSymbol == ''
29 execute 'echo "ToggleCommentify has not (yet) been implemented for the file-type " . &filetype'
31 if isCommented == commentSymbol
32 call UnCommentify(commentSymbol) " if the line is already commented, uncomment
34 call Commentify(commentSymbol) " if the line is uncommented, comment
40 function! Commentify(commentSymbol)
41 execute ':s+^+'.a:commentSymbol.'+'
45 function! UnCommentify(commentSymbol)
46 execute ':s+'.a:commentSymbol.'++'