如何在不破坏当前行的情况下添加新行?
在 vim 中,我可以通过键入“o”在命令模式下执行此操作,这将在光标下方添加一个新行,并进入插入模式。
emacs 中有类似的吗?
In vim, I can do this in command mode by typing 'o', which will add a new line below the cursor, and enter the insert mode.
Is there an equivalent in emacs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
其他人建议的命令 Co
open-line
与 vi 中的 o 不太一样,因为它分割当前行并让光标保留在当前行。您可以通过两笔画得到与 vi 的 o 完全相同的效果:Ce RET,它将光标移动到当前行的末尾,然后插入一个新行,这会将光标保留在该行的开头。
您可以将该序列绑定到它自己的键(也许会覆盖 Co 的现有定义),但我怀疑这是否值得这么麻烦。
(顺便说一下,对称序列 Ca RET 给你 vi 的大写 O 的效果,在 之前 插入一行当前行。)
The command C-o
open-line
that others have suggested is not quite the same as o in vi, because it splits the current line and lets the cursor remain in the current line.You get the exact same effect as vi's o with two strokes: C-e RET, which moves the cursor to the end of the current line and then inserts a new line, which leaves the cursor at the beginning of that line.
You could bind that sequence to a key of its own (perhaps overriding the existing definition of C-o), but I doubt if it's worth the trouble.
(Incidentally, the symmetric sequence C-a RET gives you the effect of vi's capital O, inserting a line before the current line.)
你的问题解决了吗?
我刚刚解决了这个问题。请随意使用此代码:)
您可以在
global-set-key
中绑定到您喜欢的每个键,也可以将newline-and-indent
替换为newline
以防万一您不喜欢缩进新行。have you solved your problem?
I just solved this problem. Feel free to use this code :)
You can bind to every key you like in the
global-set-key
,also to replacenewline-and-indent
withnewline
in case you don't like the new line to be indented.我使用的是prelude,S-RET相当于vi的o,CS-RET相当于vi的O。
I am using prelude, and S-RET is equivalent to vi's o and C-S-RET is equivalent to vi's O.
我正在使用
emacs 25
并且我有这样的东西:希望它会有所帮助:)
I am using
emacs 25
and I have something like this:Hope it will help :)
我正在使用 Emacs 24。将该行插入“.emacs”文件。
表示
下面的新行< /em>和
表示
< /strong> 用于新行上面。两者都会缩进。我希望它会起作用。
I am using Emacs 24.Insert the line to ".emacs" file.
<C + Return>
that means<Ctrl + Enter>
for new line belowand
<C + S + Return>
that means<Ctrl + Shift + Enter>
for new line above.Both will indent also. I hope it will work.
我使用以下键绑定使其工作方式类似于 vim 的 o 和 O:
I use following key bindings make it work similar to vim's o and O:
Co 将运行
open- line
将在光标后插入一个空行。默认情况下,emacs 已经处于“插入模式”,除非您处于只读缓冲区中。C-o will run
open-line
which will insert a blank line after the cursor. By default emacs is already in "insert mode" unless you are in a read-only buffer.此配置可以帮助:
This configuration could help: