File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ gc Text object for a comment (operator pending mode
2626gcgc Uncomment the current and adjacent commented lines.
2727gcu
2828
29+ *i_CTRL-/* *i_CTRL-_*
30+ CTRL-/ or CTRL-_ Insert comment delimiters around the cursor in insert
31+ mode.
32+
2933 *:Commentary*
3034:[range] Commentary Comment or uncomment [range] lines
3135
Original file line number Diff line number Diff line change @@ -102,12 +102,18 @@ function! s:textobject(inner) abort
102102 endif
103103endfunction
104104
105+ function s: insert ()
106+ let [l , r ] = s: surroundings ()
107+ return l . r . repeat (" \<C-G> U\<Left> " , strchars (r ))
108+ endfunction
109+
105110command ! - range - bar - bang Commentary call s: go (<line1> ,<line2> ,<bang> 0 )
106111xnoremap <expr> <Plug> Commentary <SID> go()
107112nnoremap <expr> <Plug> Commentary <SID> go()
108113nnoremap <expr> <Plug> CommentaryLine <SID> go() . '_'
109114onoremap <silent> <Plug> Commentary :<C-U> call <SID> textobject(get(v:, 'operator', '') ==# 'c')<CR>
110115nnoremap <silent> <Plug> ChangeCommentary c:<C-U> call <SID> textobject(1)<CR>
116+ inoremap <expr> <Plug> CommentaryInsert <SID> insert()
111117nmap <silent> <Plug> CommentaryUndo :echoerr "Change your <Plug> CommentaryUndo map to <Plug> Commentary<Plug> Commentary"<CR>
112118
113119if ! hasmapto (' <Plug>Commentary' ) || maparg (' gc' ,' n' ) == # ' '
@@ -116,6 +122,8 @@ if !hasmapto('<Plug>Commentary') || maparg('gc','n') ==# ''
116122 omap gc <Plug> Commentary
117123 nmap gcc <Plug> CommentaryLine
118124 nmap gcu <Plug> Commentary<Plug> Commentary
125+ imap <C-/> <C-G> u<Plug> CommentaryInsert
126+ imap <C-_> <C-G> u<Plug> CommentaryInsert
119127endif
120128
121129" vim:set et sw = 2 :
You can’t perform that action at this time.
0 commit comments