Skip to content
Myr

[vim] Add 'tmux' layout option to use fzf-tmux

Before adoption: this commit came in with the history the project adopted, so no landing records it.

e.g. if exists('$TMUX') let g:fzf_layout = { 'tmux': '-p90%,60%' } else let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } } endif

authored by Junegunn Choi · committed by Junegunn Choi · parent 334a4fa · Browse files · 3 files+133 added−35 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+133 added−35 removed

  • other:+133 added−35 removed

3 files+133 added−35 removed

modified:doc/fzf.txt+101 added-3 removed
1fzf.txt fzf Last change: February 14 20201fzf.txt fzf Last change: April 4 20202FZF - TABLE OF CONTENTS *fzf* *fzf-toc*3==============================================================================45 FZF Vim integration6 Installation7 Summary8 :FZF[!]9 Configuration10 Examples11 Explanation of g:fzf_colors12 fzf#run13 fzf#wrap14 Tips15 fzf inside terminal buffer
4 unmodified lines
20FZF VIM INTEGRATION *fzf-vim-integration*21==============================================================================222324INSTALLATION *fzf-installation*25==============================================================================2627Once you have fzf installed, you can enable it inside Vim simply by adding the28directory to 'runtimepath' in your Vim configuration file. The path may differ29depending on the package manager.30>31 " If installed using Homebrew32 set rtp+=/usr/local/opt/fzf3334 " If installed using git35 set rtp+=~/.fzf36<37If you use {vim-plug}{1}, the same can be written as:38>39 " If installed using Homebrew40 Plug '/usr/local/opt/fzf'4142 " If installed using git43 Plug '~/.fzf'44<45But if you want the latest Vim plugin file from GitHub rather than the one46included in the package, write:47>48 Plug 'junegunn/fzf'49<50The Vim plugin will pick up fzf binary available on the system. If fzf is not51found on `$PATH`, it will ask you if it should download the latest binary for52you.5354To make sure that you have the latest version of the binary, set up55post-update hook like so:5657 *fzf#install*58>59 Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }60<61 {1} https://github.com/junegunn/vim-plug626364SUMMARY *fzf-summary*65==============================================================================6667The Vim plugin of fzf provides two core functions, and `:FZF` command which is
11 unmodified lines
79 3. `:FZF [fzf_options string] [path string]`80 - Basic fuzzy file selector81 - A reference implementation for those who don't want to write VimScript to82 implement custom commands41 - If you're looking for more such commands, check out {fzf.vim}{1} project.83 - If you're looking for more such commands, check out {fzf.vim}{2} project.8485The most important of all is `fzf#run`, but it would be easier to understand86the whole if we start off with `:FZF` command.8746 {1} https://github.com/junegunn/fzf.vim88 {2} https://github.com/junegunn/fzf.vim899091:FZF[!]92==============================================================================
92 unmodified lines
185 " 'previous-history' instead of 'down' and 'up'.186 let g:fzf_history_dir = '~/.local/share/fzf-history'187<188189Explanation of g:fzf_colors~190 *fzf-explanation-of-gfzfcolors*191192`g:fzf_colors` is a dictionary mapping fzf elements to a color specification193list:194>195 element: [ component, group1 [, group2, ...] ]196<197 - `element` is an fzf element to apply a color to:198199 ----------------------+------------------------------------------------------200 Element | Description ~201 ----------------------+------------------------------------------------------202 `fg` / `bg` / `hl` | Item (foreground / background / highlight)203 `fg+` / `bg+` / `hl+` | Current item (foreground / background / highlight)204 `hl` / `hl+` | Highlighted substrings (normal / current)205 `gutter` | Background of the gutter on the left206 `pointer` | Pointer to the current line ( `>` )207 `marker` | Multi-select marker ( `>` )208 `border` | Border around the window ( `--border` and `--preview` )209 `header` | Header ( `--header` or `--header-lines` )210 `info` | Info line (match counters)211 `spinner` | Streaming input indicator212 `prompt` | Prompt before query ( `> ` )213 ----------------------+------------------------------------------------------214 - `component` specifies the component (`fg` / `bg`) from which to extract the215 color when considering each of the following highlight groups216 - `group1 [, group2, ...]` is a list of highlight groups that are searched (in217 order) for a matching color definition218219For example, consider the following specification:220>221 'prompt': ['fg', 'Conditional', 'Comment'],222<223This means we color the prompt - using the `fg` attribute of the `Conditional`224if it exists, - otherwise use the `fg` attribute of the `Comment` highlight225group if it exists, - otherwise fall back to the default color settings for226the prompt.227228You can examine the color option generated according the setting by printing229the result of `fzf#wrap()` function like so:230>231 :echo fzf#wrap()232<233234FZF#RUN235==============================================================================236237 *fzf#run*
51 unmodified lines
289 `sink*` | funcref | Similar to `sink` , but takes the list of output lines at once290 `options` | string/list | Options to fzf291 `dir` | string | Working directory292 `up` / `down` / `left` / `right` | number/string | (Layout) Window position and size (e.g. `20` , `50%` )293 `tmux` | string | (Layout) fzf-tmux options (e.g. `-p90%,60%` )294 `window` (Vim 8 / Neovim) | string | (Layout) Command to open fzf window (e.g. `vertical aboveleft 30new` )295 `window` (Vim 8 / Neovim) | dict | (Layout) Popup window settings (e.g. `{'width': 0.9, 'height': 0.6}` )296 ---------------------------+---------------+----------------------------------------------------------------------297
109 unmodified lines
407 " - border [string default 'rounded']: Border style408 " - 'rounded' / 'sharp' / 'horizontal' / 'vertical' / 'top' / 'bottom' / 'left' / 'right'409 let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }410<411Alternatively, you can make fzf open in a tmux popup window (requires tmux 3.2412or above) by putting fzf-tmux options in `tmux` key.413>414 " See `man fzf-tmux` for available options415 if exists('$TMUX')416 let g:fzf_layout = { 'tmux': '-p90%,60%' }417 else418 let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }419 endif420<421422Hide statusline~423 *fzf-hide-statusline*424
23 unmodified lines
modified:plugin/fzf.vim+18 added-31 removed
114 unmodified lines
115 return s:fzf_call('tempname')116endfunction117118let s:default_layout = { 'down': '~40%' }119let s:layout_keys = ['window', 'up', 'down', 'left', 'right']119let s:layout_keys = ['window', 'tmux', 'up', 'down', 'left', 'right']120let s:fzf_go = s:base_dir.'/bin/fzf'121let s:fzf_tmux = s:base_dir.'/bin/fzf-tmux'122123let s:cpo_save = &cpo
66 unmodified lines
190 let path = fnameescape(a:path)191 return s:is_win ? escape(path, '$') : path192endfunction193194" Upgrade legacy options195function! s:upgrade(dict)196 let copy = copy(a:dict)197 if has_key(copy, 'tmux')198 let copy.down = remove(copy, 'tmux')199 endif200 if has_key(copy, 'tmux_height')201 let copy.down = remove(copy, 'tmux_height')202 endif203 if has_key(copy, 'tmux_width')204 let copy.right = remove(copy, 'tmux_width')205 endif206 return copy207endfunction208194function! s:error(msg)195 echohl ErrorMsg196 echom a:msg197 echohl None
170 unmodified lines
368function! fzf#run(...) abort369try370 let [shell, shellslash, shellcmdflag, shellxquote] = s:use_sh()371387 let dict = exists('a:1') ? s:upgrade(a:1) : {}372 let dict = exists('a:1') ? copy(a:1) : {}373 let temps = { 'result': s:fzf_tempname() }374 let optstr = s:evaluate_opts(get(dict, 'options', ''))375 try376 let fzf_exec = s:fzf_exec()
23 unmodified lines
400 else401 let prefix = ''402 endif403419 let prefer_tmux = get(g:, 'fzf_prefer_tmux', 0)404 let prefer_tmux = get(g:, 'fzf_prefer_tmux', 0) || has_key(dict, 'tmux')405 let use_height = has_key(dict, 'down') && !has('gui_running') &&406 \ !(has('nvim') || s:is_win || has('win32unix') || s:present(dict, 'up', 'left', 'right', 'window')) &&407 \ executable('tput') && filereadable('/dev/tty')408 let has_vim8_term = has('terminal') && has('patch-8.0.995')409 let has_nvim_term = has('nvim-0.2.1') || has('nvim') && !s:is_win410 let use_term = has_nvim_term ||411 \ has_vim8_term && !has('win32unix') && (has('gui_running') || s:is_win || !use_height && s:present(dict, 'down', 'up', 'left', 'right', 'window'))427 let use_tmux = (!use_height && !use_term || prefer_tmux) && !has('win32unix') && s:tmux_enabled() && s:splittable(dict)412 let use_tmux = (has_key(dict, 'tmux') || (!use_height && !use_term || prefer_tmux) && !has('win32unix') && s:splittable(dict)) && s:tmux_enabled()413 if prefer_tmux && use_tmux414 let use_height = 0415 let use_term = 0416 endif
27 unmodified lines
444 return 0445endfunction446447function! s:fzf_tmux(dict)448 let size = get(a:dict, 'tmux', '')463 let size = ''464 for o in ['up', 'down', 'left', 'right']465 if s:present(a:dict, o)466 let spec = a:dict[o]467 if (o == 'up' || o == 'down') && spec[0] == '~'468 let size = '-'.o[0].s:calc_size(&lines, spec, a:dict)469 else470 " Legacy boolean option471 let size = '-'.o[0].(spec == 1 ? '' : substitute(spec, '^\~', '', ''))449 if empty(size)450 for o in ['up', 'down', 'left', 'right']451 if s:present(a:dict, o)452 let spec = a:dict[o]453 if (o == 'up' || o == 'down') && spec[0] == '~'454 let size = '-'.o[0].s:calc_size(&lines, spec, a:dict)455 else456 " Legacy boolean option457 let size = '-'.o[0].(spec == 1 ? '' : substitute(spec, '^\~', '', ''))458 endif459 break460 endif473 break474 endif475 endfor461 endfor462 endif463 return printf('LINES=%d COLUMNS=%d %s %s %s --',464 \ &lines, &columns, fzf#shellescape(s:fzf_tmux), size, (has_key(a:dict, 'source') ? '' : '-'))465endfunction466
474 unmodified lines
modified:README-VIM.md+14 added-1 removed
272 unmodified lines
273| `sink*` | funcref | Similar to `sink`, but takes the list of output lines at once |274| `options` | string/list | Options to fzf |275| `dir` | string | Working directory |276| `up`/`down`/`left`/`right` | number/string | (Layout) Window position and size (e.g. `20`, `50%`) |277| `tmux` | string | (Layout) fzf-tmux options (e.g. `-p90%,60%`) |277| `window` (Vim 8 / Neovim) | string | (Layout) Command to open fzf window (e.g. `vertical aboveleft 30new`) |278j `window` (Vim 8 / Neovim) | string | (Layout) Command to open fzf window (e.g. `vertical aboveleft 30new`) |279| `window` (Vim 8 / Neovim) | dict | (Layout) Popup window settings (e.g. `{'width': 0.9, 'height': 0.6}`) |280281`options` entry can be either a string or a list. For simple cases, string282should suffice, but prefer to use list type to avoid escaping issues.
114 unmodified lines
397" - 'rounded' / 'sharp' / 'horizontal' / 'vertical' / 'top' / 'bottom' / 'left' / 'right'398let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }399```400401Alternatively, you can make fzf open in a tmux popup window (requires tmux 3.2402or above) by putting fzf-tmux options in `tmux` key.403404```vim405" See `man fzf-tmux` for available options406if exists('$TMUX')407 let g:fzf_layout = { 'tmux': '-p90%,60%' }408else409 let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }410endif411```412413#### Hide statusline414415When fzf starts in a terminal buffer, the file type of the buffer is set to416`fzf`. So you can set up `FileType fzf` autocmd to customize the settings of
19 unmodified lines