对于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-line
:
(defun kill-current-line (&optional n)
(interactive "p")
(save-excursion
(beginning-of-line)
(let ((kill-whole-line t))
(kill-line n))))
为了完整起见,它接受一个前缀参数并将其应用于kill-line
,因此它可以杀死比“当前”行更多的东西。
您还可以查看源代码viper-mode
以了解它如何实现等效dd
的o
、 和O
命令。