Reputation: 45666
I am using a vim plugin called tComment
It allows me to comment a line by pressing gc
or <c-_><c-_>
Also, it works on the shortcut <c-/><c-/>
but the visual selection
is lost.
So, I tried:
<c-/>
My attempts :
inoremap <c-/> gc
vnoremap <c-/> gc gv
nnoremap <c-/> gc
=========
imap <c-/> gc
vmap <c-/> gc gv
nmap <c-/> gc
=========
imap <c-/> gc$
vmap <c-/> gc$ gv
nmap <c-/> gc$
=========
inoremap <c-/> <c-_><c-_>
vnoremap <c-/> <c-_><c-_> gv
nnoremap <c-/> <c-_><c-_>
=========
imap <c-/> <c-_><c-_>
vmap <c-/> <c-_><c-_> gv
nmap <c-/> <c-_><c-_>
( Non of the above seems to work )
Note:
tComment
on native vim
(Ubuntu) lands you to my setup.Upvotes: 4
Views: 406
Reputation: 949
If I understand you correctly, you want to have one map (in i, n, & v-mode) that either comments the current line or the visual selection. This is what tcomment's <c-_><c-_>
map does now (with the exception that you want to maintain the visual selection). In order to use <c-/>
you have to set g:tcommentMapLeader1 = '' (or some other map, since <c-/>
seems to be the same as <c-_>
as echristopherson pointed out) in vimrc and then define your maps for <c-/>
.
This should work (add these lines to .vimrc):
let g:tcommentMapLeader1 = ''
noremap <silent> <c-/> :TComment<cr>
vnoremap <silent> <c-/> :TCommentMaybeInline<cr>gv
inoremap <silent> <c-/> <c-o>:TComment<cr>
You might have to replace <c-/>
with <c-_>
to make this work. Since you reported that tcomment already worked when typing <c-/><c-/>
, the <c-_>
map should work.
Anyway, I'd also recommend to use the operator maps since those fit better the way vim works. I don't think using a single key is still a good idea though.
Upvotes: 2
Reputation: 172600
:map
, not :noremap
.<Plug>PluginName...
for that. Read :help g:tcommentMaps
for instructions for this particular plugin, then place your overrides into your ~/.vimrc
.Upvotes: 5