As title. Is it possible to simulate an Enter(i.e. <CR>) in command-mode, i.e. after pressing :?

  • 2
    what do you mean, execute <cr> in command-mode? I do not follow Apr 26 at 6:19
  • 1
    Maybe you're looking for :help c_CTRL-V in the cmdline.txt section.
    – mattb
    Apr 26 at 6:46
  • @ChristianBrabandt: I want to use command to simulate pressing the Enter key.
    – Kindred
    Apr 26 at 7:11
  • As running command already involves enter key, it is strange. maybe you want :h feedkeys..
    – eyal karni
    Apr 26 at 19:32

1 Answer 1


As @mattb was saying in comments you need to check :h c_CTRL-V and you'll also need :h :normal.

The basic you'll need to use is:

:normal! ^M

Note that ^M is not two literal characters, you have to input it by using ctrl+v followed by Enter.

The ! after normal is to use the default <CR> key, it's important if you (or the users of your plugin) remapped <CR> to do other things.

Edit: Cf. Ben's comment: If you want to avoid special characters requiring ctrl+v you can use :h :execute to build you command and escape the special chars:

:execute "normal! \<cr>"

If you are running that "manually" from the command line I think the first option is easier but in a script it's better to use the more verbose form.

  • 2
    To avoid "special characters" like from C-v CR: :execute "normal! \<cr>"
    – D. Ben Knoble
    Apr 26 at 13:44
  • 1
    Right thank you Ben! I wanted to add that in my answer but somehow I forgot about the `` and decided to go the other way... I'm not doing as much vimscript as I used to, I losing the right reflexes :D
    – statox
    Apr 26 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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