In Vim is there more than one way to leave insert mode?

后端 未结 5 1169
抹茶落季
抹茶落季 2021-02-05 11:44

There are several commands that do something and then enter insert mode. Are there also commands that leave insert mode and do things?

For example, I frequently do this.

相关标签:
5条回答
  • 2021-02-05 12:12

    The only one I can think of is c-o, which lets you run one command in normal mode then drops you back into insert mode.

    For example, a<c-o>~b would result in Ab.

    0 讨论(0)
  • 2021-02-05 12:20

    In addition to Esc (which is identical to ^[), ^C also exits insert mode.

    0 讨论(0)
  • 2021-02-05 12:22

    ALt + the command lets you execute a command from INSERT mode, for example reference:

    alt+o to open newline

    alt+A to append

    0 讨论(0)
  • 2021-02-05 12:25

    If you'd like to map a few keys to do things like save a file while in insert mode, you can use the imap command. This binds F2 to exit insert mode and save the file:

    :imap <F2> <Esc>:w<CR>
    

    This binds F2 to exit insert mode, save the file, and re-enter insert mode:

    :imap <F2> <Esc>:w<CR>a
    

    Or:

    :imap <F2> <C-o>:w<CR>
    
    0 讨论(0)
  • 2021-02-05 12:25

    Pressing Ctrl-L leaves insert mode in evim, so why not in regular vim, too? Add this to your vimrc: :imap

    Or if you don't want to configure vim use Ctrl-[, as suggested by others.

    0 讨论(0)
提交回复
热议问题