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
5 " block to comment ... just keep the CTRL-key pressed down and tap on 'c' as
8 function! ToggleCommentify()
9 let lineString = getline(".")
10 if strlen(lineString) == 0
11 " don't comment empty lines
15 let isCommented = strpart(lineString,0,3)
16 let commentSymbol = ''
18 let commentMapping = {
69 for commentChar in keys(commentMapping)
70 for name in commentMapping[commentChar]
72 let commentSymbol = commentChar
77 if commentSymbol == ''
78 execute 'echo "ToggleCommentify has not (yet) been implemented for the file-type " . &filetype'
80 if isCommented == commentSymbol
81 " if the line is already commented, uncomment
82 call UnCommentify(commentSymbol)
84 " if the line is uncommented, comment
85 call Commentify(commentSymbol)
90 function! Commentify(commentSymbol)
91 execute ':s+^+'.a:commentSymbol.'+'
95 function! UnCommentify(commentSymbol)
96 execute ':s+'.a:commentSymbol.'++'