2017-04-01 06:00:30 +03:00
|
|
|
FZF Vim integration
|
|
|
|
===================
|
|
|
|
|
2020-02-14 08:01:46 +03:00
|
|
|
Installation
|
|
|
|
------------
|
|
|
|
|
|
|
|
Once you have fzf installed, you can enable it inside Vim simply by adding the
|
|
|
|
directory to `&runtimepath` in your Vim configuration file. The path may
|
|
|
|
differ depending on the package manager.
|
|
|
|
|
|
|
|
```vim
|
|
|
|
" If installed using Homebrew
|
|
|
|
set rtp+=/usr/local/opt/fzf
|
|
|
|
|
2022-12-26 10:25:36 +03:00
|
|
|
" If installed using Homebrew on Apple Silicon
|
|
|
|
set rtp+=/opt/homebrew/opt/fzf
|
|
|
|
|
2023-03-20 16:30:14 +03:00
|
|
|
" If you have cloned fzf on ~/.fzf directory
|
2020-02-14 08:01:46 +03:00
|
|
|
set rtp+=~/.fzf
|
|
|
|
```
|
|
|
|
|
|
|
|
If you use [vim-plug](https://github.com/junegunn/vim-plug), the same can be
|
|
|
|
written as:
|
|
|
|
|
|
|
|
```vim
|
|
|
|
" If installed using Homebrew
|
|
|
|
Plug '/usr/local/opt/fzf'
|
|
|
|
|
2023-08-12 17:29:00 +03:00
|
|
|
" If installed using Homebrew on Apple Silicon
|
|
|
|
Plug '/opt/homebrew/opt/fzf'
|
|
|
|
|
2023-03-20 16:30:14 +03:00
|
|
|
" If you have cloned fzf on ~/.fzf directory
|
2020-02-14 08:01:46 +03:00
|
|
|
Plug '~/.fzf'
|
|
|
|
```
|
|
|
|
|
|
|
|
But if you want the latest Vim plugin file from GitHub rather than the one
|
|
|
|
included in the package, write:
|
|
|
|
|
|
|
|
```vim
|
|
|
|
Plug 'junegunn/fzf'
|
|
|
|
```
|
|
|
|
|
|
|
|
The Vim plugin will pick up fzf binary available on the system. If fzf is not
|
|
|
|
found on `$PATH`, it will ask you if it should download the latest binary for
|
|
|
|
you.
|
|
|
|
|
|
|
|
To make sure that you have the latest version of the binary, set up
|
|
|
|
post-update hook like so:
|
|
|
|
|
|
|
|
```vim
|
|
|
|
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
|
|
|
|
```
|
|
|
|
|
2019-11-22 19:54:52 +03:00
|
|
|
Summary
|
|
|
|
-------
|
|
|
|
|
|
|
|
The Vim plugin of fzf provides two core functions, and `:FZF` command which is
|
|
|
|
the basic file selector command built on top of them.
|
|
|
|
|
|
|
|
1. **`fzf#run([spec dict])`**
|
|
|
|
- Starts fzf inside Vim with the given spec
|
|
|
|
- `:call fzf#run({'source': 'ls'})`
|
|
|
|
2. **`fzf#wrap([spec dict]) -> (dict)`**
|
|
|
|
- Takes a spec for `fzf#run` and returns an extended version of it with
|
|
|
|
additional options for addressing global preferences (`g:fzf_xxx`)
|
|
|
|
- `:echo fzf#wrap({'source': 'ls'})`
|
|
|
|
- We usually *wrap* a spec with `fzf#wrap` before passing it to `fzf#run`
|
|
|
|
- `:call fzf#run(fzf#wrap({'source': 'ls'}))`
|
|
|
|
3. **`:FZF [fzf_options string] [path string]`**
|
|
|
|
- Basic fuzzy file selector
|
|
|
|
- A reference implementation for those who don't want to write VimScript
|
|
|
|
to implement custom commands
|
|
|
|
- If you're looking for more such commands, check out [fzf.vim](https://github.com/junegunn/fzf.vim) project.
|
|
|
|
|
|
|
|
The most important of all is `fzf#run`, but it would be easier to understand
|
|
|
|
the whole if we start off with `:FZF` command.
|
2017-04-01 06:00:30 +03:00
|
|
|
|
|
|
|
`:FZF[!]`
|
|
|
|
---------
|
|
|
|
|
|
|
|
```vim
|
|
|
|
" Look for files under current directory
|
|
|
|
:FZF
|
|
|
|
|
|
|
|
" Look for files under your home directory
|
|
|
|
:FZF ~
|
|
|
|
|
2019-11-22 19:54:52 +03:00
|
|
|
" With fzf command-line options
|
|
|
|
:FZF --reverse --info=inline /tmp
|
2017-04-01 06:00:30 +03:00
|
|
|
|
|
|
|
" Bang version starts fzf in fullscreen mode
|
|
|
|
:FZF!
|
|
|
|
```
|
|
|
|
|
|
|
|
Similarly to [ctrlp.vim](https://github.com/kien/ctrlp.vim), use enter key,
|
|
|
|
`CTRL-T`, `CTRL-X` or `CTRL-V` to open selected files in the current window,
|
|
|
|
in new tabs, in horizontal splits, or in vertical splits respectively.
|
|
|
|
|
|
|
|
Note that the environment variables `FZF_DEFAULT_COMMAND` and
|
|
|
|
`FZF_DEFAULT_OPTS` also apply here.
|
|
|
|
|
|
|
|
### Configuration
|
|
|
|
|
|
|
|
- `g:fzf_action`
|
|
|
|
- Customizable extra key bindings for opening selected files in different ways
|
|
|
|
- `g:fzf_layout`
|
2017-09-28 18:36:09 +03:00
|
|
|
- Determines the size and position of fzf window
|
2017-04-01 06:00:30 +03:00
|
|
|
- `g:fzf_colors`
|
|
|
|
- Customizes fzf colors to match the current color scheme
|
|
|
|
- `g:fzf_history_dir`
|
|
|
|
- Enables history feature
|
|
|
|
|
|
|
|
#### Examples
|
|
|
|
|
|
|
|
```vim
|
|
|
|
" This is the default extra key bindings
|
|
|
|
let g:fzf_action = {
|
|
|
|
\ 'ctrl-t': 'tab split',
|
|
|
|
\ 'ctrl-x': 'split',
|
|
|
|
\ 'ctrl-v': 'vsplit' }
|
2017-08-14 10:22:07 +03:00
|
|
|
|
|
|
|
" An action can be a reference to a function that processes selected lines
|
|
|
|
function! s:build_quickfix_list(lines)
|
2023-03-10 16:20:57 +03:00
|
|
|
call setqflist(map(copy(a:lines), '{ "filename": v:val, "lnum": 1 }'))
|
2017-08-14 10:22:07 +03:00
|
|
|
copen
|
|
|
|
cc
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let g:fzf_action = {
|
|
|
|
\ 'ctrl-q': function('s:build_quickfix_list'),
|
|
|
|
\ 'ctrl-t': 'tab split',
|
|
|
|
\ 'ctrl-x': 'split',
|
|
|
|
\ 'ctrl-v': 'vsplit' }
|
2017-04-01 06:00:30 +03:00
|
|
|
|
|
|
|
" Default fzf layout
|
2021-04-17 14:48:10 +03:00
|
|
|
" - Popup window (center of the screen)
|
2020-09-12 15:08:05 +03:00
|
|
|
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
|
2017-04-01 06:00:30 +03:00
|
|
|
|
2021-04-17 14:48:10 +03:00
|
|
|
" - Popup window (center of the current window)
|
|
|
|
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6, 'relative': v:true } }
|
|
|
|
|
|
|
|
" - Popup window (anchored to the bottom of the current window)
|
|
|
|
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6, 'relative': v:true, 'yoffset': 1.0 } }
|
|
|
|
|
2020-10-18 07:06:51 +03:00
|
|
|
" - down / up / left / right
|
|
|
|
let g:fzf_layout = { 'down': '40%' }
|
|
|
|
|
|
|
|
" - Window using a Vim command
|
2017-04-01 06:00:30 +03:00
|
|
|
let g:fzf_layout = { 'window': 'enew' }
|
|
|
|
let g:fzf_layout = { 'window': '-tabnew' }
|
2019-06-08 17:29:04 +03:00
|
|
|
let g:fzf_layout = { 'window': '10new' }
|
2017-04-01 06:00:30 +03:00
|
|
|
|
|
|
|
" Customize fzf colors to match your color scheme
|
2019-11-22 19:54:52 +03:00
|
|
|
" - fzf#wrap translates this to a set of `--color` options
|
2017-04-01 06:00:30 +03:00
|
|
|
let g:fzf_colors =
|
|
|
|
\ { 'fg': ['fg', 'Normal'],
|
|
|
|
\ 'bg': ['bg', 'Normal'],
|
|
|
|
\ 'hl': ['fg', 'Comment'],
|
|
|
|
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
|
|
|
|
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
|
|
|
|
\ 'hl+': ['fg', 'Statement'],
|
|
|
|
\ 'info': ['fg', 'PreProc'],
|
2017-09-06 04:44:25 +03:00
|
|
|
\ 'border': ['fg', 'Ignore'],
|
2017-04-01 06:00:30 +03:00
|
|
|
\ 'prompt': ['fg', 'Conditional'],
|
|
|
|
\ 'pointer': ['fg', 'Exception'],
|
|
|
|
\ 'marker': ['fg', 'Keyword'],
|
|
|
|
\ 'spinner': ['fg', 'Label'],
|
|
|
|
\ 'header': ['fg', 'Comment'] }
|
|
|
|
|
2019-11-22 19:54:52 +03:00
|
|
|
" Enable per-command history
|
|
|
|
" - History files will be stored in the specified directory
|
|
|
|
" - When set, CTRL-N and CTRL-P will be bound to 'next-history' and
|
|
|
|
" 'previous-history' instead of 'down' and 'up'.
|
2017-04-01 06:00:30 +03:00
|
|
|
let g:fzf_history_dir = '~/.local/share/fzf-history'
|
|
|
|
```
|
|
|
|
|
2020-03-11 03:58:59 +03:00
|
|
|
##### Explanation of `g:fzf_colors`
|
|
|
|
|
|
|
|
`g:fzf_colors` is a dictionary mapping fzf elements to a color specification
|
|
|
|
list:
|
|
|
|
|
|
|
|
element: [ component, group1 [, group2, ...] ]
|
|
|
|
|
|
|
|
- `element` is an fzf element to apply a color to:
|
|
|
|
|
2021-01-02 18:00:40 +03:00
|
|
|
| Element | Description |
|
|
|
|
| --- | --- |
|
|
|
|
| `fg` / `bg` / `hl` | Item (foreground / background / highlight) |
|
|
|
|
| `fg+` / `bg+` / `hl+` | Current item (foreground / background / highlight) |
|
|
|
|
| `preview-fg` / `preview-bg` | Preview window text and background |
|
|
|
|
| `hl` / `hl+` | Highlighted substrings (normal / current) |
|
|
|
|
| `gutter` | Background of the gutter on the left |
|
|
|
|
| `pointer` | Pointer to the current line (`>`) |
|
|
|
|
| `marker` | Multi-select marker (`>`) |
|
|
|
|
| `border` | Border around the window (`--border` and `--preview`) |
|
|
|
|
| `header` | Header (`--header` or `--header-lines`) |
|
|
|
|
| `info` | Info line (match counters) |
|
|
|
|
| `spinner` | Streaming input indicator |
|
|
|
|
| `query` | Query string |
|
|
|
|
| `disabled` | Query string when search is disabled |
|
|
|
|
| `prompt` | Prompt before query (`> `) |
|
|
|
|
| `pointer` | Pointer to the current line (`>`) |
|
2020-03-11 03:58:59 +03:00
|
|
|
|
|
|
|
- `component` specifies the component (`fg` / `bg`) from which to extract the
|
|
|
|
color when considering each of the following highlight groups
|
|
|
|
|
|
|
|
- `group1 [, group2, ...]` is a list of highlight groups that are searched (in
|
|
|
|
order) for a matching color definition
|
|
|
|
|
|
|
|
For example, consider the following specification:
|
|
|
|
|
|
|
|
```vim
|
|
|
|
'prompt': ['fg', 'Conditional', 'Comment'],
|
|
|
|
```
|
|
|
|
|
|
|
|
This means we color the **prompt**
|
|
|
|
- using the `fg` attribute of the `Conditional` if it exists,
|
|
|
|
- otherwise use the `fg` attribute of the `Comment` highlight group if it exists,
|
|
|
|
- otherwise fall back to the default color settings for the **prompt**.
|
|
|
|
|
|
|
|
You can examine the color option generated according the setting by printing
|
|
|
|
the result of `fzf#wrap()` function like so:
|
|
|
|
|
|
|
|
```vim
|
|
|
|
:echo fzf#wrap()
|
|
|
|
```
|
|
|
|
|
2017-04-01 06:00:30 +03:00
|
|
|
`fzf#run`
|
|
|
|
---------
|
|
|
|
|
2019-06-08 17:17:30 +03:00
|
|
|
`fzf#run()` function is the core of Vim integration. It takes a single
|
2019-11-22 19:54:52 +03:00
|
|
|
dictionary argument, *a spec*, and starts fzf process accordingly. At the very
|
|
|
|
least, specify `sink` option to tell what it should do with the selected
|
|
|
|
entry.
|
2019-06-08 17:17:30 +03:00
|
|
|
|
|
|
|
```vim
|
|
|
|
call fzf#run({'sink': 'e'})
|
|
|
|
```
|
|
|
|
|
2019-11-22 19:54:52 +03:00
|
|
|
We haven't specified the `source`, so this is equivalent to starting fzf on
|
2024-02-15 09:10:54 +03:00
|
|
|
command line without standard input pipe; fzf will traverse the file system
|
|
|
|
under the current directory to get the list of files. (If
|
|
|
|
`$FZF_DEFAULT_COMMAND` is set, fzf will use the output of the command
|
|
|
|
instead.) When you select one, it will open it with the sink, `:e` command. If
|
|
|
|
you want to open it in a new tab, you can pass `:tabedit` command instead as
|
|
|
|
the sink.
|
2019-06-08 17:17:30 +03:00
|
|
|
|
|
|
|
```vim
|
|
|
|
call fzf#run({'sink': 'tabedit'})
|
|
|
|
```
|
|
|
|
|
2024-02-15 09:10:54 +03:00
|
|
|
You can use any shell command as the source to generate the list. The
|
|
|
|
following example will list the files managed by git. It's equivalent to
|
|
|
|
running `git ls-files | fzf` on shell.
|
2019-06-08 17:17:30 +03:00
|
|
|
|
|
|
|
```vim
|
2019-11-22 19:54:52 +03:00
|
|
|
call fzf#run({'source': 'git ls-files', 'sink': 'e'})
|
2019-06-08 17:17:30 +03:00
|
|
|
```
|
|
|
|
|
2019-11-22 19:54:52 +03:00
|
|
|
fzf options can be specified as `options` entry in spec dictionary.
|
2019-06-08 17:17:30 +03:00
|
|
|
|
|
|
|
```vim
|
2019-11-22 19:54:52 +03:00
|
|
|
call fzf#run({'sink': 'tabedit', 'options': '--multi --reverse'})
|
2019-06-08 17:17:30 +03:00
|
|
|
```
|
|
|
|
|
2019-11-22 19:54:52 +03:00
|
|
|
You can also pass a layout option if you don't want fzf window to take up the
|
|
|
|
entire screen.
|
2019-06-08 17:17:30 +03:00
|
|
|
|
|
|
|
```vim
|
|
|
|
" up / down / left / right / window are allowed
|
2019-11-22 19:54:52 +03:00
|
|
|
call fzf#run({'source': 'git ls-files', 'sink': 'e', 'left': '40%'})
|
2019-06-08 17:29:04 +03:00
|
|
|
call fzf#run({'source': 'git ls-files', 'sink': 'e', 'window': '30vnew'})
|
2019-06-08 17:17:30 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
`source` doesn't have to be an external shell command, you can pass a Vim
|
2019-11-22 19:54:52 +03:00
|
|
|
array as the source. In the next example, we pass the names of color
|
|
|
|
schemes as the source to implement a color scheme selector.
|
2019-06-08 17:17:30 +03:00
|
|
|
|
|
|
|
```vim
|
|
|
|
call fzf#run({'source': map(split(globpath(&rtp, 'colors/*.vim')),
|
|
|
|
\ 'fnamemodify(v:val, ":t:r")'),
|
|
|
|
\ 'sink': 'colo', 'left': '25%'})
|
|
|
|
```
|
|
|
|
|
2019-11-22 19:54:52 +03:00
|
|
|
The following table summarizes the available options.
|
2017-04-01 06:00:30 +03:00
|
|
|
|
2019-11-22 19:54:52 +03:00
|
|
|
| Option name | Type | Description |
|
|
|
|
| -------------------------- | ------------- | ---------------------------------------------------------------- |
|
|
|
|
| `source` | string | External command to generate input to fzf (e.g. `find .`) |
|
|
|
|
| `source` | list | Vim list as input to fzf |
|
|
|
|
| `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |
|
|
|
|
| `sink` | funcref | Reference to function to process each selected item |
|
2021-06-04 16:04:20 +03:00
|
|
|
| `sinklist` (or `sink*`) | funcref | Similar to `sink`, but takes the list of output lines at once |
|
2019-11-22 19:54:52 +03:00
|
|
|
| `options` | string/list | Options to fzf |
|
|
|
|
| `dir` | string | Working directory |
|
|
|
|
| `up`/`down`/`left`/`right` | number/string | (Layout) Window position and size (e.g. `20`, `50%`) |
|
2024-05-10 11:43:42 +03:00
|
|
|
| `tmux` | string | (Layout) `--tmux` options (e.g. `90%,70%`) |
|
2020-04-05 12:36:31 +03:00
|
|
|
| `window` (Vim 8 / Neovim) | string | (Layout) Command to open fzf window (e.g. `vertical aboveleft 30new`) |
|
2020-02-03 18:35:57 +03:00
|
|
|
| `window` (Vim 8 / Neovim) | dict | (Layout) Popup window settings (e.g. `{'width': 0.9, 'height': 0.6}`) |
|
2017-04-01 06:00:30 +03:00
|
|
|
|
2017-04-27 20:09:55 +03:00
|
|
|
`options` entry can be either a string or a list. For simple cases, string
|
2019-11-22 19:54:52 +03:00
|
|
|
should suffice, but prefer to use list type to avoid escaping issues.
|
2017-04-27 20:09:55 +03:00
|
|
|
|
|
|
|
```vim
|
|
|
|
call fzf#run({'options': '--reverse --prompt "C:\\Program Files\\"'})
|
|
|
|
call fzf#run({'options': ['--reverse', '--prompt', 'C:\Program Files\']})
|
|
|
|
```
|
|
|
|
|
2020-02-03 18:35:57 +03:00
|
|
|
When `window` entry is a dictionary, fzf will start in a popup window. The
|
|
|
|
following options are allowed:
|
|
|
|
|
|
|
|
- Required:
|
2020-09-06 16:12:51 +03:00
|
|
|
- `width` [float range [0 ~ 1]] or [integer range [8 ~ ]]
|
|
|
|
- `height` [float range [0 ~ 1]] or [integer range [4 ~ ]]
|
2020-02-03 18:35:57 +03:00
|
|
|
- Optional:
|
2020-02-06 04:38:37 +03:00
|
|
|
- `yoffset` [float default 0.5 range [0 ~ 1]]
|
|
|
|
- `xoffset` [float default 0.5 range [0 ~ 1]]
|
2021-04-17 14:48:10 +03:00
|
|
|
- `relative` [boolean default v:false]
|
2023-01-16 16:44:22 +03:00
|
|
|
- `border` [string default `rounded` (`sharp` on Windows)]: Border style
|
2020-10-28 19:32:41 +03:00
|
|
|
- `rounded` / `sharp` / `horizontal` / `vertical` / `top` / `bottom` / `left` / `right` / `no[ne]`
|
2020-02-03 18:35:57 +03:00
|
|
|
|
2017-04-01 06:00:30 +03:00
|
|
|
`fzf#wrap`
|
|
|
|
----------
|
|
|
|
|
2019-11-22 19:54:52 +03:00
|
|
|
We have seen that several aspects of `:FZF` command can be configured with
|
|
|
|
a set of global option variables; different ways to open files
|
|
|
|
(`g:fzf_action`), window position and size (`g:fzf_layout`), color palette
|
|
|
|
(`g:fzf_colors`), etc.
|
|
|
|
|
|
|
|
So how can we make our custom `fzf#run` calls also respect those variables?
|
|
|
|
Simply by *"wrapping"* the spec dictionary with `fzf#wrap` before passing it
|
|
|
|
to `fzf#run`.
|
|
|
|
|
|
|
|
- **`fzf#wrap([name string], [spec dict], [fullscreen bool]) -> (dict)`**
|
|
|
|
- All arguments are optional. Usually we only need to pass a spec dictionary.
|
|
|
|
- `name` is for managing history files. It is ignored if
|
|
|
|
`g:fzf_history_dir` is not defined.
|
|
|
|
- `fullscreen` can be either `0` or `1` (default: 0).
|
|
|
|
|
|
|
|
`fzf#wrap` takes a spec and returns an extended version of it (also
|
|
|
|
a dictionary) with additional options for addressing global preferences. You
|
|
|
|
can examine the return value of it like so:
|
|
|
|
|
|
|
|
```vim
|
|
|
|
echo fzf#wrap({'source': 'ls'})
|
|
|
|
```
|
|
|
|
|
|
|
|
After we *"wrap"* our spec, we pass it to `fzf#run`.
|
2019-06-08 17:17:30 +03:00
|
|
|
|
2019-11-22 19:54:52 +03:00
|
|
|
```vim
|
|
|
|
call fzf#run(fzf#wrap({'source': 'ls'}))
|
|
|
|
```
|
|
|
|
|
2020-10-18 07:06:51 +03:00
|
|
|
Now it supports `CTRL-T`, `CTRL-V`, and `CTRL-X` key bindings (configurable
|
|
|
|
via `g:fzf_action`) and it opens fzf window according to `g:fzf_layout`
|
|
|
|
setting.
|
2019-11-22 19:54:52 +03:00
|
|
|
|
|
|
|
To make it easier to use, let's define `LS` command.
|
|
|
|
|
|
|
|
```vim
|
|
|
|
command! LS call fzf#run(fzf#wrap({'source': 'ls'}))
|
|
|
|
```
|
|
|
|
|
|
|
|
Type `:LS` and see how it works.
|
|
|
|
|
|
|
|
We would like to make `:LS!` (bang version) open fzf in fullscreen, just like
|
|
|
|
`:FZF!`. Add `-bang` to command definition, and use `<bang>` value to set
|
|
|
|
the last `fullscreen` argument of `fzf#wrap` (see `:help <bang>`).
|
2017-04-01 06:00:30 +03:00
|
|
|
|
|
|
|
```vim
|
2019-11-22 19:54:52 +03:00
|
|
|
" On :LS!, <bang> evaluates to '!', and '!0' becomes 1
|
|
|
|
command! -bang LS call fzf#run(fzf#wrap({'source': 'ls'}, <bang>0))
|
|
|
|
```
|
2019-06-08 17:17:30 +03:00
|
|
|
|
2019-11-22 19:54:52 +03:00
|
|
|
Our `:LS` command will be much more useful if we can pass a directory argument
|
|
|
|
to it, so that something like `:LS /tmp` is possible.
|
2019-06-08 17:17:30 +03:00
|
|
|
|
2019-11-22 19:54:52 +03:00
|
|
|
```vim
|
2021-02-03 07:51:56 +03:00
|
|
|
command! -bang -complete=dir -nargs=? LS
|
2019-11-22 19:54:52 +03:00
|
|
|
\ call fzf#run(fzf#wrap({'source': 'ls', 'dir': <q-args>}, <bang>0))
|
|
|
|
```
|
|
|
|
|
|
|
|
Lastly, if you have enabled `g:fzf_history_dir`, you might want to assign
|
|
|
|
a unique name to our command and pass it as the first argument to `fzf#wrap`.
|
2019-06-08 17:17:30 +03:00
|
|
|
|
2019-11-22 19:54:52 +03:00
|
|
|
```vim
|
|
|
|
" The query history for this command will be stored as 'ls' inside g:fzf_history_dir.
|
|
|
|
" The name is ignored if g:fzf_history_dir is not defined.
|
2021-02-03 07:51:56 +03:00
|
|
|
command! -bang -complete=dir -nargs=? LS
|
2019-11-22 19:54:52 +03:00
|
|
|
\ call fzf#run(fzf#wrap('ls', {'source': 'ls', 'dir': <q-args>}, <bang>0))
|
2017-04-01 06:00:30 +03:00
|
|
|
```
|
|
|
|
|
2020-10-18 07:06:51 +03:00
|
|
|
### Global options supported by `fzf#wrap`
|
|
|
|
|
|
|
|
- `g:fzf_layout`
|
|
|
|
- `g:fzf_action`
|
2021-06-04 16:04:20 +03:00
|
|
|
- **Works only when no custom `sink` (or `sinklist`) is provided**
|
2020-10-18 07:06:51 +03:00
|
|
|
- Having custom sink usually means that each entry is not an ordinary
|
|
|
|
file path (e.g. name of color scheme), so we can't blindly apply the
|
|
|
|
same strategy (i.e. `tabedit some-color-scheme` doesn't make sense)
|
|
|
|
- `g:fzf_colors`
|
|
|
|
- `g:fzf_history_dir`
|
|
|
|
|
2019-11-22 19:54:52 +03:00
|
|
|
Tips
|
|
|
|
----
|
|
|
|
|
|
|
|
### fzf inside terminal buffer
|
2017-11-19 06:07:03 +03:00
|
|
|
|
2021-05-19 08:43:34 +03:00
|
|
|
On the latest versions of Vim and Neovim, fzf will start in a terminal buffer.
|
|
|
|
If you find the default ANSI colors to be different, consider configuring the
|
|
|
|
colors using `g:terminal_ansi_colors` in regular Vim or `g:terminal_color_x`
|
|
|
|
in Neovim.
|
2017-11-19 06:07:03 +03:00
|
|
|
|
2021-05-19 08:43:34 +03:00
|
|
|
```vim
|
|
|
|
" Terminal colors for seoul256 color scheme
|
|
|
|
if has('nvim')
|
|
|
|
let g:terminal_color_0 = '#4e4e4e'
|
|
|
|
let g:terminal_color_1 = '#d68787'
|
|
|
|
let g:terminal_color_2 = '#5f865f'
|
|
|
|
let g:terminal_color_3 = '#d8af5f'
|
|
|
|
let g:terminal_color_4 = '#85add4'
|
|
|
|
let g:terminal_color_5 = '#d7afaf'
|
|
|
|
let g:terminal_color_6 = '#87afaf'
|
|
|
|
let g:terminal_color_7 = '#d0d0d0'
|
|
|
|
let g:terminal_color_8 = '#626262'
|
|
|
|
let g:terminal_color_9 = '#d75f87'
|
|
|
|
let g:terminal_color_10 = '#87af87'
|
|
|
|
let g:terminal_color_11 = '#ffd787'
|
|
|
|
let g:terminal_color_12 = '#add4fb'
|
|
|
|
let g:terminal_color_13 = '#ffafaf'
|
|
|
|
let g:terminal_color_14 = '#87d7d7'
|
|
|
|
let g:terminal_color_15 = '#e4e4e4'
|
|
|
|
else
|
|
|
|
let g:terminal_ansi_colors = [
|
|
|
|
\ '#4e4e4e', '#d68787', '#5f865f', '#d8af5f',
|
|
|
|
\ '#85add4', '#d7afaf', '#87afaf', '#d0d0d0',
|
|
|
|
\ '#626262', '#d75f87', '#87af87', '#ffd787',
|
|
|
|
\ '#add4fb', '#ffafaf', '#87d7d7', '#e4e4e4'
|
|
|
|
\ ]
|
|
|
|
endif
|
|
|
|
```
|
2017-11-19 06:07:03 +03:00
|
|
|
|
2021-05-19 08:43:34 +03:00
|
|
|
### Starting fzf in a popup window
|
2019-11-22 19:54:52 +03:00
|
|
|
|
|
|
|
```vim
|
2020-02-03 18:35:57 +03:00
|
|
|
" Required:
|
2020-09-06 16:12:51 +03:00
|
|
|
" - width [float range [0 ~ 1]] or [integer range [8 ~ ]]
|
|
|
|
" - height [float range [0 ~ 1]] or [integer range [4 ~ ]]
|
2020-02-03 18:35:57 +03:00
|
|
|
"
|
|
|
|
" Optional:
|
2020-02-09 19:24:00 +03:00
|
|
|
" - xoffset [float default 0.5 range [0 ~ 1]]
|
|
|
|
" - yoffset [float default 0.5 range [0 ~ 1]]
|
2021-04-17 14:48:10 +03:00
|
|
|
" - relative [boolean default v:false]
|
[vim] More border styles
e.g.
let g:fzf_layout = { 'window': { 'width': 0.4, 'height': 1, 'xoffset': 0, 'border': 'right' } }
let g:fzf_layout = { 'window': { 'width': 0.4, 'height': 1, 'xoffset': 1, 'border': 'left' } }
let g:fzf_layout = { 'window': { 'width': 1, 'height': 0.5, 'yoffset': 1, 'border': 'top' } }
let g:fzf_layout = { 'window': { 'width': 1, 'height': 0.5, 'yoffset': 0, 'border': 'bottom' } }
2020-02-13 18:32:45 +03:00
|
|
|
" - border [string default 'rounded']: Border style
|
|
|
|
" - 'rounded' / 'sharp' / 'horizontal' / 'vertical' / 'top' / 'bottom' / 'left' / 'right'
|
2020-02-03 18:35:57 +03:00
|
|
|
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
|
2019-11-22 19:54:52 +03:00
|
|
|
```
|
|
|
|
|
2020-04-05 12:14:05 +03:00
|
|
|
Alternatively, you can make fzf open in a tmux popup window (requires tmux 3.2
|
2024-05-10 11:43:42 +03:00
|
|
|
or above) by putting `--tmux` option value in `tmux` key.
|
2020-04-05 12:14:05 +03:00
|
|
|
|
|
|
|
```vim
|
2024-05-10 11:43:42 +03:00
|
|
|
" See `--tmux` option in `man fzf` for available options
|
|
|
|
" [center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]
|
2020-04-05 12:14:05 +03:00
|
|
|
if exists('$TMUX')
|
2024-05-10 11:43:42 +03:00
|
|
|
let g:fzf_layout = { 'tmux': '90%,70%' }
|
2020-04-05 12:14:05 +03:00
|
|
|
else
|
|
|
|
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
|
|
|
|
endif
|
|
|
|
```
|
|
|
|
|
2021-05-19 08:43:34 +03:00
|
|
|
### Hide statusline
|
2017-11-19 06:07:03 +03:00
|
|
|
|
2019-11-29 12:32:49 +03:00
|
|
|
When fzf starts in a terminal buffer, the file type of the buffer is set to
|
|
|
|
`fzf`. So you can set up `FileType fzf` autocmd to customize the settings of
|
|
|
|
the window.
|
|
|
|
|
2021-05-19 08:43:34 +03:00
|
|
|
For example, if you open fzf on the bottom on the screen (e.g. `{'down':
|
|
|
|
'40%'}`), you might want to temporarily disable the statusline for a cleaner
|
|
|
|
look.
|
2017-11-19 06:07:03 +03:00
|
|
|
|
|
|
|
```vim
|
2021-05-19 08:43:34 +03:00
|
|
|
let g:fzf_layout = { 'down': '30%' }
|
|
|
|
autocmd! FileType fzf
|
|
|
|
autocmd FileType fzf set laststatus=0 noshowmode noruler
|
|
|
|
\| autocmd BufLeave <buffer> set laststatus=2 showmode ruler
|
2017-11-19 06:07:03 +03:00
|
|
|
```
|
|
|
|
|
2017-04-01 06:00:30 +03:00
|
|
|
[License](LICENSE)
|
|
|
|
------------------
|
|
|
|
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
2024-01-01 03:01:43 +03:00
|
|
|
Copyright (c) 2013-2024 Junegunn Choi
|