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?
1 Answer
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
-
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. Apr 20, 2020 at 11:27 -
-
1Thank you! Now that I have the proper terminology I updated the question title as well. Apr 20, 2020 at 16:09