Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM : Trouble mapping <c-/> and re-selecting visual selection?

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:

  • To make it work on single <c-/>
  • To retain the visual selection.

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:

  1. I have not done any other customizations from my side.
  2. My attempts are listed above
  3. Installing tComment on native vim (Ubuntu) lands you to my setup.
like image 233
Yugal Jindle Avatar asked Oct 19 '25 02:10

Yugal Jindle


1 Answers

  1. If you want to map keys to another mapping, you need to use :map, not :noremap.
  2. For most plugins, this shouldn't be necessary; they usually provide either configuration variables or <Plug>PluginName... for that. Read :help g:tcommentMaps for instructions for this particular plugin, then place your overrides into your ~/.vimrc.
like image 141
Ingo Karkat Avatar answered Oct 22 '25 05:10

Ingo Karkat