I have created a vmap but I can't figure out how to apply a count to it.

In this case, the mapping is on <C-a> and 4<C-a> is an example of a command with a count failing to be applied. We would expect the <C-a> command to be called four times in the second case.

I use the following modified version of <C-a> for incrementing numbers:

vnoremap <C-a> $<ESC>`>v`<<C-a>gvo

This version has the benefit that you can visually select a vertical list of numbers and repeatedly increment them using repeated invocations of <C-v>, without having to reselect, and without having to worry about expanding your selection to capture numbers that have "rolled over" to add another digit.

There are various tutorials online for getting a count to apply to a mapping. I have been unsuccessful in getting them to work for this command.

Keywords: <C-a> ctrl-a ctrl+a

  • 2
    If you want to use a count in your mapping read :h v:count and maybe this question which might be a duplicate.
    – statox
    Commented Aug 18, 2017 at 7:17
  • Already have. Could not get it to work. Looking for something ready-to-go. Commented Aug 18, 2017 at 15:01
  • If you read the doc and the question I linked then you have all of the information you need. Your question doesn't show that you tried anything to make it work so for now it really looks like your waiting for someone to do the job for you which isn't the best way to encourage people to help you.
    – statox
    Commented Aug 18, 2017 at 16:15
  • Get real dude. Your answers:questions ratio on SO is lower than mine. I did my due diligence. Did you do yours? Did you execute the command to verify that "RTFM" is an appropriate response? The kernel of the answer is in the missing technique, and neither of your comments supplies it. Commented Aug 18, 2017 at 19:24

1 Answer 1


You can use v:vcount1 with a map expression.

xnoremap <expr> <c-a> "\<esc>'<V'>".v:count1."\<c-a>"

The key is to escape visual mode then apply the count only to the <c-a>. command. Simply use . to repeat the command.

If you rather reselect and keep visual block mode then use the following mapping:

xnoremap <expr> <c-a> "\<esc>`<\<c-v>`>$".v:count1."\<c-a>gvo"

For more help see:

:h :map-expression
:h string
:h v:count1
:h map-modes

Your Answer

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

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