加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Emacs相当于Vim的dd,o,O

发布时间:2020-12-15 19:54:54 所属栏目:安全 来源:网络整理
导读:我目前正在玩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将
我目前正在玩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)))

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

(define-key global-map [(meta insert)] 'vi-open-line)

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读