I'm in the process of mapping MacOS keybindings (Cmd/Alt + arrows/backspace/delete) to Vim commands, and the only thing remaining is to make the movements in normal mode (such as b
or e
) work in the command line :-)
-
2Does this answer your question? VI mode when using colon (:)– Gustav BlomqvistNov 23, 2022 at 11:24
2 Answers
Martin’s answer with :normal[!]
is great for running Normal commands from an Ex command.
Two other possible interpretations:
- In a (Normal-mode) mapping, the right-hand side is Normal mode. So
nnoremap <M-w> db
is fine if you can use Meta mappings. - To use Normal-mode editing features on the Ex/
:
command line, pressq:
or Ctrl-f while already in:
. The latter works for searches as well and may be customized. For the former, cf.q/
andq?
.
The :normal command seems to be what you're looking for; there are two variants of this: :normal
may use custom mappings from your vimrc or plugins, if any, and :normal!
will always use the default built-in Vim mappings. For example, this will run gj
, which is usually unexpected:
nnoremap j gj
normal j
You usually want to use :normal!
with the exclamation mark, unless you have a specific reason to use :normal
.
To use modifiers or named keys, wrap it inside :execute
(or :exe
for short); for example:
exe "normal! \<C-x>\<C-u>"
-
Yeah I meant normal mode commands to operate on the Command line, not on the buffer, but thanks! Nov 22, 2022 at 17:14