如何在不使用Evil模式的普通Emacs中实现类似evil-snipe的跳转功能
Hey there! Great question—you can absolutely get that quick, letter-based jump functionality in vanilla Emacs without relying on Evil mode. Here are a couple of tried-and-true options to replicate evil-snipe's behavior:
1. 使用Avy(推荐)
Avy is one of the most popular packages for this kind of jump functionality, and it’s actively maintained. It lets you jump to any visible position (or line) by typing a character (or just triggering line jumps) and then pressing the corresponding letter that pops up near your target.
设置步骤:
- First, install Avy via
M-x package-install RET avy RET. - Add these keybindings to your Emacs config (usually
~/.emacsor~/.emacs.d/init.el) to make it easy to access:
;; 绑定跳转到字符的快捷键(类似evil-snipe的字符跳转) (global-set-key (kbd "C-c j") 'avy-goto-char-timer) ;; 绑定跳转到行的快捷键(对应你描述的每行显示字母的场景) (global-set-key (kbd "C-c l") 'avy-goto-line)
- Reload your config with
M-x eval-bufferor restart Emacs.
使用方法:
- To jump to a specific character: Press
C-c j, then type the character you want to jump to. Avy will overlay small letters next to every occurrence of that character—just press the letter corresponding to your target position, and you’ll jump right there. - To jump to any line: Press
C-c l, and Avy will show letters next to each visible line. Press the letter for the line you want to jump to, and you’re done!
Avy is also highly customizable—you can tweak things like the letter set used, the color of the overlays, or even the delay in avy-goto-char-timer if you want to adjust how long it waits for your input.
2. Ace-Jump-Mode(替代选项)
If you prefer an older but still reliable alternative, Ace-Jump-Mode offers similar line and character jumping. It works much like Avy, but has a slightly different default workflow. However, note that Avy is more actively updated these days.
快速设置:
- Install via
M-x package-install RET ace-jump-mode RET. - Add keybindings:
(global-set-key (kbd "C-c SPC") 'ace-jump-mode)
- When you press
C-c SPC, you’ll be prompted to type a character, then select the letter for your target position.
Either of these packages will give you that snappy, minimal-keystroke jumping experience you loved with evil-snipe, no Evil mode required. Give Avy a first shot—it’s become the go-to for most Emacs users for this kind of feature!
备注:内容来源于stack exchange,提问作者David

