As title. Is it possible to simulate an Enter(i.e. <CR>
) in command-mode, i.e. after pressing :
?
1 Answer
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.
-
2To avoid "special characters" like from C-v CR:
:execute "normal! \<cr>"
– D. Ben Knoble ♦Commented Apr 26, 2022 at 13:44 -
1Right 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– statoxCommented Apr 26, 2022 at 14:20
<cr>
in command-mode? I do not follow:help c_CTRL-V
in the cmdline.txt section.:h feedkeys
..