Skip to content

Commit c73eace

Browse files
committed
Add insert mode command to comment around cursor
1 parent 3654775 commit c73eace

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

doc/commentary.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ gc Text object for a comment (operator pending mode
2626
gcgc Uncomment the current and adjacent commented lines.
2727
gcu
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

plugin/commentary.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,18 @@ function! s:textobject(inner) abort
102102
endif
103103
endfunction
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+
105110
command! -range -bar -bang Commentary call s:go(<line1>,<line2>,<bang>0)
106111
xnoremap <expr> <Plug>Commentary <SID>go()
107112
nnoremap <expr> <Plug>Commentary <SID>go()
108113
nnoremap <expr> <Plug>CommentaryLine <SID>go() . '_'
109114
onoremap <silent> <Plug>Commentary :<C-U>call <SID>textobject(get(v:, 'operator', '') ==# 'c')<CR>
110115
nnoremap <silent> <Plug>ChangeCommentary c:<C-U>call <SID>textobject(1)<CR>
116+
inoremap <expr> <Plug>CommentaryInsert <SID>insert()
111117
nmap <silent> <Plug>CommentaryUndo :echoerr "Change your <Plug>CommentaryUndo map to <Plug>Commentary<Plug>Commentary"<CR>
112118
113119
if !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
119127
endif
120128

121129
" vim:set et sw=2:

0 commit comments

Comments
 (0)