This plugin is DEPRECATED since the commands are now provided by default by vim-fzy.
Fuzzy-select files under a directory using the fuzzy-searcher fzy and your favorite find command.
fzy, vim-fzy (see installation instructions below).
Command | Description |
---|---|
:Find [dir] | Find files in [dir] , open selected file in current window. |
:SFind [dir] | Same as :Find, but open the selected file in a new split. |
[dir]
is the directory to search in. If omitted, the search is performed in
the current working directory.
:SFind accept a command modifier. For example, to open the selected file in a new vertical split, run :vertical SFind. :tab SFind will open the selected file in a new tab. For a full list of supported command modifiers, see :help fzy-:SFind.
Options can be passed to fzy through the dictionary g:fzy
. Currently, the
following entries are supported:
Entry | Description | Default |
---|---|---|
lines |
Specify how many lines of results to show. Sets the fzy --lines option. |
10 |
prompt |
Set the fzy input prompt. | ▶ |
showinfo |
If true, fzy is invoked with the --show-info option. |
0 |
term_highlight |
Highlight group for the terminal window. | 'Terminal' |
popupwin |
Display fzy in a popup terminal. | v:false |
popup |
Popup window options. Entry must be a dictionary. | see below |
findcmd |
File-search command. | see below |
Note: All entries except for findcmd
are also used by the plugin
vim-fzy-builtins in order to provide a uniform fzy interface.
If findcmd
is not specified, the following command is used:
find
-name '.*'
-a '!' -name .
-a '!' -name .gitignore
-a '!' -name .vim
-a -prune
-o '(' -type f -o -type l ')'
-a -print 2> /dev/null
| sed 's/^\.\///'
Broken down the expression means:
- Ignore all hidden files and directories, except for
.gitignore
, and.vim
, - print only files and symlinks.
- The sed(1) command will remove the
./
prefix from all file paths.
The file-search command is always run in the specified search directory to avoid listing long file paths.
The appearance of the popup window can be changed through the popup
key. When
unspecified or set to an empty dictionary, the following values are used:
{
'padding': [0, 1, 0, 1],
'border': [],
'minwidth': 80
}
The following popup
entries can be set: line
, col
, pos
, minwidth
,
drag
, resize
, close
, padding
, border
, borderhighlight
,
borderchars
, highlight
, and zindex
. For more details on each entry see
:help popup-usage as well as the examples below.
- Display 15 items, use a custom prompt, and show the selection info line:
let g:fzy = { \ 'lines': 15, \ 'prompt': '>>> ', \ 'showinfo': 1 \ }
- Same as 1. but display fzy in a popup window, use the default popup options:
let g:fzy = { \ 'lines': 15, \ 'prompt': '>>> ', \ 'showinfo': 1, \ 'popupwin': 1, \ 'popup': {} \ }
- Use a custom popup border and custom highlighting:
let g:fzy = { \ 'lines': 15, \ 'showinfo': 1, \ 'term_highlight': 'NormalDark', \ 'popupwin': 1, \ 'popup': { \ 'minwidth': 90, \ 'highlight': 'NormalDark', \ 'borderchars': ['─', '│', '─', '│', '┌', '┐', '┘', '└'], \ 'padding': [0, 1, 0, 1], \ 'borderhighlight': ['GreyDark'] \ } \ }
- Same as 3. but don't draw a popup border:
let g:fzy = { \ 'lines': 15, \ 'showinfo': 1, \ 'term_highlight': 'NormalDark', \ 'popupwin': 1, \ 'popup': { \ 'minwidth': 90, \ 'highlight': 'NormalDark', \ 'borderchars': [' '], \ 'padding': [0, 1, 0, 1], \ 'borderhighlight': ['GreyDark'] \ } \ }
- Open the popup window at the 5th screen line from the top of the screen:
let g:fzy = { \ 'lines': 15, \ 'showinfo': 1, \ 'popupwin': 1, \ 'popup': { \ 'padding': [0, 1, 0, 1], \ 'pos': 'topleft', \ 'line': 5, \ } \ }
Set your preferred file-search command only if it's available:
let g:fzy = {'lines': 15, 'prompt': '>> '}
if executable('fd')
let g:fzy.findcmd = 'fd --type f --type l --exclude __pycache__'
elseif executable('rg')
let g:fzy.findcmd = 'rg --files --no-messages'
elseif executable('ag')
let g:fzy.findcmd = 'ag --silent --ignore __pycache__ -g ""'
endif
If you prefer shorter Ex commands, add the following to your vimrc
:
" Fuzzy search and edit files recursively under a specified directory
command -nargs=* -bar -complete=dir FE Find <args>
command -nargs=* -bar -complete=dir FS <mods> SFind <args>
command -nargs=* -bar -complete=dir FV vertical SFind <args>
command -nargs=* -bar -complete=dir FT tab SFind <args>
If you prefer mappings over Ex commands, you might find the following useful:
" Edit files under current working directory
nnoremap <silent> <leader>fe :<c-u>Find<cr>
nnoremap <silent> <leader>fs :<c-u>SFind<cr>
nnoremap <silent> <leader>fv :<c-u>vertical SFind<cr>
nnoremap <silent> <leader>ft :<c-u>tab SFind<cr>
Run the following commands in your terminal:
$ cd ~/.vim/pack/git-plugins/start
$ git clone https://github.com/bfrg/vim-fzy
$ git clone https://github.com/bfrg/vim-fzy-find
$ vim -u NONE -c "helptags vim-fzy/doc" -c q
$ vim -u NONE -c "helptags vim-fzy-find/doc" -c q
Note: The directory name git-plugins
is arbitrary, you can pick any other
name. For more details see :help packages.
Assuming vim-plug is your favorite plugin manager, add the following to
your vimrc
:
Plug 'bfrg/vim-fzy'
Plug 'bfrg/vim-fzy-find'
Distributed under the same terms as Vim itself. See :help license.