VIM: exit insert mode with :normal command

不羁岁月 提交于 2019-12-06 19:35:23

问题


When I go into insert mode with the :normal command (:normal i) for example, how do I exit insert mode?

If I press <Esc>, or <c-c>, or <c-[>, VIM exits command mode and I can't run my :normal command.

I put imap <c-e> <Esc> in my .vimrc but when I type <c-e> in command mode, nothing gets inserted. I can't figure out how to enter a "control e" in command mode.

<c-o> works, for example :normal Ihello<c-o>Aworld but sometimes I want to do more than one command in normal mode.

I know I can use a macro, but I want to know how to do it with :normal.


回答1:


To add a literal <ESC> to your command, press CTRL+V then <ESC>.

See :help i_CTRL-V.




回答2:


The maintainable solution would be:

exe "normal! Ihello\<c-o>Aaworld\<esc>"

... :h :normal




回答3:


:imap will not trigger in command mode. Use :cmap or better, :cnoremap.

And as too much php said, CTRL-V makes it possible to insert raw characters in insert mode or command line editing.



来源:https://stackoverflow.com/questions/4010890/vim-exit-insert-mode-with-normal-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!