1 " Commenting of lines! Stolen & modified from vim.org's ToggleCommentify
2 map <C-_> :call ToggleCommentify()<CR>j
3 imap <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 = {
70 for commentChar in keys(commentMapping)
71 for name in commentMapping[commentChar]
73 let commentSymbol = commentChar
78 if commentSymbol == ''
79 execute 'echo "ToggleCommentify has not (yet) been implemented for the file-type " . &filetype'
81 if isCommented == commentSymbol
82 " if the line is already commented, uncomment
83 call UnCommentify(commentSymbol)
85 " if the line is uncommented, comment
86 call Commentify(commentSymbol)
91 function! Commentify(commentSymbol)
92 execute ':s+^+'.a:commentSymbol.'+'
96 function! UnCommentify(commentSymbol)
97 execute ':s+'.a:commentSymbol.'++'