Emacs相当于Vim的dd,o,O

前端之家收集整理的这篇文章主要介绍了Emacs相当于Vim的dd,o,O前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我目前正在玩emacs,并对大多数概念感到满意。但是我真的很喜欢三个vim命令的方便:dd,o,O
希望你能告诉我如何在emacs镜像他们:)

dd – deletes whole line,including newline,no matter where the cursor is.

我发现了类似的做法:

C-a C-k C-k

虽然C-a将光标移动到行的开头,但第一个C-k会杀死文本,第二个则会杀死换行符。唯一的问题是,这不是在空线上工作,我只需要键入C-k,这是非常不方便的,因为我必须对同一个任务使用不同的命令:杀死一条线。

o / O – creates a new empty line below / above cursor and moves cursor to the new line,indented correctly

那么,C-C C-O几乎像O,只是身份丢失了。 C-e C-o在当前下方创建一个空行,但不会移动光标。

有什么更好的解决方案我的问题,还是我必须学习Lisp和定义新的命令来满足我的需要?

对于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)))@H_301_31@ 
 

您可以将vi-open-line绑定到M-insert,如下所示:

(define-key global-map [(Meta insert)] 'vi-open-line)@H_301_31@ 
 

对于dd,如果想要杀死的行将其置于kill ring上,可以使用包含kill-line的此函数

(defun kill-current-line (&optional n)
  (interactive "p")
  (save-excursion
    (beginning-of-line)
    (let ((kill-whole-line t))
      (kill-line n))))@H_301_31@ 
 

为了完整,它接受一个前缀参数并将其应用于kill-line,这样它可以比“current”行多得多。

您也可以查看viper-mode的源,看看它如何实现等效的dd,o和o命令。

原文链接:https://www.f2er.com/bash/388726.html

猜你在找的Bash相关文章