eri*_*ert 27 vim emacs editing editor
我目前正在玩emacs并对大多数概念感到满意.但我真的很喜欢三个vim命令的便利:dd,o,O希望你能告诉我如何在emacs中镜像它们:)
dd - 无论光标在哪里,都删除整行,包括换行符.
我找到了类似的技巧:
Ca Ck Ck
同时C-a光标移动到行的开始,所述第一C-k杀死文本,第二个杀死的换行符.唯一的问题是,这不是在空行上工作,我只需要键入C-k这是非常不方便的,因为我必须使用不同的命令来执行相同的任务:查杀一行.
o/O - 在光标下方/上方创建一个新的空行,并将光标移动到新行,正确缩进
嗯,C-a C-o几乎就像是O,只是缺少了这个标识.C-e C-o在当前下方创建一个空行但不移动光标.
有没有更好的解决方案来解决我的问题,还是我必须学习Lisp并定义新的命令来满足我的需求?
seh*_*seh 27
对于o和O,这里是我多年前写的一些函数:
(defun vi-open-line-above ()
"Insert a newline above the current line and put point at beginning."
(interactive)
(unless (bolp)
(beginning-of-line))
(newline)
(forward-line -1)
(indent-according-to-mode))
(defun vi-open-line-below ()
"Insert a newline below the current line and put point at beginning."
(interactive)
(unless (eolp)
(end-of-line))
(newline-and-indent))
(defun vi-open-line (&optional abovep)
"Insert a newline below the current line and put point at beginning.
With a prefix argument, insert a newline above the current line."
(interactive "P")
(if abovep
(vi-open-line-above)
(vi-open-line-below)))
Run Code Online (Sandbox Code Playgroud)
你可以绑定vi-open-line到M-insert,如下所示:
(define-key global-map [(meta insert)] 'vi-open-line)
Run Code Online (Sandbox Code Playgroud)
因为dd,如果你想让被杀死的线路进入杀戮戒指,你可以使用这个包裹的功能kill-line:
(defun kill-current-line (&optional n)
(interactive "p")
(save-excursion
(beginning-of-line)
(let ((kill-whole-line t))
(kill-line n))))
Run Code Online (Sandbox Code Playgroud)
为了完整性,它接受一个前缀参数并将其应用于kill-line,以便它可以比"当前"行杀死更多.
您还可以看看源viper-mode来看看它是如何实现了等同的dd,o和O命令.
pja*_*mer 24
C+e C+j
Run Code Online (Sandbox Code Playgroud)
根据emacs手册文档.这会让你有一个新的界限和缩进.