Created
February 24, 2012 16:31
-
-
Save gamefreak/1901886 to your computer and use it in GitHub Desktop.
commentify
This file contains 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
nmap <silent> <leader>/ :call Commentify()<cr> | |
vmap <silent> <leader>/ :call Commentify()<cr> | |
"Commentify config | |
if !exists("b:commentType") | |
let b:commentType="#" | |
endif | |
augroup Commentify | |
autocmd! BufNewFile,BufRead *.sage setf python | |
autocmd! FileType c,h,cpp,java,javascript,php,objc,objcpp let b:commentType="//" | |
autocmd! FileType lua,sql,haskell let b:commentType="--" | |
autocmd! FileType bash,sh,shell,perl,python,ruby let b:commentType="#" | |
autocmd! FileType vim,vimrc let b:commentType="\"" | |
autocmd! FileType asm,lisp let b:commentType=";" | |
augroup END | |
function! Commentify() | |
if getline(".") =~ "^\\s*" . b:commentType . ".*" | |
execute 's@' . b:commentType . '@@' | |
"REMOVE | |
normal! `` | |
"don't define a 3 character comment | |
if len(b:commentType) == 2 | |
normal! 2h | |
else | |
normal! h | |
endif | |
else | |
substitute/^/\=b:commentType/ "ADD | |
normal! `` | |
if len(b:commentType) == 2 | |
normal! 2l | |
else | |
normal! l | |
endif | |
endif | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment