如何在vim正常模式下换行?

发布于 2024-09-27 15:15:11 字数 213 浏览 1 评论 0原文

我想将一行(在光标位置)分成两行,而不离开正常模式(进入插入或命令行模式)。这可能吗?

我目前到达我想要的位置,然后按“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

一生独一 2024-10-04 15:15:11

我不知道单个按键命令,但很多时候我先按“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...

尬尬 2024-10-04 15:15:11

试试这个:

:nnoremap <NL> i<CR><ESC>

然后只要你想分割一行就按 Ctrl-J 即可。

Try this:

:nnoremap <NL> i<CR><ESC>

then just press Ctrl-J whenever you want to split a line.

两人的回忆 2024-10-04 15:15:11

与其他答案类似,但不替换当前字符。

R

无需重新映射。

Similar to other answers but doesn't replace the current character.

R<enter>

No remaps required.

静谧 2024-10-04 15:15:11

将光标置于适当位置并...

  r<Enter>

put cursor in position and...

  r<Enter>
絕版丫頭 2024-10-04 15:15:11

据我所知,如果不进入插入模式,这是不可能的。但是,您可以使用类似的宏(将 Z 替换为您想要使用的任何键)

nmap Z i<cr><esc>k$

基本上这会映射键“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)

nmap Z i<cr><esc>k$

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 '$'

清音悠歌 2024-10-04 15:15:11

您可以使用录音。

  1. 将光标置于要插入换行符的位置。
  2. 输入 qa 开始记录到寄存器 a(如果需要,您可以使用 a 以外的其他寄存器。)
  3. 然后输入 i< /code>(切换到插入模式)、Return(插入换行符)、escape(退出插入模式)、q(结束录制。)

现在,您可以通过输入@a(其中a是您开始录制时使用的寄存器号)来调用该按键序列,只需将光标移动到您想要的位置即可插入换行符并输入 @a

You can use recording.

  1. Place your cursor where you would like to insert a line break.
  2. Type qa to start recording into register a (you can use another register other than a if you want.)
  3. Then type 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 (where a 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.

_蜘蛛 2024-10-04 15:15:11

根据这个重复的问题: 如何在不进入 Vim 插入模式的情况下在光标所在位置插入换行符?

在 vi​​m 中,键入:

:map g i[Ctrl+V][Enter][Ctrl+V][Esc][Enter]

这将 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:

:map g i[Ctrl+V][Enter][Ctrl+V][Esc][Enter]

This maps the G key to macro I [Enter] [Escape]

混吃等死 2024-10-04 15:15:11

在正常模式下,按字符“O”,然后按“Esc”。无需映射。

In normal mode, Press the character 'O' then 'Esc'. No mapping needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文