3

My vimrc already has the very useful mapping

vnoremap < <gv
vnoremap > >gv

I'm using the TComment plugin, and I'd like to also do something like

vmap gc gcgv

to re-highlight a visual selection after toggling gc.

But, as written, it just seems to prevent gc from working. vnoremap gives the same result.

Is there a way to do this with a simple mapping? Or should I write a function for it?

1 Answer 1

6

Indeed, you either defined a recursive mapping (vmap), or one that doesn't know that gc is supposed to comment something (vnoremap).

Solution: do what gc does (if you look at it with :verbose vmap gc), and add gv to it as you want:

:xmap gc <Plug>TComment_gcgv

It does look strange. Maybe that's why other plugins use a format like <Plug>(some_code) ?

Also note that (un)commenting may change the text "bounding box" and it won't necessarily correspond to the visual selection before the operation.

1
  • All this time I assumed gc only worked linewise anyway... Dec 16, 2015 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.