0

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 :-)

1

2 Answers 2

1

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, press q: or Ctrl-f while already in :. The latter works for searches as well and may be customized. For the former, cf. q/ and q?.
1

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>"
1
  • Yeah I meant normal mode commands to operate on the Command line, not on the buffer, but thanks! Nov 22, 2022 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.