在 Vim 中有不止一种方法可以退出插入模式? [英] In Vim is there more than one way to leave insert mode?

查看:27
本文介绍了在 Vim 中有不止一种方法可以退出插入模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有几个命令可以做一些事情然后进入插入模式.是否还有退出插入模式并执行操作的命令?

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...

控制[ : w 返回

在我创建映射之前,是否已经有 Vim 命令可以做到这一点?

Before I create a mapping, is there already Vim command that does that?

推荐答案

如果您想映射几个键来执行诸如在插入模式下保存文件之类的操作,您可以使用 imap 命令.这将绑定 F2 以退出插入模式并保存文件:

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>

这绑定 F2 退出插入模式,保存文件,并重新进入插入模式:

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

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

或者:

:imap <F2> <C-o>:w<CR>

这篇关于在 Vim 中有不止一种方法可以退出插入模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆