preservim / nerdcommenter

Vim plugin for intensely nerdy commenting powers
Creative Commons Zero v1.0 Universal
4.97k stars 447 forks source link

Keep selection after commenting #528

Open josecastillolema opened 9 months ago

josecastillolema commented 9 months ago

Is there a way to keep a selection after commenting?

Thanks!

alerque commented 9 months ago

You looking for gv?

josecastillolema commented 9 months ago

Sorry @alerque I do not follow, could you please elaborate? Just to clarify what I meant:

  1. Select a text in visual mode
  2. Press \<leader>c\<space> (NERDCommenterToggle)
  3. Have the selected text commented AND the keep the selection from step 1
alerque commented 9 months ago

Because there are a variety of possible use cases and starting scenarios, I'm not sure it makes sense to try to bake this into NERDCommenter itself, but VIM already provides the tooling to compose actions like this yourself. gv reselects that last visual mode selection range, so all you need to do is write yourself a map bound to whatever you like that calls the comment function you'd like and then gv at the end. All VIM commands are comparable this way so you can build up whatever combination of actions you want.

josecastillolema commented 9 months ago

Hi @alerque , thanks for your comment. Just to document in case anyone it's trying the same setup, have tried:

map <C-/> <plug>NERDCommenterToggle gv<cr>

but presents a erratic behavior. Anyway, if you maintainers feel that this is not the native way of moving forward let me know and I'll close the issue. Thanks