[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
Provenance
- Commit
71e573d- Tree
efadd80- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
334a4fa
3 files changed+133 added−35 removed
modified:doc/fzf.txt+101 added-3 removed
1-fzf.txt fzf Last change: February 14 20201+fzf.txt fzf Last change: April 4 20202 FZF - TABLE OF CONTENTS *fzf* *fzf-toc*3 ==============================================================================4 5 FZF Vim integration6+ Installation7 Summary8 :FZF[!]9 Configuration10 Examples11+ Explanation of g:fzf_colors12 fzf#run13 fzf#wrap14 Tips15 fzf inside terminal buffer4 unmodified lines20 FZF VIM INTEGRATION *fzf-vim-integration*21 ==============================================================================22 23 24+INSTALLATION *fzf-installation*25+==============================================================================26+27+Once you have fzf installed, you can enable it inside Vim simply by adding the28+directory to 'runtimepath' in your Vim configuration file. The path may differ29+depending on the package manager.30+>31+ " If installed using Homebrew32+ set rtp+=/usr/local/opt/fzf33+34+ " If installed using git35+ set rtp+=~/.fzf36+<37+If you use {vim-plug}{1}, the same can be written as:38+>39+ " If installed using Homebrew40+ Plug '/usr/local/opt/fzf'41+42+ " If installed using git43+ Plug '~/.fzf'44+<45+But if you want the latest Vim plugin file from GitHub rather than the one46+included in the package, write:47+>48+ Plug 'junegunn/fzf'49+<50+The Vim plugin will pick up fzf binary available on the system. If fzf is not51+found on `$PATH`, it will ask you if it should download the latest binary for52+you.53+54+To make sure that you have the latest version of the binary, set up55+post-update hook like so:56+57+ *fzf#install*58+>59+ Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }60+<61+ {1} https://github.com/junegunn/vim-plug62+63+64 SUMMARY *fzf-summary*65 ==============================================================================66 67 The Vim plugin of fzf provides two core functions, and `:FZF` command which is11 unmodified lines79 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.84 85 The most important of all is `fzf#run`, but it would be easier to understand86 the whole if we start off with `:FZF` command.87 46- {1} https://github.com/junegunn/fzf.vim88+ {2} https://github.com/junegunn/fzf.vim89 90 91 :FZF[!]92 ==============================================================================92 unmodified lines185 " 'previous-history' instead of 'down' and 'up'.186 let g:fzf_history_dir = '~/.local/share/fzf-history'187 <188 189+Explanation of g:fzf_colors~190+ *fzf-explanation-of-gfzfcolors*191+192+`g:fzf_colors` is a dictionary mapping fzf elements to a color specification193+list:194+>195+ element: [ component, group1 [, group2, ...] ]196+<197+ - `element` is an fzf element to apply a color to:198+199+ ----------------------+------------------------------------------------------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 definition218+219+For example, consider the following specification:220+>221+ 'prompt': ['fg', 'Conditional', 'Comment'],222+<223+This means we color the prompt - using the `fg` attribute of the `Conditional`224+if it exists, - otherwise use the `fg` attribute of the `Comment` highlight225+group if it exists, - otherwise fall back to the default color settings for226+the prompt.227+228+You can examine the color option generated according the setting by printing229+the result of `fzf#wrap()` function like so:230+>231+ :echo fzf#wrap()232+<233+234 FZF#RUN235 ==============================================================================236 237 *fzf#run*51 unmodified lines289 `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 lines407 " - 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 <411+Alternatively, you can make fzf open in a tmux popup window (requires tmux 3.2412+or 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+<421 422 Hide statusline~423 *fzf-hide-statusline*424 23 unmodified linesmodified:plugin/fzf.vim+18 added-31 removed
114 unmodified lines115 return s:fzf_call('tempname')116 endfunction117 118 let s:default_layout = { 'down': '~40%' }119-let s:layout_keys = ['window', 'up', 'down', 'left', 'right']119+let s:layout_keys = ['window', 'tmux', 'up', 'down', 'left', 'right']120 let s:fzf_go = s:base_dir.'/bin/fzf'121 let s:fzf_tmux = s:base_dir.'/bin/fzf-tmux'122 123 let s:cpo_save = &cpo66 unmodified lines190 let path = fnameescape(a:path)191 return s:is_win ? escape(path, '$') : path192 endfunction193 194-" Upgrade legacy options195-function! 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 copy207-endfunction208-194 function! s:error(msg)195 echohl ErrorMsg196 echom a:msg197 echohl None170 unmodified lines368 function! fzf#run(...) abort369 try370 let [shell, shellslash, shellcmdflag, shellxquote] = s:use_sh()371 387- 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 lines400 else401 let prefix = ''402 endif403 419- 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 endif27 unmodified lines444 return 0445 endfunction446 447 function! 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') ? '' : '-'))465 endfunction466 474 unmodified linesmodified:README-VIM.md+14 added-1 removed
272 unmodified lines273 | `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`) |278+j `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}`) |280 281 `options` entry can be either a string or a list. For simple cases, string282 should suffice, but prefer to use list type to avoid escaping issues.114 unmodified lines397 " - 'rounded' / 'sharp' / 'horizontal' / 'vertical' / 'top' / 'bottom' / 'left' / 'right'398 let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }399 ```400 401+Alternatively, you can make fzf open in a tmux popup window (requires tmux 3.2402+or above) by putting fzf-tmux options in `tmux` key.403+404+```vim405+" See `man fzf-tmux` for available options406+if exists('$TMUX')407+ let g:fzf_layout = { 'tmux': '-p90%,60%' }408+else409+ let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }410+endif411+```412+413 #### Hide statusline414 415 When 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 of19 unmodified lines