summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitsuo Tokumori <[email protected]>2022-09-13 16:34:45 -0500
committerMitsuo Tokumori <[email protected]>2022-09-13 16:34:45 -0500
commit6364658da063381339b32b51af13229cbfab310d (patch)
treecee1ba934aae2e79e25e0ac3b4f191483e9aa466
parent9047154ea855c7afa6881f62a39e39e6b834b107 (diff)
downloaddotfiles-6364658da063381339b32b51af13229cbfab310d.tar.gz
dotfiles-6364658da063381339b32b51af13229cbfab310d.tar.bz2
dotfiles-6364658da063381339b32b51af13229cbfab310d.zip
Add Comment and UnComment mappings
-rw-r--r--vim/vimrc15
1 files changed, 15 insertions, 0 deletions
diff --git a/vim/vimrc b/vim/vimrc
index 415212e..7156c73 100644
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -201,6 +201,21 @@ nnoremap gJ :%!python3 -m json.tool<CR>
" NERDTree plugin
nnoremap <C-t> :NERDTreeToggle<CR>
+" Comment/UnComment lines
+" Ref.:
+" - https://vim.fandom.com/wiki/Comment/UnComment_visually_selected_text
+" - https://stackoverflow.com/a/1676672/7498073
+" - https://stackoverflow.com/a/9051932/7498073
+au FileType haskell,vhdl,ada let b:comment_leader = '-- '
+au FileType vim let b:comment_leader = '" '
+au FileType c,cpp,java let b:comment_leader = '// '
+au FileType sh,make let b:comment_leader = '# '
+au FileType tex let b:comment_leader = '% '
+" That c_CTRL-R_= thingy enters the "expression register". And that \V
+" tells :s to go into "Very NonMagic" mode.
+noremap ,c :s/^/<C-R>=escape(b:comment_leader,'\/')<CR>/<CR>:noh<CR>
+noremap ,u :s/^\V<C-R>=escape(b:comment_leader,'\/')<CR>//e<CR>:noh<CR>
+
" Yanking and pasting
" ----------------------------------------------------------------------