對於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-插入如下:
(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
命令。
來源
2010-01-31 21:20:32
seh
我認爲最好的新方法是http://superuser.com/a/331661(C-e C-j) – 2014-01-09 07:08:48