From 82116a8c1ae63ed76863651aa9fe4058a0e517f5 Mon Sep 17 00:00:00 2001 From: Pavel Lutskov Date: Wed, 11 Apr 2018 11:15:30 +0200 Subject: [PATCH] custom comment char support Signed-off-by: Pavel Lutskov --- plugin/comment.vim | 31 ++++++++++++++++++++----------- plugin/settings.vim | 20 +++++++++++--------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/plugin/comment.vim b/plugin/comment.vim index 9e80a31..0ad1398 100644 --- a/plugin/comment.vim +++ b/plugin/comment.vim @@ -1,4 +1,4 @@ -let s:comment_filetype_map = { +let s:comment_map = { \ 'c': '\/\/', \ 'cpp': '\/\/', \ 'java': '\/\/', @@ -6,10 +6,11 @@ let s:comment_filetype_map = { \ 'python': '#', \ 'vim': '"', \ 'tex': '%', + \ 'plaintex': '%', \ 'sh': '#' \ } -let s:block_filetype_map = { +let s:block_map = { \ 'c': ['\/\*', '\*\/'], \ 'java': ['\/\*', '\*\/'], \ 'cpp': ['\/\*', '\*\/'], @@ -18,21 +19,29 @@ let s:block_filetype_map = { \ } function! MyCommenter(uncomment) range - let comment = get(s:comment_filetype_map, &ft, '') + let comment = get(s:comment_map, &ft, '') + if exists('g:custom_comment_map') + let comment = get(g:custom_comment_map, &ft, '') + endif if !len(comment) return endif let search_range = a:firstline . ',' . a:lastline + + " Uncomment the line (when commenting this avoids multiple comment chars) + execute search_range . 's/\(^\s*\)\(' . comment . '\s*\)\+/\1/e' if !a:uncomment + " Comment execute search_range . 's/\(^\s*\)\(\S\)/\1' . comment . ' \2/e' - else - execute search_range . 's/\(^\s*\)' . comment . '\s*/\1/e' endif nohl endfunction function! MyBlocker(unblock) range - let block = get(s:block_filetype_map, &ft, []) + let block = get(s:block_map, &ft, []) + if exists('g:custom_block_map') + let block = get(g:custom_block_map, &ft, []) + endif if !len(block) return endif @@ -45,10 +54,10 @@ function! MyBlocker(unblock) range execute 'normal! ?' . block[0] . "\" . 'dd' execute 'normal! /' . block[1] . "\" . 'dd' endif - noh + nohl endfunction -command! -range CommenseComment ,call MyCommenter(0) -command! -range CommenseUncomment ,call MyCommenter(1) -command! -range CommenseBlock ,call MyBlocker(0) -command! -range CommenseUnblock ,call MyBlocker(1) +command! -range CommenseComment silent ,call MyCommenter(0) +command! -range CommenseUncomment silent ,call MyCommenter(1) +command! -range CommenseBlock silent ,call MyBlocker(0) +command! -range CommenseUnblock silent ,call MyBlocker(1) diff --git a/plugin/settings.vim b/plugin/settings.vim index 45b79b2..4aff954 100644 --- a/plugin/settings.vim +++ b/plugin/settings.vim @@ -27,6 +27,7 @@ set incsearch set laststatus=2 set nojoinspaces +set backspace= " set splitbelow " }}} @@ -62,7 +63,7 @@ let g:LatexBox_latexmk_options = '-xelatex -outdir=build' " YouCompleteMe stuff " {{{ set completeopt-=preview -let g:ycm_autoclose_preview_window_after_completion = 1 +let g:ycm_autoclose_preview_window_after_completion = 0 let g:ycm_filetype_blacklist = { \ 'tex': 1, \ 'markdown': 1, @@ -122,16 +123,17 @@ else let my_settings_file = "$HOME/.vim/plugin/settings.vim" endif -nnoremap c mc:CommenseComment`c:delm c -nnoremap xc mc:CommenseUncomment`c:delm c -vnoremap c :CommenseComment -vnoremap xc :CommenseUncomment -vnoremap b :CommenseBlock -nnoremap xb mc:CommenseUnblock`c:delm c +nnoremap c mc:CommenseComment`c:delm c +nnoremap xc mc:CommenseUncomment`c:delm c +vnoremap c :CommenseComment +vnoremap xc :CommenseUncomment +vnoremap b :CommenseBlock +nnoremap xb mc:CommenseUnblock`c:delm c -nnoremap sl :tabe $MYVIMRC -nnoremap ss :execute 'tabe' my_settings_file +nnoremap sl :pedit $MYVIMRC +nnoremap ss :execute 'pedit' my_settings_file nnoremap sv :source $MYVIMRC:execute 'source' my_settings_file +nnoremap st :source % nnoremap k nnoremap j nnoremap h