

Emacs的avy插件
source link: https://liutos.github.io/2020/10/11/Emacs的avy插件/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

用Emacs的时候,我习惯将它分成“四个部分”
怎么弄的呢?一般是先按 C-x 3
分出左右两个window,再到各个window中用 C-x 2
分出上下两个window——这不是我的笔误,在Emacs的术语中,用来显示一个buffer的区域就叫做一个 window 。而常常被人们冠名为window的、最外层的窗体,则叫做 frame 。
这样划分后,多次按下 C-Tab
(我把这个快捷键绑定到了命令 other-window
上),便可以按照左上、左下、右上、右下的顺序轮换当前聚焦的window了。
如果需要从其它window中复制内容到当前window中粘贴,操作会麻烦一点。以右上角需要左下角的内容为例:
- 按三次
C-Tab
换到左下角的window中——用快捷键是因为我不想去挪鼠标; - 按
k
或j
上下移动光标到目标行——用k
和j
是因为用了evil-mode
插件(参见这篇文章); - 复制内容,再按一次
C-Tab
回到原来的window中粘贴。
听起来可麻烦了。
好在Emacs有一个非常好用的插件,可以把第1和第2个步骤合在一起完成。
avy
这个非常好用的插件就是 avy ,它提供的 avy-goto-line
函数可以一步到位地完成上面的第1和第2个步骤。
用Emacs的包管理器就可以安装它
M-x package-install RET avy RET
接着要为命令 avy-goto-line
绑定一个喜欢的快捷键
(global-set-key (kbd "M-g f") 'avy-goto-line)
至此便可以在Emacs中愉快地使用 M-g f
来快速跳转到当前或其它window中的行了。百闻不如一见,我来演示一番。
avy-goto-line
众所周知,我用org-mode来跟踪自己的学习计划,还会将摸索过程中的一些半成品代码保存到org-mode的条目中。例如,我想要将左下角的window中的三个函数的定义,复制到右上角的代码块中去
于是我先按下 M-g f
,让 avy
为每一行赋予一个标记
因为希望切换到左下角的window的第一行,所以我先按下 j
此时,在前一幅截图中不以字母 j
开始的标记统统消失了,而以字母 j
开始的标记则只留下了从第二个字符开始的部分。
再按下字母 l
,就可以将焦点切换到左下角的window,并且将光标移动到第一行的行首了。然后只需要选中内容、复制,并返回原来的window中粘贴即可。完整的过程如下
后记
如果在按下组合键 M-g f
后,接着按下的是数字键的话, avy-goto-line
会认为使用者打算跳转到指定的行。它将在Emacs的minibuffer中继续等待输入更多的数字或按下回车。不过我不怎么用这个功能,因为我没有让Emacs显示行号,按行号来跳转对我并不方便。
Recommend
-
158
Files Permalink Latest commit message
-
117
Code Navigation in Emacs October 01, 2017 When working with Python code bases, i sometimes have the need to jump between next / previous functions i am working on within t...
-
145
sauron what is it? sauron is an emacs mode for keeping track of events happening in the (emacs) world around you. Events are things like ‘appointment in 5 minutes’, ‘bob pinged you on IRC’, ‘torrent download is...
-
137
emacs-fireplace A cozy fireplace for emacs. Usage After you installed the fireplace package from melpa you can start the fire using M-x fire...
-
166
[emacs-announce] Emacs pretest 26.0.90 is out emacs-devel
-
189
J Mode Provides font-lock, REPL integration ( via comint ) and a basic help documentation for the J programming language. Installation j-mode has been ad...
-
123
powerline Emacs version of the Vim powerline. This is a proposed version 2.0 of the original Emacs Powerline which is a fork of
-
173
Introduction avy is a GNU Emacs package for jumping to visible text using a char-based decision tree. See also ace-jump-mode and
-
71
-
3
将Emacs插件库同步到本地来安装 如果你喜欢把玩各种Emacs插件,会不会觉得在线安装插件特别的慢,而且时时刻刻都得保持网络在线(虽然这也不是什么大问题),如果Emacs版本比较低的话还得解决TLS/SSL的连接问题。 既然这样,为什么不把Emac...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK