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.
nnoremap ; :
and that's it. – Lottery;
Normal mode command. When the second mapping is added, the meanings of;
and:
are swapped. – Lepidote