Skip to content
Myr

fzf.vim

This file

Path

plugin/fzf.vim

778 lines · 21.9 KiB

Last changed by

[neovim] Allow running FZF in multiple windowsJunegunn Choibefore adoptione825b07

History of this file

Take it

The walk stopped after 200 commits: lines older than a3244c4 point at it.

[vim] g:fzf_prefer_tmux for choosing fzf-tmux over --heightJunegunn Choibefore adoptiona425e96

line 1why, one step back
1" Copyright (c) 2017 Junegunn Choi

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 2–28why, one step back
2"
3" MIT License4"5" Permission is hereby granted, free of charge, to any person obtaining6" a copy of this software and associated documentation files (the7" "Software"), to deal in the Software without restriction, including8" without limitation the rights to use, copy, modify, merge, publish,9" distribute, sublicense, and/or sell copies of the Software, and to10" permit persons to whom the Software is furnished to do so, subject to11" the following conditions:12"13" The above copyright notice and this permission notice shall be14" included in all copies or substantial portions of the Software.15"16" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,17" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF18" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND19" NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE20" LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION21" OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION22" WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.2324if exists('g:loaded_fzf')25 finish26endif27let g:loaded_fzf = 128

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

lines 29–47why, one step back
29let s:is_win = has('win32') || has('win64')
30if s:is_win && &shellslash31 set noshellslash32 let s:base_dir = expand('<sfile>:h:h')33 set shellslash34else35 let s:base_dir = expand('<sfile>:h:h')36endif37if s:is_win38 function! s:fzf_call(fn, ...)39 let shellslash = &shellslash40 try41 set noshellslash42 return call(a:fn, a:000)43 finally44 let &shellslash = shellslash45 endtry46 endfunction47

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

lines 48–53why, one step back
48 " Use utf-8 for fzf.vim commands
49 " Return array of shell commands for cmd.exe50 function! s:wrap_cmds(cmds)51 return ['@echo off', 'for /f "tokens=4" %%a in (''chcp'') do set origchcp=%%a', 'chcp 65001 > nul'] +52 \ (type(a:cmds) == type([]) ? a:cmds : [a:cmds]) +53 \ ['chcp %origchcp% > nul']

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

lines 54–59why, one step back
54 endfunction
55else56 function! s:fzf_call(fn, ...)57 return call(a:fn, a:000)58 endfunction59

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

lines 60–61why, one step back
60 function! s:wrap_cmds(cmds)
61 return a:cmds

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

lines 62–64why, one step back
62 endfunction
63endif64

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

lines 65–68why, one step back
65function! s:shellesc_cmd(arg)
66 let escaped = substitute(a:arg, '[&|<>()@^]', '^&', 'g')67 let escaped = substitute(escaped, '%', '%%', 'g')68 let escaped = substitute(escaped, '"', '\\^&', 'g')

[vim] Escape backslashes in fzf#shellescape (#1021)Jan Edmund Lazobefore adoption3399e39

lines 69–70why, one step back
69 let escaped = substitute(escaped, '\(\\\+\)\(\\^\)', '\1\1\2', 'g')
70 return '^"'.substitute(escaped, '\(\\\+\)$', '\1\1', '').'^"'

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

lines 71–80why, one step back
71endfunction
7273function! fzf#shellescape(arg, ...)74 let shell = get(a:000, 0, &shell)75 if shell =~# 'cmd.exe$'76 return s:shellesc_cmd(a:arg)77 endif78 return s:fzf_call('shellescape', a:arg)79endfunction80

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

lines 81–89why, one step back
81function! s:fzf_getcwd()
82 return s:fzf_call('getcwd')83endfunction8485function! s:fzf_fnamemodify(fname, mods)86 return s:fzf_call('fnamemodify', a:fname, a:mods)87endfunction8889function! s:fzf_expand(fmt)

[vim] Prevent 'wildignore' from affecting expand() (#917)Junegunn Choibefore adoption3a50867

line 90why, one step back
90 return s:fzf_call('expand', a:fmt, 1)

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

lines 91–96why, one step back
91endfunction
9293function! s:fzf_tempname()94 return s:fzf_call('tempname')95endfunction96

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 97–98why, one step back
97let s:default_layout = { 'down': '~40%' }
98let s:layout_keys = ['window', 'up', 'down', 'left', 'right']

[vim] Download instruction for WindowsJunegunn Choibefore adoption02ceae1

lines 99–101why, one step back
99let s:fzf_go = s:base_dir.'/bin/fzf'
100let s:fzf_tmux = s:base_dir.'/bin/fzf-tmux'101let s:install = s:base_dir.'/install'

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 102–109why, one step back
102let s:installed = 0
103104let s:cpo_save = &cpo105set cpo&vim106107function! s:fzf_exec()108 if !exists('s:exec')109 if executable(s:fzf_go)

[vim] Do not expand s:fzf_goJunegunn Choibefore adoption1130091

line 110why, one step back
110 let s:exec = s:fzf_go

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 111–112why, one step back
111 elseif executable('fzf')
112 let s:exec = 'fzf'

[vim] Allow running install --bin on CygwinJunegunn Choibefore adoption773133c

line 113why, one step back
113 elseif s:is_win && !has('win32unix')

[vim] Download instruction for WindowsJunegunn Choibefore adoption02ceae1

lines 114–117why, one step back
114 call s:warn('fzf executable not found.')
115 call s:warn('Download fzf binary for Windows from https://github.com/junegunn/fzf-bin/releases/')116 call s:warn('and place it as '.s:base_dir.'\bin\fzf.exe')117 throw 'fzf executable not found'

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 118–130why, one step back
118 elseif !s:installed && executable(s:install) &&
119 \ input('fzf executable not found. Download binary? (y/n) ') =~? '^y'120 redraw121 echo122 call s:warn('Downloading fzf binary. Please wait ...')123 let s:installed = 1124 call system(s:install.' --bin')125 return s:fzf_exec()126 else127 redraw128 throw 'fzf executable not found'129 endif130 endif

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

line 131why, one step back
131 return fzf#shellescape(s:exec)

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 132–151why, one step back
132endfunction
133134function! s:tmux_enabled()135 if has('gui_running')136 return 0137 endif138139 if exists('s:tmux')140 return s:tmux141 endif142143 let s:tmux = 0144 if exists('$TMUX') && executable(s:fzf_tmux)145 let output = system('tmux -V')146 let s:tmux = !v:shell_error && output >= 'tmux 1.7'147 endif148 return s:tmux149endfunction150151function! s:escape(path)

[vim] Use fnameescape to escape command line argumentsJunegunn Choibefore adoption7727ad4

lines 152–153why, one step back
152 let path = fnameescape(a:path)
153 return s:is_win ? escape(path, '$') : path

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 154–192why, one step back
154endfunction
155156" Upgrade legacy options157function! s:upgrade(dict)158 let copy = copy(a:dict)159 if has_key(copy, 'tmux')160 let copy.down = remove(copy, 'tmux')161 endif162 if has_key(copy, 'tmux_height')163 let copy.down = remove(copy, 'tmux_height')164 endif165 if has_key(copy, 'tmux_width')166 let copy.right = remove(copy, 'tmux_width')167 endif168 return copy169endfunction170171function! s:error(msg)172 echohl ErrorMsg173 echom a:msg174 echohl None175endfunction176177function! s:warn(msg)178 echohl WarningMsg179 echom a:msg180 echohl None181endfunction182183function! s:has_any(dict, keys)184 for key in a:keys185 if has_key(a:dict, key)186 return 1187 endif188 endfor189 return 0190endfunction191192function! s:open(cmd, target)

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

line 193why, one step back
193 if stridx('edit', a:cmd) == 0 && s:fzf_fnamemodify(a:target, ':p') ==# s:fzf_expand('%:p')

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 194–203why, one step back
194 return
195 endif196 execute a:cmd s:escape(a:target)197endfunction198199function! s:common_sink(action, lines) abort200 if len(a:lines) < 2201 return202 endif203 let key = remove(a:lines, 0)

[vim] Allow Funcref in g:fzf_actionJunegunn Choibefore adoption2069bbc

lines 204–207why, one step back
204 let Cmd = get(a:action, key, 'e')
205 if type(Cmd) == type(function('call'))206 return Cmd(a:lines)207 endif

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 208–210why, one step back
208 if len(a:lines) > 1
209 augroup fzf_swap210 autocmd SwapExists * let v:swapchoice='o'

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

line 211why, one step back
211 \| call s:warn('fzf: E325: swap file exists: '.s:fzf_expand('<afile>'))

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 212–214why, one step back
212 augroup END
213 endif214 try

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

line 215why, one step back
215 let empty = empty(s:fzf_expand('%')) && line('$') == 1 && empty(getline(1)) && !&modified

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 216–222why, one step back
216 let autochdir = &autochdir
217 set noautochdir218 for item in a:lines219 if empty220 execute 'e' s:escape(item)221 let empty = 0222 else

[vim] Allow Funcref in g:fzf_actionJunegunn Choibefore adoption2069bbc

line 223why, one step back
223 call s:open(Cmd, item)

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 224–254why, one step back
224 endif
225 if !has('patch-8.0.0177') && !has('nvim-0.2') && exists('#BufEnter')226 \ && isdirectory(item)227 doautocmd BufEnter228 endif229 endfor230 finally231 let &autochdir = autochdir232 silent! autocmd! fzf_swap233 endtry234endfunction235236function! s:get_color(attr, ...)237 let gui = has('termguicolors') && &termguicolors238 let fam = gui ? 'gui' : 'cterm'239 let pat = gui ? '^#[a-f0-9]\+' : '^[0-9]\+$'240 for group in a:000241 let code = synIDattr(synIDtrans(hlID(group)), a:attr, fam)242 if code =~? pat243 return code244 endif245 endfor246 return ''247endfunction248249function! s:defaults()250 let rules = copy(get(g:, 'fzf_colors', {}))251 let colors = join(map(items(filter(map(rules, 'call("s:get_color", v:val)'), '!empty(v:val)')), 'join(v:val, ":")'), ',')252 return empty(colors) ? '' : ('--color='.colors)253endfunction254

[vim] Throw error if g:fzf_layout is incorrectly usedJunegunn Choibefore adoption111d193

lines 255–257why, one step back
255function! s:validate_layout(layout)
256 for key in keys(a:layout)257 if index(s:layout_keys, key) < 0

[vim] Capitalize exception messagesJunegunn Choibefore adoptiona484811

line 258why, one step back
258 throw printf('Invalid entry in g:fzf_layout: %s (allowed: %s)%s',

[vim] Throw error if g:fzf_layout is incorrectly usedJunegunn Choibefore adoption111d193

lines 259–264why, one step back
259 \ key, join(s:layout_keys, ', '), key == 'options' ? '. Use $FZF_DEFAULT_OPTS.' : '')
260 endif261 endfor262 return a:layout263endfunction264

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

lines 265–266why, one step back
265function! s:evaluate_opts(options)
266 return type(a:options) == type([]) ?

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

line 267why, one step back
267 \ join(map(copy(a:options), 'fzf#shellescape(v:val)')) : a:options

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

lines 268–269why, one step back
268endfunction
269

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 270–277why, one step back
270" [name string,] [opts dict,] [fullscreen boolean]
271function! fzf#wrap(...)272 let args = ['', {}, 0]273 let expects = map(copy(args), 'type(v:val)')274 let tidx = 0275 for arg in copy(a:000)276 let tidx = index(expects, type(arg), tidx)277 if tidx < 0

[vim] Capitalize exception messagesJunegunn Choibefore adoptiona484811

line 278why, one step back
278 throw 'Invalid arguments (expected: [name string] [opts dict] [fullscreen boolean])'

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 279–285why, one step back
279 endif
280 let args[tidx] = arg281 let tidx += 1282 unlet arg283 endfor284 let [name, opts, bang] = args285

[vim] Expose buffer variable with the current fzf setup (#828)Kassio Borgesbefore adoption712b7b2

lines 286–289why, one step back
286 if len(name)
287 let opts.name = name288 end289

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 290–300why, one step back
290 " Layout: g:fzf_layout (and deprecated g:fzf_height)
291 if bang292 for key in s:layout_keys293 if has_key(opts, key)294 call remove(opts, key)295 endif296 endfor297 elseif !s:has_any(opts, s:layout_keys)298 if !exists('g:fzf_layout') && exists('g:fzf_height')299 let opts.down = g:fzf_height300 else

[vim] Throw error if g:fzf_layout is incorrectly usedJunegunn Choibefore adoption111d193

line 301why, one step back
301 let opts = extend(opts, s:validate_layout(get(g:, 'fzf_layout', s:default_layout)))

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 302–305why, one step back
302 endif
303 endif304305 " Colors: g:fzf_colors

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

line 306why, one step back
306 let opts.options = s:defaults() .' '. s:evaluate_opts(get(opts, 'options', ''))

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 307–309why, one step back
307
308 " History: g:fzf_history_dir309 if len(name) && len(get(g:, 'fzf_history_dir', ''))

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

line 310why, one step back
310 let dir = s:fzf_expand(g:fzf_history_dir)

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 311–313why, one step back
311 if !isdirectory(dir)
312 call mkdir(dir, 'p')313 endif

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

line 314why, one step back
314 let history = fzf#shellescape(dir.'/'.name)

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

line 315why, one step back
315 let opts.options = join(['--history', history, opts.options])

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 316–335why, one step back
316 endif
317318 " Action: g:fzf_action319 if !s:has_any(opts, ['sink', 'sink*'])320 let opts._action = get(g:, 'fzf_action', s:default_action)321 let opts.options .= ' --expect='.join(keys(opts._action), ',')322 function! opts.sink(lines) abort323 return s:common_sink(self._action, a:lines)324 endfunction325 let opts['sink*'] = remove(opts, 'sink')326 endif327328 return opts329endfunction330331function! fzf#run(...) abort332try333 let oshell = &shell334 let useshellslash = &shellslash335

[vim] Download instruction for WindowsJunegunn Choibefore adoption02ceae1

line 336why, one step back
336 if s:is_win

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 337–343why, one step back
337 set shell=cmd.exe
338 set noshellslash339 else340 set shell=sh341 endif342343 let dict = exists('a:1') ? s:upgrade(a:1) : {}

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

lines 344–345why, one step back
344 let temps = { 'result': s:fzf_tempname() }
345 let optstr = s:evaluate_opts(get(dict, 'options', ''))

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 346–351why, one step back
346 try
347 let fzf_exec = s:fzf_exec()348 catch349 throw v:exception350 endtry351

[neovim] Set 'dir' to the current direcotryJunegunn Choibefore adoptioncd59e5d

line 352why, one step back
352 if has('nvim') && !has_key(dict, 'dir')

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

line 353why, one step back
353 let dict.dir = s:fzf_getcwd()

[neovim] Set 'dir' to the current direcotryJunegunn Choibefore adoptioncd59e5d

line 354why, one step back
354 endif

[vim] Expand 'dir' on Cygwin to handle Windows-style pathsJunegunn Choibefore adoption5efdecc

lines 355–357why, one step back
355 if has('win32unix') && has_key(dict, 'dir')
356 let dict.dir = fnamemodify(dict.dir, ':p')357 endif

[neovim] Set 'dir' to the current direcotryJunegunn Choibefore adoptioncd59e5d

line 358why, one step back
358

[vim] Don't pipe FZF_DEFAULT_COMMAND in Windows (#969)Jan Edmund Lazobefore adoption68bd410

lines 359–360why, one step back
359 if !has_key(dict, 'source') && !empty($FZF_DEFAULT_COMMAND) && !s:is_win
360 let temps.source = s:fzf_tempname()

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

line 361why, one step back
361 call writefile(s:wrap_cmds(split($FZF_DEFAULT_COMMAND, "\n")), temps.source)

[vim] Don't pipe FZF_DEFAULT_COMMAND in Windows (#969)Jan Edmund Lazobefore adoption68bd410

line 362why, one step back
362 let dict.source = (empty($SHELL) ? &shell : $SHELL).' '.fzf#shellescape(temps.source)

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 363–370why, one step back
363 endif
364365 if has_key(dict, 'source')366 let source = dict.source367 let type = type(source)368 if type == 1369 let prefix = source.'|'370 elseif type == 3

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

line 371why, one step back
371 let temps.input = s:fzf_tempname()

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

line 372why, one step back
372 call writefile(source, temps.input)

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

line 373why, one step back
373 let prefix = (s:is_win ? 'type ' : 'cat ').fzf#shellescape(temps.input).'|'

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

line 374why, one step back
374 else

[vim] Capitalize exception messagesJunegunn Choibefore adoptiona484811

line 375why, one step back
375 throw 'Invalid source type'

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 376–380why, one step back
376 endif
377 else378 let prefix = ''379 endif380

[vim] g:fzf_prefer_tmux for choosing fzf-tmux over --heightJunegunn Choibefore adoptiona425e96

line 381why, one step back
381 let prefer_tmux = get(g:, 'fzf_prefer_tmux', 0)

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

line 382why, one step back
382 let use_height = has_key(dict, 'down') &&

[vim] Add support for Cygwin (#933)Jan Edmund Lazobefore adoption7e483b0

line 383why, one step back
383 \ !(has('nvim') || s:is_win || has('win32unix') || s:present(dict, 'up', 'left', 'right')) &&

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

line 384why, one step back
384 \ executable('tput') && filereadable('/dev/tty')

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

line 385why, one step back
385 let use_term = has('nvim') && !s:is_win

[vim] Add support for Cygwin (#933)Jan Edmund Lazobefore adoption7e483b0

line 386why, one step back
386 let use_tmux = (!use_height && !use_term || prefer_tmux) && !has('win32unix') && s:tmux_enabled() && s:splittable(dict)

[vim] g:fzf_prefer_tmux for choosing fzf-tmux over --heightJunegunn Choibefore adoptiona425e96

lines 387–390why, one step back
387 if prefer_tmux && use_tmux
388 let use_height = 0389 let use_term = 0390 endif

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

line 391why, one step back
391 if use_height

Merge branch 'master' into develJunegunn Choibefore adoption33f32de

lines 392–393why, one step back
392 let height = s:calc_size(&lines, dict.down, dict)
393 let optstr .= ' --height='.height

[vim] Download instruction for WindowsJunegunn Choibefore adoption02ceae1

line 394why, one step back
394 elseif use_term

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 395–396why, one step back
395 let optstr .= ' --no-height'
396 endif

[vim] g:fzf_prefer_tmux for choosing fzf-tmux over --heightJunegunn Choibefore adoptiona425e96

line 397why, one step back
397 let command = prefix.(use_tmux ? s:fzf_tmux(dict) : fzf_exec).' '.optstr.' > '.temps.result

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

line 398why, one step back
398

[vim] g:fzf_prefer_tmux for choosing fzf-tmux over --heightJunegunn Choibefore adoptiona425e96

line 399why, one step back
399 if use_term

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 400–402why, one step back
400 return s:execute_term(dict, command, temps)
401 endif402

[vim] g:fzf_prefer_tmux for choosing fzf-tmux over --heightJunegunn Choibefore adoptiona425e96

line 403why, one step back
403 let lines = use_tmux ? s:execute_tmux(dict, command, temps)

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 404–436why, one step back
404 \ : s:execute(dict, command, use_height, temps)
405 call s:callback(dict, lines)406 return lines407finally408 let &shell = oshell409 let &shellslash = useshellslash410endtry411endfunction412413function! s:present(dict, ...)414 for key in a:000415 if !empty(get(a:dict, key, ''))416 return 1417 endif418 endfor419 return 0420endfunction421422function! s:fzf_tmux(dict)423 let size = ''424 for o in ['up', 'down', 'left', 'right']425 if s:present(a:dict, o)426 let spec = a:dict[o]427 if (o == 'up' || o == 'down') && spec[0] == '~'428 let size = '-'.o[0].s:calc_size(&lines, spec, a:dict)429 else430 " Legacy boolean option431 let size = '-'.o[0].(spec == 1 ? '' : substitute(spec, '^\~', '', ''))432 endif433 break434 endif435 endfor436 return printf('LINES=%d COLUMNS=%d %s %s %s --',

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

line 437why, one step back
437 \ &lines, &columns, fzf#shellescape(s:fzf_tmux), size, (has_key(a:dict, 'source') ? '' : '-'))

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 438–446why, one step back
438endfunction
439440function! s:splittable(dict)441 return s:present(a:dict, 'up', 'down') && &lines > 15 ||442 \ s:present(a:dict, 'left', 'right') && &columns > 40443endfunction444445function! s:pushd(dict)446 if s:present(a:dict, 'dir')

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

line 447why, one step back
447 let cwd = s:fzf_getcwd()

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 448–452why, one step back
448 if get(a:dict, 'prev_dir', '') ==# cwd
449 return 1450 endif451 let a:dict.prev_dir = cwd452 execute 'lcd' s:escape(a:dict.dir)

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

line 453why, one step back
453 let a:dict.dir = s:fzf_getcwd()

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 454–464why, one step back
454 return 1
455 endif456 return 0457endfunction458459augroup fzf_popd460 autocmd!461 autocmd WinEnter * call s:dopopd()462augroup END463464function! s:dopopd()

[vim] Fix issues with other plugins changing working directoryJunegunn Choibefore adoption462c68b

line 465why, one step back
465 if !exists('w:fzf_dir') || s:fzf_getcwd() != w:fzf_dir[1]

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 466–467why, one step back
466 return
467 endif

[vim] Fix issues with other plugins changing working directoryJunegunn Choibefore adoption462c68b

lines 468–469why, one step back
468 execute 'lcd' s:escape(w:fzf_dir[0])
469 unlet w:fzf_dir

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 470–481why, one step back
470endfunction
471472function! s:xterm_launcher()473 let fmt = 'xterm -T "[fzf]" -bg "\%s" -fg "\%s" -geometry %dx%d+%d+%d -e bash -ic %%s'474 if has('gui_macvim')475 let fmt .= '&& osascript -e "tell application \"MacVim\" to activate"'476 endif477 return printf(fmt,478 \ synIDattr(hlID("Normal"), "bg"), synIDattr(hlID("Normal"), "fg"),479 \ &columns, &lines/2, getwinposx(), getwinposy())480endfunction481unlet! s:launcher

[vim] Add support for Cygwin (#933)Jan Edmund Lazobefore adoption7e483b0

line 482why, one step back
482if s:is_win || has('win32unix')

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 483–505why, one step back
483 let s:launcher = '%s'
484else485 let s:launcher = function('s:xterm_launcher')486endif487488function! s:exit_handler(code, command, ...)489 if a:code == 130490 return 0491 elseif a:code > 1492 call s:error('Error running ' . a:command)493 if !empty(a:000)494 sleep495 endif496 return 0497 endif498 return 1499endfunction500501function! s:execute(dict, command, use_height, temps) abort502 call s:pushd(a:dict)503 if has('unix') && !a:use_height504 silent! !clear 2> /dev/null505 endif

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

line 506why, one step back
506 let escaped = (a:use_height || s:is_win) ? a:command : escape(substitute(a:command, '\n', '\\n', 'g'), '%#!')

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 507–514why, one step back
507 if has('gui_running')
508 let Launcher = get(a:dict, 'launcher', get(g:, 'Fzf_launcher', get(g:, 'fzf_launcher', s:launcher)))509 let fmt = type(Launcher) == 2 ? call(Launcher, []) : Launcher510 if has('unix')511 let escaped = "'".substitute(escaped, "'", "'\"'\"'", 'g')."'"512 endif513 let command = printf(fmt, escaped)514 else

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

line 515why, one step back
515 let command = escaped

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

line 516why, one step back
516 endif

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

lines 517–518why, one step back
517 if s:is_win
518 let batchfile = s:fzf_tempname().'.bat'

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

line 519why, one step back
519 call writefile(s:wrap_cmds(command), batchfile)

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

line 520why, one step back
520 let command = batchfile

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

line 521why, one step back
521 let a:temps.batchfile = batchfile

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

lines 522–523why, one step back
522 if has('nvim')
523 let fzf = {}

[neovim] Fix lcd when fzf job exits on Windows (#970)Jan Edmund Lazobefore adoption940214a

lines 524–525why, one step back
524 let fzf.dict = a:dict
525 let fzf.temps = a:temps

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

line 526why, one step back
526 function! fzf.on_exit(job_id, exit_status, event) dict

[neovim] Fix lcd when fzf job exits on Windows (#970)Jan Edmund Lazobefore adoption940214a

lines 527–531why, one step back
527 if s:present(self.dict, 'dir')
528 execute 'lcd' s:escape(self.dict.dir)529 endif530 let lines = s:collect(self.temps)531 call s:callback(self.dict, lines)

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

lines 532–536why, one step back
532 endfunction
533 let cmd = 'start /wait cmd /c '.command534 call jobstart(cmd, fzf)535 return []536 endif

[vim] Add support for Cygwin (#933)Jan Edmund Lazobefore adoption7e483b0

lines 537–541why, one step back
537 elseif has('win32unix') && $TERM !=# 'cygwin'
538 let shellscript = s:fzf_tempname()539 call writefile([command], shellscript)540 let command = 'cmd.exe /C '.fzf#shellescape('set "TERM=" & start /WAIT sh -c '.shellscript)541 let a:temps.shellscript = shellscript

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

line 542why, one step back
542 endif

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 543–546why, one step back
543 if a:use_height
544 let stdin = has_key(a:dict, 'source') ? '' : '< /dev/tty'545 call system(printf('tput cup %d > /dev/tty; tput cnorm > /dev/tty; %s %s 2> /dev/tty', &lines, command, stdin))546 else

[vim] Minor refactoringJunegunn Choibefore adoptionb29375c

line 547why, one step back
547 execute 'silent !'.command

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 548–557why, one step back
548 endif
549 let exit_status = v:shell_error550 redraw!551 return s:exit_handler(exit_status, command) ? s:collect(a:temps) : []552endfunction553554function! s:execute_tmux(dict, command, temps) abort555 let command = a:command556 if s:pushd(a:dict)557 " -c '#{pane_current_path}' is only available on tmux 1.9 or above

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

line 558why, one step back
558 let command = join(['cd', fzf#shellescape(a:dict.dir), '&&', command])

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 559–627why, one step back
559 endif
560561 call system(command)562 let exit_status = v:shell_error563 redraw!564 return s:exit_handler(exit_status, command) ? s:collect(a:temps) : []565endfunction566567function! s:calc_size(max, val, dict)568 let val = substitute(a:val, '^\~', '', '')569 if val =~ '%$'570 let size = a:max * str2nr(val[:-2]) / 100571 else572 let size = min([a:max, str2nr(val)])573 endif574575 let srcsz = -1576 if type(get(a:dict, 'source', 0)) == type([])577 let srcsz = len(a:dict.source)578 endif579580 let opts = get(a:dict, 'options', '').$FZF_DEFAULT_OPTS581 let margin = stridx(opts, '--inline-info') > stridx(opts, '--no-inline-info') ? 1 : 2582 let margin += stridx(opts, '--header') > stridx(opts, '--no-header')583 return srcsz >= 0 ? min([srcsz + margin, size]) : size584endfunction585586function! s:getpos()587 return {'tab': tabpagenr(), 'win': winnr(), 'cnt': winnr('$'), 'tcnt': tabpagenr('$')}588endfunction589590function! s:split(dict)591 let directions = {592 \ 'up': ['topleft', 'resize', &lines],593 \ 'down': ['botright', 'resize', &lines],594 \ 'left': ['vertical topleft', 'vertical resize', &columns],595 \ 'right': ['vertical botright', 'vertical resize', &columns] }596 let ppos = s:getpos()597 try598 if s:present(a:dict, 'window')599 execute 'keepalt' a:dict.window600 elseif !s:splittable(a:dict)601 execute (tabpagenr()-1).'tabnew'602 else603 for [dir, triple] in items(directions)604 let val = get(a:dict, dir, '')605 if !empty(val)606 let [cmd, resz, max] = triple607 if (dir == 'up' || dir == 'down') && val[0] == '~'608 let sz = s:calc_size(max, val, a:dict)609 else610 let sz = s:calc_size(max, val, {})611 endif612 execute cmd sz.'new'613 execute resz sz614 return [ppos, {}]615 endif616 endfor617 endif618 return [ppos, { '&l:wfw': &l:wfw, '&l:wfh': &l:wfh }]619 finally620 setlocal winfixwidth winfixheight621 endtry622endfunction623624function! s:execute_term(dict, command, temps) abort625 let winrest = winrestcmd()626 let pbuf = bufnr('')627 let [ppos, winopts] = s:split(a:dict)

[vim] Expose buffer variable with the current fzf setup (#828)Kassio Borgesbefore adoption712b7b2

line 628why, one step back
628 let b:fzf = a:dict

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 629–686why, one step back
629 let fzf = { 'buf': bufnr(''), 'pbuf': pbuf, 'ppos': ppos, 'dict': a:dict, 'temps': a:temps,
630 \ 'winopts': winopts, 'winrest': winrest, 'lines': &lines,631 \ 'columns': &columns, 'command': a:command }632 function! fzf.switch_back(inplace)633 if a:inplace && bufnr('') == self.buf634 if bufexists(self.pbuf)635 execute 'keepalt b' self.pbuf636 endif637 " No other listed buffer638 if bufnr('') == self.buf639 enew640 endif641 endif642 endfunction643 function! fzf.on_exit(id, code, _event)644 if s:getpos() == self.ppos " {'window': 'enew'}645 for [opt, val] in items(self.winopts)646 execute 'let' opt '=' val647 endfor648 call self.switch_back(1)649 else650 if bufnr('') == self.buf651 " We use close instead of bd! since Vim does not close the split when652 " there's no other listed buffer (nvim +'set nobuflisted')653 close654 endif655 execute 'tabnext' self.ppos.tab656 execute self.ppos.win.'wincmd w'657 endif658659 if bufexists(self.buf)660 execute 'bd!' self.buf661 endif662663 if &lines == self.lines && &columns == self.columns && s:getpos() == self.ppos664 execute self.winrest665 endif666667 if !s:exit_handler(a:code, self.command, 1)668 return669 endif670671 call s:pushd(self.dict)672 let lines = s:collect(self.temps)673 call s:callback(self.dict, lines)674 call self.switch_back(s:getpos() == self.ppos)675 endfunction676677 try678 if s:present(a:dict, 'dir')679 execute 'lcd' s:escape(a:dict.dir)680 endif681 call termopen(a:command . ';#FZF', fzf)682 finally683 if s:present(a:dict, 'dir')684 lcd -685 endif686 endtry

[nvim] Disable number in fzf bufferJunegunn Choibefore adoptiona2604c0

line 687why, one step back
687 setlocal nospell bufhidden=wipe nobuflisted nonumber

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 688–717why, one step back
688 setf fzf
689 startinsert690 return []691endfunction692693function! s:collect(temps) abort694 try695 return filereadable(a:temps.result) ? readfile(a:temps.result) : []696 finally697 for tf in values(a:temps)698 silent! call delete(tf)699 endfor700 endtry701endfunction702703function! s:callback(dict, lines) abort704 " Since anything can be done in the sink function, there is no telling that705 " the change of the working directory was made by &autochdir setting.706 "707 " We use the following heuristic to determine whether to restore CWD:708 " - Always restore the current directory when &autochdir is disabled.709 " FIXME This makes it impossible to change directory from inside the sink710 " function when &autochdir is not used.711 " - In case of an error or an interrupt, a:lines will be empty.712 " And it will be an array of a single empty string when fzf was finished713 " without a match. In these cases, we presume that the change of the714 " directory is not expected and should be undone.715 let popd = has_key(a:dict, 'prev_dir') &&716 \ (!&autochdir || (empty(a:lines) || len(a:lines) == 1 && empty(a:lines[0])))717 if popd

[vim] Fix issues with other plugins changing working directoryJunegunn Choibefore adoption462c68b

line 718why, one step back
718 let w:fzf_dir = [a:dict.prev_dir, a:dict.dir]

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 719–741why, one step back
719 endif
720721 try722 if has_key(a:dict, 'sink')723 for line in a:lines724 if type(a:dict.sink) == 2725 call a:dict.sink(line)726 else727 execute a:dict.sink s:escape(line)728 endif729 endfor730 endif731 if has_key(a:dict, 'sink*')732 call a:dict['sink*'](a:lines)733 endif734 catch735 if stridx(v:exception, ':E325:') < 0736 echoerr v:exception737 endif738 endtry739740 " We may have opened a new window or tab741 if popd

[vim] Fix issues with other plugins changing working directoryJunegunn Choibefore adoption462c68b

line 742why, one step back
742 let w:fzf_dir = [a:dict.prev_dir, a:dict.dir]

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 743–753why, one step back
743 call s:dopopd()
744 endif745endfunction746747let s:default_action = {748 \ 'ctrl-t': 'tab split',749 \ 'ctrl-x': 'split',750 \ 'ctrl-v': 'vsplit' }751752function! s:shortpath()753 let short = pathshorten(fnamemodify(getcwd(), ':~:.'))

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

line 754why, one step back
754 let slash = (s:is_win && !&shellslash) ? '\' : '/'

[vim] Fix escape of backslash in s:shortpathJan Edmund Lazobefore adoption1fcc07e

line 755why, one step back
755 return empty(short) ? '~'.slash : short . (short =~ escape(slash, '\').'$' ? '' : slash)

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 756–759why, one step back
756endfunction
757758function! s:cmd(bang, ...) abort759 let args = copy(a:000)

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

line 760why, one step back
760 let opts = { 'options': ['--multi'] }

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 761–762why, one step back
761 if len(args) && isdirectory(expand(args[-1]))
762 let opts.dir = substitute(substitute(remove(args, -1), '\\\(["'']\)', '\1', 'g'), '[/\\]*$', '/', '')

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

lines 763–766why, one step back
763 if s:is_win && !&shellslash
764 let opts.dir = substitute(opts.dir, '/', '\\', 'g')765 endif766 let prompt = opts.dir

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

line 767why, one step back
767 else

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

line 768why, one step back
768 let prompt = s:shortpath()

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

line 769why, one step back
769 endif

[vim] Use backslash for Windows filepaths (#896)Jan Edmund Lazobefore adoption7a11a06

lines 770–771why, one step back
770 call extend(opts.options, ['--prompt', prompt])
771 call extend(opts.options, args)

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 772–778why, one step back
772 call fzf#run(fzf#wrap('FZF', opts, a:bang))
773endfunction774775command! -nargs=* -complete=dir -bang FZF call s:cmd(<bang>0, <f-args>)776777let &cpo = s:cpo_save778unlet s:cpo_save