summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.vimrc26
1 files changed, 26 insertions, 0 deletions
diff --git a/.vimrc b/.vimrc
index 1483d5c..88288c1 100644
--- a/.vimrc
+++ b/.vimrc
@@ -49,6 +49,32 @@ if !exists(":DiffOrig")
\ | wincmd p | diffthis
endif
+" Comment out a visual block
+function CommentLines()
+ execute ":s@^@".g:StartComment." @g"
+ "execute ":s@^\\(\\s*\\)@\\1".g:StartComment." @g"
+
+ execute ":s@$@ ".g:EndComment."@g"
+endfunction
+
+" Uncomment a visual block
+function UncommentLines()
+ execute ":s@^".g:StartComment." @\@g"
+ "execute ":s@^\\(\\s*\\)".g:StartComment." @\\1@g"
+
+ execute ":s@ ".g:EndComment."$@@g"
+endfunction
+
+" Set comment characters for common languages
+autocmd FileType python,sh,bash,zsh,ruby,perl let StartComment="#" | let EndComment=""
+autocmd FileType html let StartComment="<!--" | let EndComment="-->"
+autocmd FileType php,c,javascript let StartComment="//" | let EndComment=""
+autocmd FileType cpp let StartComment="/*" | let EndComment="*/"
+autocmd FileType vim let StartComment="\"" | let EndComment=""
+
+vmap <C-c> :call CommentLines()<cr>
+vmap <C-u> :call UncommentLines()<cr>
+
set runtimepath+=/usr/share/vim
"inoremap <tab> <c-n>