evil-move-beyond-eol
为t
时,normal-state下光标可以移动到一行最后一个字符之后,为nil
时则不可以,这些都符合预期,但是visual-state下,改变evil-move-beyond-eol
不起作用,光标总是可以移到最后一个字之后。
我在 Vim 试了一下,似乎在 visual-state
下 $
会移动到最后一个字符后是 Vim 的默认行为,用于选中行尾的换行符。
好吧,确实vim下normal mode不可以移到最后一个字后,visual mode可以,所以现在evil的行为是正确的。
去翻了下evil-end-of-line
的代码:
(evil-define-motion evil-end-of-line (count)
"Move the cursor to the end of the current line.
If COUNT is given, move COUNT - 1 lines downward first."
:type inclusive
(move-end-of-line count)
(when evil-track-eol
(setq temporary-goal-column most-positive-fixnum
this-command 'next-line))
(unless (evil-visual-state-p)
(evil-adjust-cursor)
(when (eolp)
;; prevent "c$" and "d$" from deleting blank lines
(setq evil-this-type 'exclusive))))
发现evil-adjust-cursor
会在非evil-visual-state-p
的时候把光标从最后一个字后面移到最后一个字上,所以覆盖一下这个函数的定义就好了 :
(evil-define-motion evil-end-of-line (count)
"Move the cursor to the end of the current line.
If COUNT is given, move COUNT - 1 lines downward first."
:type inclusive
(move-end-of-line count)
(when evil-track-eol
(setq temporary-goal-column most-positive-fixnum
this-command 'next-line))
(evil-adjust-cursor)
(when (evil-visual-state-p)
(when (eolp)
;; prevent "c$" and "d$" from deleting blank lines
(setq evil-this-type 'exclusive))))