开发工具 vim 的模糊查找插件 LeaderF 新功能介绍

Yggdroot · 2018年12月30日 · 最后由 sadwen 回复于 2022年09月02日 · 7002 次阅读

前言

上一篇文章《让人相见恨晚的 vim 插件:模糊查找神器 LeaderF》概括性的介绍了LeaderF的基本功能,本篇对 LeaderF 的新功能做一下介绍。

统一的命令接口

随着 LeaderF 功能的不断增多,LeaderF 的命令也在不断的增加,给开发和使用都带来一些不便。于是,LeaderF 提供了一个统一的命令接口,就像 shell 命令一样,不同的命令选项组合,带来不同的功能。
可以通过:Leaderf -h来查看具体使用方法。

usage: Leaderf[!] [-h] [--reverse] [--stayOpen] [--input <INPUT> | --cword]
                  [--top | --bottom | --left | --right | --belowright | --aboveleft | --fullScreen]
                  [--nameOnly | --fullPath | --fuzzy | --regexMode] [--nowrap]
                  {file,tag,function,mru,searchHistory,cmdHistory,help,line,colorscheme,self,bufTag,buffer,rg}
                  ...

optional arguments:
  -h, --help            show this help message and exit
  --reverse             show results in bottom-up order
  --stayOpen            don't quit LeaderF after accepting an entry
  --input <INPUT>       specifies INPUT as the pattern inputted in advance
  --cword               current word under cursor is inputted in advance
  --top                 the LeaderF window is at the top of the screen
  --bottom              the LeaderF window is at the bottom of the screen
  --left                the LeaderF window is at the left of the screen
  --right               the LeaderF window is at the right of the screen
  --belowright          the LeaderF window is at the belowright of the screen
  --aboveleft           the LeaderF window is at the aboveleft of the screen
  --fullScreen          the LeaderF window takes up the full screen
  --nameOnly            LeaderF is in NameOnly mode by default
  --fullPath            LeaderF is in FullPath mode by default
  --fuzzy               LeaderF is in Fuzzy mode by default
  --regexMode           LeaderF is in Regex mode by default
  --nowrap              long lines in the LeaderF window won't wrap

subcommands:

  {file,tag,function,mru,searchHistory,cmdHistory,help,line,colorscheme,self,bufTag,buffer,rg}
    file                search files
    tag                 navigate tags using the tags file
    function            navigate functions or methods in the buffer
    mru                 search most recently used files
    searchHistory       execute the search command in the history
    cmdHistory          execute the command in the history
    help                navigate the help tags
    line                search a line in the buffer
    colorscheme         switch between colorschemes
    self                execute the commands of itself
    bufTag              navigate tags in the buffer
    buffer              search buffers
    rg                  grep using rg

If [!] is given, enter normal mode directly.

这样就可以用:Leaderf <subcommand> [options]来执行 LeaderF 的命令了。例如:

Before Now
:LeaderfFile <=> :Leaderf file
:LeaderfBuffer <=> :Leaderf buffer
:LeaderfMru <=> :Leaderf mru
:LeaderfMruCwd <=> :Leaderf mru --cwd
...

每个子命令都有专有的命令选项,可以用:Leaderf <subcommand> -h来查看。例如,Leaderf mru -h:

usage: Leaderf[!] mru [-h] [--cwd] [--no-split-path] [--reverse] [--stayOpen]
                      [--input <INPUT> | --cword]
                      [--top | --bottom | --left | --right | --belowright | --aboveleft | --fullScreen]
                      [--nameOnly | --fullPath | --fuzzy | --regexMode]
                      [--nowrap]

optional arguments:
  -h, --help       show this help message and exit

specific arguments:
  --cwd            search MRU in current working directory
  --no-split-path  do not split the path

common arguments:
  --reverse        show results in bottom-up order
  --stayOpen       don't quit LeaderF after accepting an entry
  --input <INPUT>  specifies INPUT as the pattern inputted in advance
  --cword          current word under cursor is inputted in advance
  --top            the LeaderF window is at the top of the screen
  --bottom         the LeaderF window is at the bottom of the screen
  --left           the LeaderF window is at the left of the screen
  --right          the LeaderF window is at the right of the screen
  --belowright     the LeaderF window is at the belowright of the screen
  --aboveleft      the LeaderF window is at the aboveleft of the screen
  --fullScreen     the LeaderF window takes up the full screen
  --nameOnly       LeaderF is in NameOnly mode by default
  --fullPath       LeaderF is in FullPath mode by default
  --fuzzy          LeaderF is in Fuzzy mode by default
  --regexMode      LeaderF is in Regex mode by default
  --nowrap         long lines in the LeaderF window won't wrap

If [!] is given, enter normal mode directly.

自下而上显示结果

好多从 ctrlp.vim 转过来的朋友说不习惯 LeaderF 自上而下显示结果的方式,想要 LeaderF 也能像 ctrlp 一样自下而上(最优结果在最下面)显示结果,为了回馈各位朋友对 LeaderF 的支持,现在 LeaderF 也添加了自下而上显示搜索结果的功能: LeaderF_reverse_order

只需要在命令后面加上--reverse即可,或者也可以一劳永逸,在 vimrc 里面加上 let g:Lf_ReverseOrder = 1

And 模式

LeaderF 支持用空格(可以用g:Lf_AndDelimiter来修改)作为 And 操作符来进行模糊匹配。当匹配已经匹配到字符串末尾时,可以通过敲空格和一个子串来匹配字符串的前面部分,进行快速过滤。
NOTE: 空格分隔的每个子串都是对整个字符串的模糊匹配,而不是精确匹配。

And模式

模糊匹配历史

可以通过上下键来翻看模糊匹配历史: 翻看历史

总结

LeaderF 精益求精,永无止境。

Yggdroot Vim 的模糊查找插件 LeaderF 新功能介绍 (二) 提及了此话题。 10月28日 18:05

目前为止使用 leaderf 已经 3 年了,对我来说已经不可或缺了,强烈推荐

需要 登录 后方可回复, 如果你还没有账号请 注册新账号