2

Sometimes it is possible to accidentally hit some numeric keys. I have a lot of binds and for most of them there is nothing to be gained by allowing them to repeat with a prefix. Let's suppose that there are some commands that can be semi-disastrous (ones that make tmux calls) if they get repeated. Is there a way to prevent this behavior for a mapping?

2

If you're using the command line, like so:

nnoremap <LEADER>t :!echo "Yay"<CR>

(just an example)

You can add <C-u> after the : to erase all undesired characters:

nnoremap <LEADER>t :<C-u>!echo "Yay"<CR>

" Also works with `<CMD>` in neovim:

nnoremap <LEADER>t <CMD>!echo "Yay"<CR>

What happens is that by default, when you hit numbers followed by :, a range will automatically be added to your command by default.

A range basically allows you to run a command on multiple lines at once, For example:

:1,5s/this/that/g

Executes the substitute command on the lines 1 to 5. Line 5 is included. The range is always placed before the command.

(above example from the vim doc)


To learn more about ranges:

  • :help 10.3
  • :help cmdline-ranges
3
  • This really works! Thanks. It just nukes the stuff that the : includes for you (like :.,.+2, could someone explain what that is/does?) if you type a number before the colon.
    – Steven Lu
    Apr 20 '20 at 11:27
  • I updated my answer 👍
    – Zorzi
    Apr 20 '20 at 12:06
  • 1
    Thank you! Now that I have the proper terminology I updated the question title as well.
    – Steven Lu
    Apr 20 '20 at 16:09

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.