vim 的模糊查詢外掛 LeaderF 新功能介紹

Yggdroot發表於2019-01-04

前言

上一篇文章《讓人相見恨晚的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精益求精,永無止境。

相關文章