【发布时间】:2011-08-19 09:34:53
【问题描述】:
在 vim 中,我可以在命令模式下通过键入 'o' 来执行此操作,这将在光标下方添加一个新行,并进入插入模式。
emacs 中是否有等价物?
【问题讨论】:
标签: emacs
在 vim 中,我可以在命令模式下通过键入 'o' 来执行此操作,这将在光标下方添加一个新行,并进入插入模式。
emacs 中是否有等价物?
【问题讨论】:
标签: emacs
其他人建议的命令Co open-line与vi中的o不太一样,因为它拆分当前行并让光标留在当前行。
你得到与 vi 的 o 完全相同的效果,只需两个笔划:Ce RET,将光标移动到当前的末尾行,然后插入一个新行,将光标留在该行的开头。
您可以将该序列绑定到它自己的键上(可能会覆盖 C-o 的现有定义),但我怀疑这是否值得麻烦。
(顺便说一句,对称序列Ca RET给你vi的大写O的效果,在之前插入一行 em> 当前行。)
【讨论】:
C-e C-o,因为如果启用了自动填充模式,这将避免换行。
M-m C-o 可以保留缩进。
你的问题解决了吗?
我刚刚解决了这个问题。随意使用此代码:)
您可以在global-set-key 中绑定到您喜欢的每个键,也可以将newline-and-indent 替换为newline 以防您不喜欢新行缩进。
;; newline-without-break-of-line
(defun newline-without-break-of-line ()
"1. move to end of the line.
2. insert newline with index"
(interactive)
(let ((oldpos (point)))
(end-of-line)
(newline-and-indent)))
(global-set-key (kbd "<C-return>") 'newline-without-break-of-line)
【讨论】:
我用的是prelude,S-RET相当于vi的o,CS-RET相当于vi的O .
【讨论】:
我正在使用emacs 25,我有这样的东西:
;; Insert new line below current line
;; and move cursor to new line
;; it will also indent newline
(global-set-key (kbd "<C-return>") (lambda ()
(interactive)
(end-of-line)
(newline-and-indent)))
;; Insert new line above current line
;; and move cursor to previous line (newly inserted line)
;; it will also indent newline
;; TODO: right now I am unable to goto previous line, FIXIT
(global-set-key (kbd "<C-S-return>") (lambda ()
(interactive)
(beginning-of-line)
(newline-and-indent)
(previous-line)))
希望它会有所帮助:)
【讨论】:
我使用以下键绑定使其与 vim 的 o 和 O 类似:
<pre>
;; vi-like line insertion
(global-set-key (kbd "C-o") (lambda () (interactive)(beginning-of-line)(open-line 1)))
(global-set-key (kbd "M-o") (lambda () (interactive)(end-of-line)(newline)))
</pre>
【讨论】:
我正在使用 Emacs 24。将行插入“.emacs”文件。
;; Move cursor to end of current line
;; Insert new line below current line
;; it will also indent newline
(global-set-key (kbd "<C-return>") (lambda ()
(interactive)
(end-of-line)
(newline-and-indent)))
;; Move cursor to previous line
;; Go to end of the line
;; Insert new line below current line (So it actually insert new line above with indentation)
;; it will also indent newline
(global-set-key (kbd "<C-S-return>") (lambda ()
(interactive)
(previous-line)
(end-of-line)
(newline-and-indent)
))
<C + Return> 表示 <Ctrl + Enter> 代表下面的新行
和
<C + S + Return> 表示 <Ctrl + Shift + Enter> 代表上面的新行。
两者都会缩进。我希望它会起作用。
【讨论】:
C-o 将运行open-line,它将在光标后插入一个空行。默认情况下,emacs 已经处于“插入模式”,除非您在只读缓冲区中。
【讨论】:
此配置可能会有所帮助:
(defun newline-without-break-of-line ()
"1. move to end of the line.
2. open new line and move to new line"
(interactive)
(end-of-line)
(open-line 1)
(right-char))
(global-set-key (kbd "<M-return>") 'newline-without-break-of-line)
【讨论】: