vim插件leaderf
2023年10月27日星期五晴北京市北京师范大学,
为了与nvim匹配等价的功能,今天为vim安装了模糊查找插件,经过对比从fzf
,
ctrp
和leaderf
中选择了最现代的leaderf
,
其原因为fzf
依赖于命令fzf
不够纯净,ctrp
使用viml
编写,速度太慢,而leaderf
使用python
编写,速度快功能强大,配置方便。于是将其README.md
贴于此处,为了方便直接使用官方给出的配置不做调整,效率更高。
LeaderF
An efficient fuzzy finder that helps to locate files, buffers, mrus, gtags, etc. on the fly.
- Written in Python.
- Support fuzzy and regex searching.
- Full-featured.
- Well-designed fuzzy matching algorithm.
- Extensible.
Changelog
Please see the CHANGELOG for a release history.
Wiki
Wiki.
Extensions
A list of community extensions can be found in the Extensions wiki.
Screenshots
Requirements
- vim7.3 or higher. Only support 7.4.1126+ after v1.01.
- Python2.7+ or Python3.1+.
- To use the popup mode, neovim 0.5.0+ or vim 8.1.1615+ are required.
Installation
For vim-plug user:
1 | Plug 'Yggdroot/LeaderF', { 'do': ':LeaderfInstallCExtension' } |
Performance
LeaderF is already very fast. If you'd like better performance,
install the C extension of the fuzzy matching algorithm, which is more
than 10 times faster.
To install the C extension, firstly, make sure python2
and/or python3
commands are available on Linux/Unix/MacOS
and py -2
and/or py -3
commands are available
on Windows.
Install the C extension
There may be some errors during the installation, please google the error messages to resolve it.1
:LeaderfInstallCExtension
For example,"error: Unable to find vcvarsall.bat"
, you can turn to here for help.Uninstall the C extension
1
:LeaderfUninstallCExtension
After running any command of LeaderF, check the value of
echo g:Lf_fuzzyEngine_C
, if the value is 1, it means the C
extension is loaded sucessfully.
Usage
1 | usage: Leaderf[!] [-h] [--reverse] [--stayOpen] [--input <INPUT> | --cword] |
use :Leaderf <subcommand> -h
to get specific help
of subcommand, e.g., :Leaderf rg -h
.
Once LeaderF is launched:
Command | Description |
---|---|
<C-C> <ESC> |
quit from LeaderF |
<C-R> |
switch between fuzzy search mode and regex mode |
<C-F> |
switch between full path search mode and name only search mode |
<Tab> |
switch to normal mode |
<C-V> <S-Insert> |
paste from clipboard |
<C-U> |
clear the prompt |
<C-W> |
delete the word before the cursor in the prompt |
<C-J> |
move the cursor downward in the result window |
<C-K> |
move the cursor upward in the result window |
<Up> /<Down> |
recall last/next input pattern from history |
<2-LeftMouse> <CR> |
open the file under cursor or selected(when multiple files are selected) |
<C-X> |
open in horizontal split window |
<C-]> |
open in vertical split window |
<C-T> |
open in new tabpage |
<C-\> |
show a prompt enable to choose split window method: vertical, horizontal, tabpage, etc |
<F5> |
refresh the cache |
<C-LeftMouse> <C-S> |
select multiple files |
<S-LeftMouse> |
select consecutive multiple files |
<C-A> |
select all files |
<C-L> |
clear all selections |
<BS> |
delete the preceding character in the prompt |
<Del> |
delete the current character in the prompt |
<Home> |
move the cursor to the begin of the prompt |
<End> |
move the cursor to the end of the prompt |
<Left> |
move the cursor one character to the left in the prompt |
<Right> |
move the cursor one character to the right in the prompt |
<C-P> |
preview the result |
<C-Up> |
scroll up in the popup preview window |
<C-Down> |
scroll down in the popup preview window |
Input formats:
In NameOnly mode (fuzzy mode)
If the first character you input is
';'
, then the searching will be the same as in FullPath mode.
If you input string as'abc;def'
, then'abc'
will match the file name and'def'
will match the directory name.In FullPath mode (fuzzy mode)
Same as in NameOnly mode except that the pattern will match the full path but not the file name only.
In Regexp mode
The input string is the same as the Vim's regexp.
Smart Case:
If the characters in search pattern are all lowercase, the matching is case-insensitive. If the search pattern contains uppercase characters, all lowercase characters still are matched case-insensitively, the uppercase characters can only match upper case. So uppercase characters can speed up the narrowing down of the searching result.
e.g., input
abcDef
,it can match the following strings:but can not match the strings such as:1
2
3
4abcDef
AbcDef
abcDEf
aBcDeFNote:1
2abcdef
Abcdefabc
andef
are still case-insensitive.
And operator:
In fuzzy mode, using
' '
(space) as the and operator, the candidate lines should fuzzily match all the substrings separated by space.e.g., input
abc def gh
,it can match the following strings:1
2
3
4...a.b.c...d.e.f...g.h...
...a.b.c...g.h...d.e.f...
...a.d..e.g.b.c...h..f...
...gh...def...abc...
Popup Mode
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
2
3let g:Lf_WindowPosition = 'popup'
```
or add `--popup` after each subcommand, e.g., 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Customization
-------------
* Change key bindings
By default, `<Up>` and `<Down>` are used to recall last/next input pattern from history. If you want to use them to navigate the result list just like `<C-K>` and `<C-J>` :
`let g:Lf_CommandMap = {'<C-K>': ['<Up>'], '<C-J>': ['<Down>']}`
for more detail, please refer to `:h g:Lf_CommandMap`.
* Change the colors used in LeaderF
```vim
let g:Lf_PopupPalette = {
\ 'light': {
\ 'Lf_hl_match': {
\ 'gui': 'NONE',
\ 'font': 'NONE',
\ 'guifg': 'NONE',
\ 'guibg': '#303136',
\ 'cterm': 'NONE',
\ 'ctermfg': 'NONE',
\ 'ctermbg': '236'
\ },
\ 'Lf_hl_cursorline': {
\ 'gui': 'NONE',
\ 'font': 'NONE',
\ 'guifg': 'NONE',
\ 'guibg': '#303136',
\ 'cterm': 'NONE',
\ 'ctermfg': 'NONE',
\ 'ctermbg': '236'
\ },
\ },
\ 'dark': {
\ ...
\ ...
\ }
\ }
Change the default mapping of searching files command
e.g.
let g:Lf_ShortcutF = '<C-P>'
Show icons (should install fonts from https://github.com/ryanoasis/nerd-fonts)
Support commands: buffer,file,mru,window
1
2
3
4
5
6" Show icons, icons are shown by default
let g:Lf_ShowDevIcons = 1
" For GUI vim, the icon font can be specify like this, for example
let g:Lf_DevIconsFont = "DroidSansM Nerd Font Mono"
" If needs
set ambiwidth=double
Configuration examples
1 | " don't show the help in normal mode |
FAQ
https://github.com/Yggdroot/LeaderF/issues?q=label%3AFAQ+
License
This plugin is released under the Apache License, Version 2.0 (the "License").
:heart: Sponsor
If you like this software, please consider buying me a coffee.
https://github.com/Yggdroot/SponsorMe/blob/main/README.md#donate
(捐赠的朋友最好备注一下自己的ID)