如何在vim正常模式下换行?
我想将一行(在光标位置)分成两行,而不离开正常模式(进入插入或命令行模式)。这可能吗?
我目前到达我想要的位置,然后按“i”进入插入模式,按“enter”将行分成两部分,然后按“esc”返回正常模式。
我不想设置最大行长度或执行任何语法或类似的操作。我只想将一行分成两行而不离开正常模式。 “J”将光标所在的行连接到其下方的行,这很方便。我想要相反的——用一个命令将一行分成两行。
I would like to break a line (at the location of the cursor) in to two lines without leaving normal mode (entering insert or command-line mode). Is this possible?
I currently get to the location I want and hit 'i' to enter insert mode, 'enter' to break the line in two, then 'esc' to return to normal mode.
I am not trying to set a maximum line length or do any syntax or anything like that. I just want to break one line into two lines without leaving normal mode. 'J' joins the line the cursor is on to the line below it, which is handy. I want the opposite -- to break one line into two with a single command.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我不知道单个按键命令,但很多时候我先按“r”,然后按“Enter”来换行。
“r”替换光标下的当前字符,而不进入插入模式。如果您不想替换角色,这可能不是您想要的......
I don't know of a single key command, but a lot of times I do "r" then "Enter" to break a line.
"r" replaces the current character under the cursor without going into insert mode. This may not be what you want if you don't want to replace a character...
试试这个:
然后只要你想分割一行就按 Ctrl-J 即可。
Try this:
then just press Ctrl-J whenever you want to split a line.
与其他答案类似,但不替换当前字符。
R
无需重新映射。
Similar to other answers but doesn't replace the current character.
R<enter>
No remaps required.
将光标置于适当位置并...
put cursor in position and...
据我所知,如果不进入插入模式,这是不可能的。但是,您可以使用类似的宏(将 Z 替换为您想要使用的任何键)
基本上这会映射键“Z”以进入插入模式“i”,插入回车符“',离开插入模式'
',向上一行'k',最后转到行尾'$'As far as I know this isn't possible without entering insert mode. You can however macro it with something like (replace Z with whatever key you want to use)
basically this maps the key 'Z' to enter insert mode 'i', insert a carriage return '
<cr>
', leave insert mode '<esc>
', go up a line 'k' and finally go to the end of the line '$'您可以使用录音。
qa
开始记录到寄存器a
(如果需要,您可以使用a
以外的其他寄存器。)i< /code>(切换到插入模式)、Return(插入换行符)、escape(退出插入模式)、
q
(结束录制。)现在,您可以通过输入
@a
(其中a
是您开始录制时使用的寄存器号)来调用该按键序列,只需将光标移动到您想要的位置即可插入换行符并输入@a
。You can use recording.
qa
to start recording into registera
(you can use another register other thana
if you want.)i
(switch to insert mode), Return (insert newline), escape (exit insert mode),q
(ends recording.)Now you can invoke this sequence of keys by typing
@a
(wherea
is the register number you used when you started the recording), just keep moving the cursor where you want to insert a newline and type@a
.根据这个重复的问题: 如何在不进入 Vim 插入模式的情况下在光标所在位置插入换行符?
在 vim 中,键入:
这将 G 键映射到宏 I [Enter] [Escape]
Per this duplicate question: How do I insert a linebreak where the cursor is without entering into insert mode in Vim?
From within vim, type:
This maps the G key to macro I [Enter] [Escape]
在正常模式下,按字符“O”,然后按“Esc”。无需映射。
In normal mode, Press the character 'O' then 'Esc'. No mapping needed.