Skip to content
Myr

fzf.vim

This file

Path

plugin/fzf.vim

787 lines · 22.1 KiB

Last changed by

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

History of this file

Take it

The walk stopped after 200 commits: lines older than 0a8d299 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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

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–80why, 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')69 let escaped = substitute(escaped, '\\\+\(\\^\)', '\\\\\1', 'g')70 return '^"'.substitute(escaped, '[^\\]\zs\\$', '\\\\', '').'^"'71endfunction7273function! 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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

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'

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

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'

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

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)

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

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 cmd.exe in Windows (#785)Jan Edmund Lazobefore adoption42a2371

lines 152–158why, one step back
152 let escaped_chars = '$%#''"'
153154 if has('unix')155 let escaped_chars .= ' \'156 endif157158 return escape(a:path, escaped_chars)

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 159–197why, one step back
159endfunction
160161" Upgrade legacy options162function! s:upgrade(dict)163 let copy = copy(a:dict)164 if has_key(copy, 'tmux')165 let copy.down = remove(copy, 'tmux')166 endif167 if has_key(copy, 'tmux_height')168 let copy.down = remove(copy, 'tmux_height')169 endif170 if has_key(copy, 'tmux_width')171 let copy.right = remove(copy, 'tmux_width')172 endif173 return copy174endfunction175176function! s:error(msg)177 echohl ErrorMsg178 echom a:msg179 echohl None180endfunction181182function! s:warn(msg)183 echohl WarningMsg184 echom a:msg185 echohl None186endfunction187188function! s:has_any(dict, keys)189 for key in a:keys190 if has_key(a:dict, key)191 return 1192 endif193 endfor194 return 0195endfunction196197function! s:open(cmd, target)

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

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 199–212why, one step back
199 return
200 endif201 execute a:cmd s:escape(a:target)202endfunction203204function! s:common_sink(action, lines) abort205 if len(a:lines) < 2206 return207 endif208 let key = remove(a:lines, 0)209 let cmd = get(a:action, key, 'e')210 if len(a:lines) > 1211 augroup fzf_swap212 autocmd SwapExists * let v:swapchoice='o'

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

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 214–216why, one step back
214 augroup END
215 endif216 try

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

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 218–226why, one step back
218 let autochdir = &autochdir
219 set noautochdir220 for item in a:lines221 if empty222 execute 'e' s:escape(item)223 let empty = 0224 else225 call s:open(cmd, item)226 endif

s:common_sink(): Avoid duplicate BufEnter. (#803)Justin M. Keyesbefore adoption1896aa1

lines 227–228why, one step back
227 if !has('patch-8.0.0177') && !has('nvim-0.2') && exists('#BufEnter')
228 \ && isdirectory(item)

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 229–237why, one step back
229 doautocmd BufEnter
230 endif231 endfor232 finally233 let &autochdir = autochdir234 silent! autocmd! fzf_swap235 endtry236endfunction237

[vim] Respect g:fzf_colorsJunegunn Choibefore adoption37f2d8f

line 238why, one step back
238function! s:get_color(attr, ...)

[vim] Use 24-bit colors if termguicolors is setJunegunn Choibefore adoptioncbb5134

lines 239–241why, one step back
239 let gui = has('termguicolors') && &termguicolors
240 let fam = gui ? 'gui' : 'cterm'241 let pat = gui ? '^#[a-f0-9]\+' : '^[0-9]\+$'

[vim] Respect g:fzf_colorsJunegunn Choibefore adoption37f2d8f

line 242why, one step back
242 for group in a:000

[vim] Use 24-bit colors if termguicolors is setJunegunn Choibefore adoptioncbb5134

lines 243–244why, one step back
243 let code = synIDattr(synIDtrans(hlID(group)), a:attr, fam)
244 if code =~? pat

[vim] Respect g:fzf_colorsJunegunn Choibefore adoption37f2d8f

lines 245–256why, one step back
245 return code
246 endif247 endfor248 return ''249endfunction250251function! s:defaults()252 let rules = copy(get(g:, 'fzf_colors', {}))253 let colors = join(map(items(filter(map(rules, 'call("s:get_color", v:val)'), '!empty(v:val)')), 'join(v:val, ":")'), ',')254 return empty(colors) ? '' : ('--color='.colors)255endfunction256

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

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

[vim] Capitalize exception messagesJunegunn Choibefore adoptiona484811

line 260why, one step back
260 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 261–266why, one step back
261 \ key, join(s:layout_keys, ', '), key == 'options' ? '. Use $FZF_DEFAULT_OPTS.' : '')
262 endif263 endfor264 return a:layout265endfunction266

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

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

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

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

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

lines 270–271why, one step back
270endfunction
271

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

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

[vim] Capitalize exception messagesJunegunn Choibefore adoptiona484811

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 281–287why, one step back
281 endif
282 let args[tidx] = arg283 let tidx += 1284 unlet arg285 endfor286 let [name, opts, bang] = args287

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

lines 288–291why, one step back
288 if len(name)
289 let opts.name = name290 end291

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 292–302why, one step back
292 " Layout: g:fzf_layout (and deprecated g:fzf_height)
293 if bang294 for key in s:layout_keys295 if has_key(opts, key)296 call remove(opts, key)297 endif298 endfor299 elseif !s:has_any(opts, s:layout_keys)300 if !exists('g:fzf_layout') && exists('g:fzf_height')301 let opts.down = g:fzf_height302 else

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

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 304–306why, one step back
304 endif
305 endif306

[vim] Respect g:fzf_colorsJunegunn Choibefore adoption37f2d8f

line 307why, one step back
307 " Colors: g:fzf_colors

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

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

[vim] Respect g:fzf_colorsJunegunn Choibefore adoption37f2d8f

line 309why, one step back
309

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 310–311why, one step back
310 " History: g:fzf_history_dir
311 if len(name) && len(get(g:, 'fzf_history_dir', ''))

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

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

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

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

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

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

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 318–335why, one step back
318 endif
319320 " Action: g:fzf_action321 if !s:has_any(opts, ['sink', 'sink*'])322 let opts._action = get(g:, 'fzf_action', s:default_action)323 let opts.options .= ' --expect='.join(keys(opts._action), ',')324 function! opts.sink(lines) abort325 return s:common_sink(self._action, a:lines)326 endfunction327 let opts['sink*'] = remove(opts, 'sink')328 endif329330 return opts331endfunction332333function! fzf#run(...) abort334try335 let oshell = &shell

[vim] Use cmd.exe in Windows (#785)Jan Edmund Lazobefore adoption42a2371

lines 336–337why, one step back
336 let useshellslash = &shellslash
337

[vim] Download instruction for WindowsJunegunn Choibefore adoption02ceae1

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

[vim] Use cmd.exe in Windows (#785)Jan Edmund Lazobefore adoption42a2371

line 339why, one step back
339 set shell=cmd.exe

[vim] FZF command to handle Windows paths with spacesJan Edmund Lazobefore adoption6c0fd7f

line 340why, one step back
340 set noshellslash

[vim] Use cmd.exe in Windows (#785)Jan Edmund Lazobefore adoption42a2371

lines 341–344why, one step back
341 else
342 set shell=sh343 endif344

fzf#run: improve "is already running" message (#885)Daniel Hahlerbefore adoptiond295d20

lines 345–350why, one step back
345 if has('nvim')
346 let running = filter(range(1, bufnr('$')), "bufname(v:val) =~# ';#FZF'")347 if len(running)348 call s:warn('FZF is already running (in buffer '.join(running, ', ').')!')349 return []350 endif

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 351–352why, one step back
351 endif
352 let dict = exists('a:1') ? s:upgrade(a:1) : {}

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

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 355–360why, one step back
355 try
356 let fzf_exec = s:fzf_exec()357 catch358 throw v:exception359 endtry360

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

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

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

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

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

line 363why, one step back
363 endif

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

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

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

line 367why, one step back
367

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

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

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

line 370why, one step back
370 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 371why, one step back
371 let dict.source = (empty($SHELL) ? &shell : $SHELL).' '.fzf#shellescape(temps.source)

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 372–379why, one step back
372 endif
373374 if has_key(dict, 'source')375 let source = dict.source376 let type = type(source)377 if type == 1378 let prefix = source.'|'379 elseif type == 3

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

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

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

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

line 383why, one step back
383 else

[vim] Capitalize exception messagesJunegunn Choibefore adoptiona484811

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 385–388why, one step back
385 endif
386 else387 let prefix = ''388 endif

Merge pull request #794 from junegunn/develJunegunn Choibefore adoption05ed57a

line 389why, one step back
389

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

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

Merge pull request #794 from junegunn/develJunegunn Choibefore adoption05ed57a

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

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

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

Merge pull request #794 from junegunn/develJunegunn Choibefore adoption05ed57a

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

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

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

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

line 395why, one step back
395 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 396–399why, one step back
396 if prefer_tmux && use_tmux
397 let use_height = 0398 let use_term = 0399 endif

Merge pull request #794 from junegunn/develJunegunn Choibefore adoption05ed57a

line 400why, one step back
400 if use_height

Merge branch 'master' into develJunegunn Choibefore adoption33f32de

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

[vim] Download instruction for WindowsJunegunn Choibefore adoption02ceae1

line 403why, one step back
403 elseif use_term

Merge pull request #794 from junegunn/develJunegunn Choibefore adoption05ed57a

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

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

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

line 407why, one step back
407

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

line 408why, one step back
408 if use_term

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 409–411why, one step back
409 return s:execute_term(dict, command, temps)
410 endif411

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

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

Merge pull request #794 from junegunn/develJunegunn Choibefore adoption05ed57a

line 413why, one step back
413 \ : s:execute(dict, command, use_height, temps)

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 414–417why, one step back
414 call s:callback(dict, lines)
415 return lines416finally417 let &shell = oshell

[vim] Use cmd.exe in Windows (#785)Jan Edmund Lazobefore adoption42a2371

line 418why, one step back
418 let &shellslash = useshellslash

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 419–445why, one step back
419endtry
420endfunction421422function! s:present(dict, ...)423 for key in a:000424 if !empty(get(a:dict, key, ''))425 return 1426 endif427 endfor428 return 0429endfunction430431function! s:fzf_tmux(dict)432 let size = ''433 for o in ['up', 'down', 'left', 'right']434 if s:present(a:dict, o)435 let spec = a:dict[o]436 if (o == 'up' || o == 'down') && spec[0] == '~'437 let size = '-'.o[0].s:calc_size(&lines, spec, a:dict)438 else439 " Legacy boolean option440 let size = '-'.o[0].(spec == 1 ? '' : substitute(spec, '^\~', '', ''))441 endif442 break443 endif444 endfor445 return printf('LINES=%d COLUMNS=%d %s %s %s --',

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 447–455why, one step back
447endfunction
448449function! s:splittable(dict)450 return s:present(a:dict, 'up', 'down') && &lines > 15 ||451 \ s:present(a:dict, 'left', 'right') && &columns > 40452endfunction453454function! s:pushd(dict)455 if s:present(a:dict, 'dir')

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

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 457–461why, one step back
457 if get(a:dict, 'prev_dir', '') ==# cwd
458 return 1459 endif460 let a:dict.prev_dir = cwd461 execute 'lcd' s:escape(a:dict.dir)

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

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 463–490why, one step back
463 return 1
464 endif465 return 0466endfunction467468augroup fzf_popd469 autocmd!470 autocmd WinEnter * call s:dopopd()471augroup END472473function! s:dopopd()474 if !exists('w:fzf_prev_dir') || exists('*haslocaldir') && !haslocaldir()475 return476 endif477 execute 'lcd' s:escape(w:fzf_prev_dir)478 unlet w:fzf_prev_dir479endfunction480481function! s:xterm_launcher()482 let fmt = 'xterm -T "[fzf]" -bg "\%s" -fg "\%s" -geometry %dx%d+%d+%d -e bash -ic %%s'483 if has('gui_macvim')484 let fmt .= '&& osascript -e "tell application \"MacVim\" to activate"'485 endif486 return printf(fmt,487 \ synIDattr(hlID("Normal"), "bg"), synIDattr(hlID("Normal"), "fg"),488 \ &columns, &lines/2, getwinposx(), getwinposy())489endfunction490unlet! s:launcher

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

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

[vim] Use cmd.exe directly on GVim (launcher='%s') (#787)Jan Edmund Lazobefore adoption3670273

line 492why, one step back
492 let s:launcher = '%s'

[vim] Use cmd.exe in Windows (#785)Jan Edmund Lazobefore adoption42a2371

lines 493–495why, one step back
493else
494 let s:launcher = function('s:xterm_launcher')495endif

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 496–509why, one step back
496
497function! s:exit_handler(code, command, ...)498 if a:code == 130499 return 0500 elseif a:code > 1501 call s:error('Error running ' . a:command)502 if !empty(a:000)503 sleep504 endif505 return 0506 endif507 return 1508endfunction509

Merge pull request #794 from junegunn/develJunegunn Choibefore adoption05ed57a

line 510why, one step back
510function! s:execute(dict, command, use_height, temps) abort

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

line 511why, one step back
511 call s:pushd(a:dict)

Merge pull request #794 from junegunn/develJunegunn Choibefore adoption05ed57a

line 512why, one step back
512 if has('unix') && !a:use_height

[vim] Use cmd.exe in Windows (#785)Jan Edmund Lazobefore adoption42a2371

lines 513–514why, one step back
513 silent! !clear 2> /dev/null
514 endif

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 516–518why, one step back
516 if has('gui_running')
517 let Launcher = get(a:dict, 'launcher', get(g:, 'Fzf_launcher', get(g:, 'fzf_launcher', s:launcher)))518 let fmt = type(Launcher) == 2 ? call(Launcher, []) : Launcher

[vim] Use cmd.exe in Windows (#785)Jan Edmund Lazobefore adoption42a2371

lines 519–522why, one step back
519 if has('unix')
520 let escaped = "'".substitute(escaped, "'", "'\"'\"'", 'g')."'"521 endif522 let command = printf(fmt, escaped)

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

line 523why, one step back
523 else

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

line 525why, one step back
525 endif

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

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

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

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

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

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

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

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

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

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

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

lines 533–534why, one step back
533 let fzf.dict = a:dict
534 let fzf.temps = a:temps

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

line 535why, one step back
535 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 536–540why, one step back
536 if s:present(self.dict, 'dir')
537 execute 'lcd' s:escape(self.dict.dir)538 endif539 let lines = s:collect(self.temps)540 call s:callback(self.dict, lines)

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

lines 541–545why, one step back
541 endfunction
542 let cmd = 'start /wait cmd /c '.command543 call jobstart(cmd, fzf)544 return []545 endif

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

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

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

line 551why, one step back
551 endif

Merge pull request #794 from junegunn/develJunegunn Choibefore adoption05ed57a

lines 552–553why, one step back
552 if a:use_height
553 let stdin = has_key(a:dict, 'source') ? '' : '< /dev/tty'

Clear lines even when background color is not setJunegunn Choibefore adoption2a669e9

line 554why, one step back
554 call system(printf('tput cup %d > /dev/tty; tput cnorm > /dev/tty; %s %s 2> /dev/tty', &lines, command, stdin))

Merge pull request #794 from junegunn/develJunegunn Choibefore adoption05ed57a

line 555why, one step back
555 else

[vim] Minor refactoringJunegunn Choibefore adoptionb29375c

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

Merge pull request #794 from junegunn/develJunegunn Choibefore adoption05ed57a

line 557why, one step back
557 endif

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 558–566why, one step back
558 let exit_status = v:shell_error
559 redraw!560 return s:exit_handler(exit_status, command) ? s:collect(a:temps) : []561endfunction562563function! s:execute_tmux(dict, command, temps) abort564 let command = a:command565 if s:pushd(a:dict)566 " -c '#{pane_current_path}' is only available on tmux 1.9 or above

Merge branch 'master' into develJunegunn Choibefore adoptionf4731c0

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 568–607why, one step back
568 endif
569570 call system(command)571 let exit_status = v:shell_error572 redraw!573 return s:exit_handler(exit_status, command) ? s:collect(a:temps) : []574endfunction575576function! s:calc_size(max, val, dict)577 let val = substitute(a:val, '^\~', '', '')578 if val =~ '%$'579 let size = a:max * str2nr(val[:-2]) / 100580 else581 let size = min([a:max, str2nr(val)])582 endif583584 let srcsz = -1585 if type(get(a:dict, 'source', 0)) == type([])586 let srcsz = len(a:dict.source)587 endif588589 let opts = get(a:dict, 'options', '').$FZF_DEFAULT_OPTS590 let margin = stridx(opts, '--inline-info') > stridx(opts, '--no-inline-info') ? 1 : 2591 let margin += stridx(opts, '--header') > stridx(opts, '--no-header')592 return srcsz >= 0 ? min([srcsz + margin, size]) : size593endfunction594595function! s:getpos()596 return {'tab': tabpagenr(), 'win': winnr(), 'cnt': winnr('$'), 'tcnt': tabpagenr('$')}597endfunction598599function! s:split(dict)600 let directions = {601 \ 'up': ['topleft', 'resize', &lines],602 \ 'down': ['botright', 'resize', &lines],603 \ 'left': ['vertical topleft', 'vertical resize', &columns],604 \ 'right': ['vertical botright', 'vertical resize', &columns] }605 let ppos = s:getpos()606 try607 if s:present(a:dict, 'window')

[neovim] Keep alternate file unchangedJunegunn Choibefore adoptionc60bfb2

line 608why, one step back
608 execute 'keepalt' a:dict.window

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 609–634why, one step back
609 elseif !s:splittable(a:dict)
610 execute (tabpagenr()-1).'tabnew'611 else612 for [dir, triple] in items(directions)613 let val = get(a:dict, dir, '')614 if !empty(val)615 let [cmd, resz, max] = triple616 if (dir == 'up' || dir == 'down') && val[0] == '~'617 let sz = s:calc_size(max, val, a:dict)618 else619 let sz = s:calc_size(max, val, {})620 endif621 execute cmd sz.'new'622 execute resz sz623 return [ppos, {}]624 endif625 endfor626 endif627 return [ppos, { '&l:wfw': &l:wfw, '&l:wfh': &l:wfh }]628 finally629 setlocal winfixwidth winfixheight630 endtry631endfunction632633function! s:execute_term(dict, command, temps) abort634 let winrest = winrestcmd()

[neovim] Keep alternate file unchangedJunegunn Choibefore adoptionc60bfb2

line 635why, one step back
635 let pbuf = bufnr('')

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

line 636why, one step back
636 let [ppos, winopts] = s:split(a:dict)

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

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

[neovim] Keep alternate file unchangedJunegunn Choibefore adoptionc60bfb2

line 638why, one step back
638 let fzf = { 'buf': bufnr(''), 'pbuf': pbuf, 'ppos': ppos, 'dict': a:dict, 'temps': a:temps,

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 639–642why, one step back
639 \ 'winopts': winopts, 'winrest': winrest, 'lines': &lines,
640 \ 'columns': &columns, 'command': a:command }641 function! fzf.switch_back(inplace)642 if a:inplace && bufnr('') == self.buf

s:execute_term: switch_back: check that self.pbuf exists (#776)Daniel Hahlerbefore adoption847c512

lines 643–645why, one step back
643 if bufexists(self.pbuf)
644 execute 'keepalt b' self.pbuf645 endif

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 646–651why, one step back
646 " No other listed buffer
647 if bufnr('') == self.buf648 enew649 endif650 endif651 endfunction

Neovim: event handlers always expect three arguments (#768)Marco Hinzbefore adoption8a502af

line 652why, one step back
652 function! fzf.on_exit(id, code, _event)

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 653–760why, one step back
653 if s:getpos() == self.ppos " {'window': 'enew'}
654 for [opt, val] in items(self.winopts)655 execute 'let' opt '=' val656 endfor657 call self.switch_back(1)658 else659 if bufnr('') == self.buf660 " We use close instead of bd! since Vim does not close the split when661 " there's no other listed buffer (nvim +'set nobuflisted')662 close663 endif664 execute 'tabnext' self.ppos.tab665 execute self.ppos.win.'wincmd w'666 endif667668 if bufexists(self.buf)669 execute 'bd!' self.buf670 endif671672 if &lines == self.lines && &columns == self.columns && s:getpos() == self.ppos673 execute self.winrest674 endif675676 if !s:exit_handler(a:code, self.command, 1)677 return678 endif679680 call s:pushd(self.dict)681 let lines = s:collect(self.temps)682 call s:callback(self.dict, lines)683 call self.switch_back(s:getpos() == self.ppos)684 endfunction685686 try687 if s:present(a:dict, 'dir')688 execute 'lcd' s:escape(a:dict.dir)689 endif690 call termopen(a:command . ';#FZF', fzf)691 finally692 if s:present(a:dict, 'dir')693 lcd -694 endif695 endtry696 setlocal nospell bufhidden=wipe nobuflisted697 setf fzf698 startinsert699 return []700endfunction701702function! s:collect(temps) abort703 try704 return filereadable(a:temps.result) ? readfile(a:temps.result) : []705 finally706 for tf in values(a:temps)707 silent! call delete(tf)708 endfor709 endtry710endfunction711712function! s:callback(dict, lines) abort713 " Since anything can be done in the sink function, there is no telling that714 " the change of the working directory was made by &autochdir setting.715 "716 " We use the following heuristic to determine whether to restore CWD:717 " - Always restore the current directory when &autochdir is disabled.718 " FIXME This makes it impossible to change directory from inside the sink719 " function when &autochdir is not used.720 " - In case of an error or an interrupt, a:lines will be empty.721 " And it will be an array of a single empty string when fzf was finished722 " without a match. In these cases, we presume that the change of the723 " directory is not expected and should be undone.724 let popd = has_key(a:dict, 'prev_dir') &&725 \ (!&autochdir || (empty(a:lines) || len(a:lines) == 1 && empty(a:lines[0])))726 if popd727 let w:fzf_prev_dir = a:dict.prev_dir728 endif729730 try731 if has_key(a:dict, 'sink')732 for line in a:lines733 if type(a:dict.sink) == 2734 call a:dict.sink(line)735 else736 execute a:dict.sink s:escape(line)737 endif738 endfor739 endif740 if has_key(a:dict, 'sink*')741 call a:dict['sink*'](a:lines)742 endif743 catch744 if stridx(v:exception, ':E325:') < 0745 echoerr v:exception746 endif747 endtry748749 " We may have opened a new window or tab750 if popd751 let w:fzf_prev_dir = a:dict.prev_dir752 call s:dopopd()753 endif754endfunction755756let s:default_action = {757 \ 'ctrl-t': 'tab split',758 \ 'ctrl-x': 'split',759 \ 'ctrl-v': 'vsplit' }760

[vim] Fix path display in FZF when cwd is ~Junegunn Choibefore adoptionab9ae4f

lines 761–762why, one step back
761function! s:shortpath()
762 let short = pathshorten(fnamemodify(getcwd(), ':~:.'))

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

lines 763–764why, one step back
763 let slash = (s:is_win && !&shellslash) ? '\' : '/'
764 return empty(short) ? '~'.slash : short . (short =~ slash.'$' ? '' : slash)

[vim] Fix path display in FZF when cwd is ~Junegunn Choibefore adoptionab9ae4f

lines 765–766why, one step back
765endfunction
766

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 767–768why, one step back
767function! s:cmd(bang, ...) abort
768 let args = copy(a:000)

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

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

line 770why, one step back
770 if len(args) && isdirectory(expand(args[-1]))

[vim] FZF command to handle Windows paths with spacesJan Edmund Lazobefore adoption6c0fd7f

line 771why, one step back
771 let opts.dir = substitute(substitute(remove(args, -1), '\\\(["'']\)', '\1', 'g'), '[/\\]*$', '/', '')

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

lines 772–775why, one step back
772 if s:is_win && !&shellslash
773 let opts.dir = substitute(opts.dir, '/', '\\', 'g')774 endif775 let prompt = opts.dir

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

line 776why, one step back
776 else

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

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

line 778why, one step back
778 endif

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

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

Set foreground color without affecting backgroundJunegunn Choibefore adoption0a8d299

lines 781–787why, one step back
781 call fzf#run(fzf#wrap('FZF', opts, a:bang))
782endfunction783784command! -nargs=* -complete=dir -bang FZF call s:cmd(<bang>0, <f-args>)785786let &cpo = s:cpo_save787unlet s:cpo_save