0

I was trying to make a mapping to run a command that takes a count, something like the following:

nnoremap gb :execute('buffer ' . v:count)<CR>

When I run the mapping, I see the following error:

E481, No range allowed

After checking this post, I find it is because vim will insert a range automatically if we press a number before pressing colon : to enter command line.

Is there documentation on this behavior? Can I disable it by default?

1

I’m not sure about documentation, but this can be useful to say 5:normal! Somecommands, or some such (I don’t use it often, but I can imagine a situation in which it’s easier than typing the corresponding range myself).

As for disabling it, use the old visual-mapping trick:

nnoremap gb :<C-u>...
1
  • I am still learning to write vim script. The vim error in this case is hard to figure out, IMO. The Ctrl-U trick is neat and solves the problem.
    – jdhao
    Oct 16 '20 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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