2016-08-19 22:07 GMT+03:00 dvd7e <mikee293@gmail.com>:
> I love NERDCommenter, and I'm using vsvim in Visual Studio 2015 which unfortunately doesn't support plugins. I want to define some keyboard mappings to replicate some barebones NERDCommenter functionality, like to comment a single line:
>
> nmap ,cc I//<esc><down> " Insert a c++ style // leading comment
>
> (note I use ",cc" as my leader key for commenting)
>
> and that mapping works great for one line. But if I try to repeat the command for several lines, e.g. "5,cc" then it will just comment the same line 5 times. It appears that the "5" modifier is applied only to "I//" while the "<esc><down>" part is only executed once.
>
> Does anyone know of a way around this, so that "5,cc" will comment 5 successive lines rather than commenting one line 5 times?
All mappings are just roughly "when user types {lhs}, replace it with
{rhs}". When you want to do something like this in Vim you normally
use v:count, but given "vsvim does not support plugins" I expect that
it does not have some essential functionality, most likely +eval and
thus v:count will not work.
You may try to write
nnoremap ,cc :normal! I//<CR>
, this works in Vim and does not require +eval, but I am not sure
whether there is :normal! in vsvim. If this does not work, there is
another idea:
nnoremap ,cc V^<C-v>I//<CR>
, but this has a different effect and can be used only for commenting
lines that have greater or equal indentation to the last line (adding
`o` after `V` should change this to "greater or equal indentation to
the *first* line", but in any case will produce a column of `//` in
place of prepending `//` just before start of text on each line).
Do not forget that `*nore*` variant of mappings should be the default
choice unless you have other reasons (e.g. `nnoremap` is not supported
by vsvim, but `nmap` is): this makes your set of mappings easier
maintainable.
>
> Thanks
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment