美文网首页
在Vim中使用fzf

在Vim中使用fzf

作者: 城西丶 | 来源:发表于2017-12-24 11:44 被阅读4823次

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

基于FZF实现的vim插件,让我们在vim搜索 更加高效。

OS: MacOS 10.13

Vim: Neovim v0.2.2

fzf_vim.png

安装

  1. 安装 fzf,将fzf的目录添加到Vim&runtimepath来启用它。
" If installed using Homebrew
set rtp+=/usr/local/opt/fzf
" If installed using git
set rtp+=~/.fzf
  1. 安装插件fzf.vim, 配置fzf命令。

安装 fzf

  1. 使用 Homebrew 安装fzf
brew install fzf
  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 <sup id="a1">1
Filetypes File types

表格来自fzf.vim

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

配置 fzf.vim 快捷键

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

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

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

nnoremap <silent> <Leader>f :Files<CR>
nnoremap <silent> <Leader>b :Buffers<CR>

<Esc><C-c>退出 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(<q-args>,
  \                 <bang>0 ? fzf#vim#with_preview('up:60%')
  \                         : fzf#vim#with_preview('right:50%:hidden', '?'),
  \                 <bang>0)
nnoremap <silent> <Leader>A :Ag<CR>

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

小结

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

希望大家有所收获。

相关文章

  • CLI命令行模糊搜索的超强大工具:fzf

    参考官方:junegunn/fzf参考:Fuzzy finder(fzf+vim) 使用全指南参考:模糊搜索神器f...

  • 在Vim中使用fzf

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

  • 在Vim中使用fzf

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

  • 使用 neovim 的浮动窗口让你再次爱上 fzf

    fzf 是一个非常高效实用且美观的命令行工具,并且配置有对应的 vim 插件 fzf.vim, 相信很多人都用过。...

  • 2018-11-18 使用fzf命令行

    #fzf vim使用指南# ## 简介 ## go语言编写unix命令行工具。 用来查找列表内容,文件,git分支...

  • Linux模糊搜索神器fzf终极配置

    fzf是Linux终端下的一款模糊搜索神器,速度极快,还可以配合vim以及其他软件使用,可以说是终端党的必备神器。...

  • 终端-fzf使用

    安装fzf 使用 命令行下的模糊完成 ctrl-r 在命令行下按下ctrl-r, fzf会列出history命令,...

  • item2+FZF + Oh My Zsh 历史命令搜索加强

    1.安装fzf 2.安装插件 在~/.oh-my-zsh/plugins下面创建文件夹fzf, 在fzf创建文件f...

  • vim学习笔记(1)

    vim中backspace失效解决办法 现象 在mac中使用vim打开文件后,在insert模式下使用backsp...

  • Vim 常用快捷键

    一、前言 总结一下 Vim 高频率使用命令,在 cmd(命令行)中,使用 Vim 编辑文件命令是vim [file...

网友评论

      本文标题:在Vim中使用fzf

      本文链接:https://www.haomeiwen.com/subject/dcstgxtx.html