如何在 Vim 中不进入插入模式的情况下在光标所在的位置插入换行符? [英] How do I insert a linebreak where the cursor is without entering into insert mode in Vim?

查看:52
本文介绍了如何在 Vim 中不进入插入模式的情况下在光标所在的位置插入换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Vim 中光标所在的位置插入换行符而不进入插入模式?下面是一个例子([x] 表示光标在 x 上):

Is possible to insert a line break where the cursor is in Vim without entering into insert mode? Here's an example ([x] means cursor is on x):

if (some_condition) {[ ]return; }

有时,我可能想输入更多代码.所以我会按 i 进入插入模式,按 Enter 插入换行符,然后删除多余的空格.接下来,我将进入正常模式并将光标定位在右大括号之前,然后执行相同的操作以使其独立行.

Occasionally, I might want to enter some more code. So I'd press i to get into insert mode, press Enter to insert the line break and then delete the extra space. Next, I'd enter normal mode and position the cursor before the closing brace and then do the same thing to get it on its own line.

我已经这样做了一段时间,但肯定有更好的方法吗?

I've been doing this a while, but there's surely a better way to do it?

推荐答案

对于您给出的示例,您可以使用 rEnter 来替换单个字符 (空格)按 Enter.然后,fspace. 前进到下一个空格并重复上一个命令.

For the example you've given, you could use rEnter to replace a single character (the space) with Enter. Then, fspace. to move forward to the next space and repeat the last command.

根据您的自动缩进设置,上述内容可能会也可能不会正确缩进 return 语句.如果没有,则使用 sEnterTabEsc 代替用换行符替换空格,缩进该行,并退出插入模式.您必须用不同的命令替换第二个空格,因此您不能使用."在这种情况下.

Depending on your autoindent settings, the above may or may not indent the return statement properly. If not, then use sEnterTabEsc instead to replace the space with a newline, indent the line, and exit insert mode. You would have to replace the second space with a different command so you couldn't use '.' in this case.

这篇关于如何在 Vim 中不进入插入模式的情况下在光标所在的位置插入换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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