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 = {
71 for commentChar in keys(commentMapping)
72 for name in commentMapping[commentChar]
74 let commentSymbol = commentChar
79 if commentSymbol == ''
80 execute 'echo "ToggleCommentify has not (yet) been implemented for the file-type " . &filetype'
82 if isCommented == commentSymbol
83 " if the line is already commented, uncomment
84 call UnCommentify(commentSymbol)
86 " if the line is uncommented, comment
87 call Commentify(commentSymbol)
92 function! Commentify(commentSymbol)
93 execute ':s+^+'.a:commentSymbol.'+'
97 function! UnCommentify(commentSymbol)
98 execute ':s+'.a:commentSymbol.'++'