evil 光标到达 {beginning,end}-of-buffer 之后竟然反方向移动

在某些特定情况下,evil 的移动有些反常。

重现步骤:

1. 运行以下脚本(依赖 evilfold-this 包),创建两行折叠内容,并把光标移动到末尾:

test-evil-previous-visual-line.el
;;; Usage: /path/to/emacs -nw -Q -l /path/to/test-evil-previous-visual-line.el
;;; Date: 2020-08-04_15.41.25
(toggle-debug-on-error)
(setq user-emacs-directory "~/.emacs.d/")
(setq package-user-dir (concat user-emacs-directory "elpa/"))
(package-initialize)
(require 'evil)
(require 'fold-this)

(add-hook 'after-init-hook
          (lambda ()
            (evil-mode 1)
            (define-key evil-normal-state-map (kbd "j") #'evil-next-visual-line)
            (define-key evil-normal-state-map (kbd "k") #'evil-previous-visual-line)
            (setq fold-this-overlay-text "...")

            (switch-to-buffer "*.el")
            (insert "(first-sexp)\n(second-sexp)")
            (goto-char (point-max))

            (backward-sexp)
            (mark-sexp)
            (call-interactively #'fold-this)

            (backward-sexp)
            (mark-sexp)
            (call-interactively #'fold-this)

            (goto-char (point-max))
            ))

(run-hooks 'after-init-hook)
;;; test-evil-previous-visual-line.el ends here

2. 按 k,光标移动到缓冲开头。

3. 按 k,光标退回到第二行。(按常理光标应该原地不动)

重复 2 和 3 一直按 k 不停上下来回跳动。也可以改为按 M-> 键。

output-k output-M


  • evil-20200718.842
  • Emacs 26.3 / 28.0.50