From 1bbf319ae5f20f33162aa1f6edd98d7e0237b69d Mon Sep 17 00:00:00 2001 From: Pavel Lutskov Date: Wed, 28 Feb 2018 21:18:26 +0100 Subject: [PATCH] behold the COMMENTER --- ftplugin/c.vim | 4 ---- ftplugin/java.vim | 4 ---- ftplugin/python.vim | 5 ----- ftplugin/tex.vim | 6 ++--- ftplugin/vim.vim | 5 ----- plugin/comment.vim | 54 +++++++++++++++++++++++++++++++++++++++++++++ plugin/settings.vim | 12 +++++++++- 7 files changed, 68 insertions(+), 22 deletions(-) delete mode 100644 ftplugin/python.vim create mode 100644 plugin/comment.vim diff --git a/ftplugin/c.vim b/ftplugin/c.vim index 78cf857..a500415 100644 --- a/ftplugin/c.vim +++ b/ftplugin/c.vim @@ -1,9 +1,5 @@ iabbrev prn printf("\n"); nnoremap fb ][% nnoremap fe ][ -nnoremap c mcI//`c:delm c -vnoremap c `>o*/` -nnoremap xc mx?//xxx`x:noh:delm x -nnoremap xb mx?\/\*dd/\*\/dd`x:noh:delm x setlocal foldmethod=syntax foldlevel=99 diff --git a/ftplugin/java.vim b/ftplugin/java.vim index 16a8a36..c03d7af 100644 --- a/ftplugin/java.vim +++ b/ftplugin/java.vim @@ -1,9 +1,5 @@ iabbrev cout System.out.println nnoremap fb ][% nnoremap fe ][ -nnoremap c mcI//`c:delm c -vnoremap c `>o*/` -nnoremap xc mx^xx`x:delm x -nnoremap xb mx?\/\*dd/\*\/dd`x:noh:delm x setlocal foldmethod=syntax foldlevel=99 diff --git a/ftplugin/python.vim b/ftplugin/python.vim deleted file mode 100644 index 88974af..0000000 --- a/ftplugin/python.vim +++ /dev/null @@ -1,5 +0,0 @@ -nnoremap c mcI#`c:delm x -vnoremap c `>o"""` - -nnoremap xb mx?"""dd/"""dd`x:noh:delm x -nnoremap xc mx?#xx`x:noh:delm x diff --git a/ftplugin/tex.vim b/ftplugin/tex.vim index 77b75a3..beeb76a 100644 --- a/ftplugin/tex.vim +++ b/ftplugin/tex.vim @@ -8,6 +8,6 @@ iabbrev ssb \subsubsection iabbrev td \todo iabbrev mb \mathbf -nnoremap lm :Latexmk -nnoremap lv :LatexView -nnoremap T :LatexTOC +nnoremap lm :Latexmk +nnoremap lv :LatexView +nnoremap T :LatexTOC diff --git a/ftplugin/vim.vim b/ftplugin/vim.vim index df9e9f7..8f32c9a 100644 --- a/ftplugin/vim.vim +++ b/ftplugin/vim.vim @@ -1,6 +1 @@ setlocal foldmethod=marker foldlevel=0 -nnoremap c mcI"`c:delm c -vnoremap c `>o"}}}` -nnoremap xb - \ mx?^"{{{dd/^"}}}dd`x:noh:delm x -nnoremap xc mx?"xx`x:noh:delm x diff --git a/plugin/comment.vim b/plugin/comment.vim new file mode 100644 index 0000000..9e80a31 --- /dev/null +++ b/plugin/comment.vim @@ -0,0 +1,54 @@ +let s:comment_filetype_map = { + \ 'c': '\/\/', + \ 'cpp': '\/\/', + \ 'java': '\/\/', + \ 'vhdl': '--', + \ 'python': '#', + \ 'vim': '"', + \ 'tex': '%', + \ 'sh': '#' + \ } + +let s:block_filetype_map = { + \ 'c': ['\/\*', '\*\/'], + \ 'java': ['\/\*', '\*\/'], + \ 'cpp': ['\/\*', '\*\/'], + \ 'python': ['"""', '"""'], + \ 'vim': ['" {{{', '" }}}'] + \ } + +function! MyCommenter(uncomment) range + let comment = get(s:comment_filetype_map, &ft, '') + if !len(comment) + return + endif + let search_range = a:firstline . ',' . a:lastline + if !a:uncomment + 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, []) + if !len(block) + return + endif + if !a:unblock + execute 'normal! ' . a:lastline . 'gg' + execute 'normal! o' . substitute(block[1], '\', '', 'g') . "\" + execute 'normal! ' . a:firstline . 'gg' + execute 'normal! O' . substitute(block[0], '\', '', 'g') . "\" + else + execute 'normal! ?' . block[0] . "\" . 'dd' + execute 'normal! /' . block[1] . "\" . 'dd' + endif + noh +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) diff --git a/plugin/settings.vim b/plugin/settings.vim index 010a39c..45b79b2 100644 --- a/plugin/settings.vim +++ b/plugin/settings.vim @@ -50,10 +50,11 @@ set langmenu=en_US.UTF-8 " {{{ let g:tagbar_autofocus = 1 " }}} -" + " LatexBox stuff " {{{ let g:LatexBox_no_mappings = 1 +let g:LatexBox_quickfix = 2 let g:LatexBox_build_dir = 'build' let g:LatexBox_latexmk_options = '-xelatex -outdir=build' " }}} @@ -121,6 +122,13 @@ 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 sl :tabe $MYVIMRC nnoremap ss :execute 'tabe' my_settings_file nnoremap sv :source $MYVIMRC:execute 'source' my_settings_file @@ -135,6 +143,8 @@ nnoremap fl mf081lFr`f:delm f vnoremap " `>a"` vnoremap "+y +nnoremap "+p +inoremap "+p " }}} " Mappings for Plugins