-
-
Save Raimondi/6750062 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Toggle Comment | |
augroup toggle_comment | |
au FileType vim let b:comment_leader = '" ' | |
au FileType c,cpp,java let b:comment_leader = '// ' | |
au FileType sh,make,python let b:comment_leader = '# ' | |
au FileType text let b:comment_leader = '% ' | |
augroup END | |
function! ToggleComment() range | |
let cl = b:comment_leader; | |
for linenr in range(a:firstline, a:lastline) | |
let line = getline(linenr) | |
if line =~? '^\s*' . cl | |
execute linenr . 's/^\(\s*\)' . escape(cl, '/') . '/\1/' | |
else | |
execute linenr . 's/^\(\s*\)/\=submatch(1) . printf( "%s", cl)/' | |
endif | |
endfor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment