とのため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
ます。