In an attempt to make myself use the shorter keystroke to get a colon, I have the following mappings defined in my .vimrc
file:
noremap ; :
noremap : ;
However, this breakes some of my other mappings, since now it interprets a colon as a semicolon. For example, the mapping
map ,c :cd ~/code<CR>
becomes
map ,c ;cd ~/code<CR>
How can I fix this?
The commands of the :map
family interpret the characters in the
mapping definition as if they were typed by the user, so that any of
the currently defined mappings (including the one being defined) are
triggered as usual. It is the reason why it becomes possible to define
recursive or nested mappings when necessary. And this is also why the
colon mapping gets applied to other mappings defined via :map
, like
the one in your example:
:map ,c :cd ~/code<cr>
To avoid this behavior, use the :noremap
family of commands, which
do not interpret any mappings in the right-hand side of a mapping
definition (see :help :nore
):
:noremap ,c :cd ~/code<cr>
In most cases, such interference with other mappings is an undesirable side effect. As a rule of thumb, I would recommend one to go by the following convention when defining a new mapping:
Always use the
:noremap
family of commands, unless there is a clear reason not to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With