在Vim中使用fzf

fzf 是一个基于Go实现的一个交互式的命令行搜索工具,可以搜索如:文件,历史命令,git提交等。功能非常强大。

  1. 使用Git手动安装
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install

安装 fzf.vim

使用 Vim-plug 作为插件管理工具。

Plug '/usr/local/opt/fzf'
Plug 'junegunn/fzf.vim'

OR 使用vim-plug安装 fzf

Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'

fzf 命令

Command List
Files [PATH] Files (similar to :FZF)
GFiles [OPTS] Git files (git ls-files)
GFiles? Git files (git status)
Buffers Open buffers
Colors Color schemes
Ag [PATTERN] ag search result (ALT-A to select all, ALT-D to deselect all)
Lines [QUERY] Lines in loaded buffers
BLines [QUERY] Lines in the current buffer
Tags [QUERY] Tags in the project (ctags -R)
BTags [QUERY] Tags in the current buffer
Marks Marks
Windows Windows
Locate PATTERN locate command output
History v:oldfiles and open buffers
History: Command history
History/ Search history
Snippets Snippets (UltiSnips)
Commits Git commits (requires fugitive.vim)
BCommits Git commits for the current buffer
Commands Commands
Maps Normal mode mappings
Helptags Help tags 1
Filetypes File types

表格来自fzf.vim

在普通模式下,使用:Command 调用命令。

配置 fzf.vim 快捷键

在 fzf.vim 中有着非常详细的设置教程。这里笔者举出自己经常使用的一些快捷键设置:

  • Files [PATH]命令绑定到快捷键f上,快速搜索当前工程目录下的文件

  • Buffers命令绑定到b上,快速搜索buffer

nnoremap  f :Files
nnoremap  b :Buffers

退出 fzf

使用 Ag 实现文本搜索

实现Ag 命令需要安装 the_silver_searcher

  1. 安装 the_silver_searcher
brew install the_silver_searcher

  1. 配置 .vimrc
command! -bang -nargs=* Ag
  \ call fzf#vim#ag(,
  \                 0 ? fzf#vim#with_preview('up:60%')
  \                         : fzf#vim#with_preview('right:50%:hidden', '?'),
  \                 0)
nnoremap  A :Ag

:Ag命令绑定到A上,这样就可以在Vim内搜索项目内的文本了。

小结

由于大多命令笔者并不是经常使用,所以并没有对它们进行设置。更多更全的命令读者可以到 fzf.vim 或者向fzf发起 Issues 和大神们讨论。

希望大家有所收获。

作者:城西丶
链接:https://www.jianshu.com/p/bb91582317ed
來源:
著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

你可能感兴趣的:(在Vim中使用fzf)