vim-leader插件

2022-07-24, updated 2022-07-24

LeaderF 介绍

LeaderF 是一个问世很长时间的 Vim 插件了,可是我直到最近才发现它,大有相见恨晚之感。它的基本功能是提供了文件、buffers、mrus(most recently used)、tags 的检索,速度很快且是异步查找。检索过程中支持正则表达式、模糊匹配,并可以实时的过滤结果。

LeaderF 是用 Python 实现的,因此需要 Vim 支持 Python Feature。可以通过 vim –version 来查看是否支持 Python。

LeaderF 的安装

推荐使用 vundle 进行安装,vundle 的安装配置请参考其他资料。在 .vimrc 配置文件里增加下面的配置:

1
Plug 'Yggdroot/LeaderF', { 'do': ':LeaderfInstallCExtension' }

:LeaderfInstallCExtension 用于安装c扩展 ubuntu: sudo apt install python3-dev

常用功能

检索文件:

1
<leader>f

检索 buffer:

1
<leader>b

在 LeaderF 运行起来以后(在正常检索的模式下),可以执行下面的一些操作:

1
2
3
4
5
6
7
8
9
<C-C>, <ESC> : 退出 LeaderF.
<C-R> : 在模糊匹配和正则式匹配之间切换
<C-F> : 在全路径搜索和名字搜索之间切换
<Tab> : 在检索模式和选择模式之间切换
<C-J>, <C-K> : 在结果列表里选择
<C-X> : 在水平窗口打开
<C-]> : 在垂直窗口打开
<C-T> : 在新标签打开
<C-P> : 预览结果

在 LeaderF 检索文件的模式下,如果按 Tab 进入选择列表之后,会有其他的快捷键,可以通过 F1 来查看。 集成 ripgrep 进行检索是 LeaderF 很强大的一个功能,rg 是异步的,比 vimgrep 要好很多。而且,对结果可以进行二次过滤:

1
2
3
:LeaderfRgRecall 显示上次 rg 的结果
:Leaderf rg 实时检索
:Leaderf rg [option] 后面的 [option] 和 rg 的语法保持一致

Popup Mode is to open LeaderF in a popup window(vim 8.1.1615+) or floating window(nvim 0.4.2+).

To enable popup mode:

1
let g:Lf_WindowPosition = 'popup'

or add –popup after each subcommand, e.g.,

1
Leaderf file --popup

It’s better to set

1
let g:Lf_PreviewInPopup = 1

, so that you can also preview the result in a popup window.

words: 586 tags: vim