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

1" Copyright (c) 2017 Junegunn Choi2"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 = 12829let 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  endfunction4748  " Use utf-8 for fzf.vim commands49  " 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']54  endfunction55else56  function! s:fzf_call(fn, ...)57    return call(a:fn, a:000)58  endfunction5960  function! s:wrap_cmds(cmds)61    return a:cmds62  endfunction63endif6465function! 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)79endfunction8081function! 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)90  return s:fzf_call('expand', a:fmt, 1)91endfunction9293function! s:fzf_tempname()94  return s:fzf_call('tempname')95endfunction9697let s:default_layout = { 'down': '~40%' }98let s:layout_keys = ['window', 'up', 'down', 'left', 'right']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'102let s:installed = 0103104let s:cpo_save = &cpo105set cpo&vim106107function! s:fzf_exec()108  if !exists('s:exec')109    if executable(s:fzf_go)110      let s:exec = s:fzf_go111    elseif executable('fzf')112      let s:exec = 'fzf'113    elseif s:is_win && !has('win32unix')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'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  endif131  return fzf#shellescape(s:exec)132endfunction133134function! 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)152  let escaped_chars = '$%#''"'153154  if has('unix')155    let escaped_chars .= ' \'156  endif157158  return escape(a:path, escaped_chars)159endfunction160161" 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)198  if stridx('edit', a:cmd) == 0 && s:fzf_fnamemodify(a:target, ':p') ==# s:fzf_expand('%:p')199    return200  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'213            \| call s:warn('fzf: E325: swap file exists: '.s:fzf_expand('<afile>'))214    augroup END215  endif216  try217    let empty = empty(s:fzf_expand('%')) && line('$') == 1 && empty(getline(1)) && !&modified218    let autochdir = &autochdir219    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      endif227      if !has('patch-8.0.0177') && !has('nvim-0.2') && exists('#BufEnter')228            \ && isdirectory(item)229        doautocmd BufEnter230      endif231    endfor232  finally233    let &autochdir = autochdir234    silent! autocmd! fzf_swap235  endtry236endfunction237238function! s:get_color(attr, ...)239  let gui = has('termguicolors') && &termguicolors240  let fam = gui ? 'gui' : 'cterm'241  let pat = gui ? '^#[a-f0-9]\+' : '^[0-9]\+$'242  for group in a:000243    let code = synIDattr(synIDtrans(hlID(group)), a:attr, fam)244    if code =~? pat245      return code246    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)255endfunction256257function! s:validate_layout(layout)258  for key in keys(a:layout)259    if index(s:layout_keys, key) < 0260      throw printf('Invalid entry in g:fzf_layout: %s (allowed: %s)%s',261            \ key, join(s:layout_keys, ', '), key == 'options' ? '. Use $FZF_DEFAULT_OPTS.' : '')262    endif263  endfor264  return a:layout265endfunction266267function! s:evaluate_opts(options)268  return type(a:options) == type([]) ?269        \ join(map(copy(a:options), 'fzf#shellescape(v:val)')) : a:options270endfunction271272" [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 < 0280      throw 'Invalid arguments (expected: [name string] [opts dict] [fullscreen boolean])'281    endif282    let args[tidx] = arg283    let tidx += 1284    unlet arg285  endfor286  let [name, opts, bang] = args287288  if len(name)289    let opts.name = name290  end291292  " 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    else303      let opts = extend(opts, s:validate_layout(get(g:, 'fzf_layout', s:default_layout)))304    endif305  endif306307  " Colors: g:fzf_colors308  let opts.options = s:defaults() .' '. s:evaluate_opts(get(opts, 'options', ''))309310  " History: g:fzf_history_dir311  if len(name) && len(get(g:, 'fzf_history_dir', ''))312    let dir = s:fzf_expand(g:fzf_history_dir)313    if !isdirectory(dir)314      call mkdir(dir, 'p')315    endif316    let history = fzf#shellescape(dir.'/'.name)317    let opts.options = join(['--history', history, opts.options])318  endif319320  " 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 = &shell336  let useshellslash = &shellslash337338  if s:is_win339    set shell=cmd.exe340    set noshellslash341  else342    set shell=sh343  endif344345  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    endif351  endif352  let dict   = exists('a:1') ? s:upgrade(a:1) : {}353  let temps  = { 'result': s:fzf_tempname() }354  let optstr = s:evaluate_opts(get(dict, 'options', ''))355  try356    let fzf_exec = s:fzf_exec()357  catch358    throw v:exception359  endtry360361  if has('nvim') && !has_key(dict, 'dir')362    let dict.dir = s:fzf_getcwd()363  endif364  if has('win32unix') && has_key(dict, 'dir')365    let dict.dir = fnamemodify(dict.dir, ':p')366  endif367368  if !has_key(dict, 'source') && !empty($FZF_DEFAULT_COMMAND) && !s:is_win369    let temps.source = s:fzf_tempname()370    call writefile(s:wrap_cmds(split($FZF_DEFAULT_COMMAND, "\n")), temps.source)371    let dict.source = (empty($SHELL) ? &shell : $SHELL).' '.fzf#shellescape(temps.source)372  endif373374  if has_key(dict, 'source')375    let source = dict.source376    let type = type(source)377    if type == 1378      let prefix = source.'|'379    elseif type == 3380      let temps.input = s:fzf_tempname()381      call writefile(source, temps.input)382      let prefix = (s:is_win ? 'type ' : 'cat ').fzf#shellescape(temps.input).'|'383    else384      throw 'Invalid source type'385    endif386  else387    let prefix = ''388  endif389390  let prefer_tmux = get(g:, 'fzf_prefer_tmux', 0)391  let use_height = has_key(dict, 'down') &&392        \ !(has('nvim') || s:is_win || has('win32unix') || s:present(dict, 'up', 'left', 'right')) &&393        \ executable('tput') && filereadable('/dev/tty')394  let use_term = has('nvim') && !s:is_win395  let use_tmux = (!use_height && !use_term || prefer_tmux) && !has('win32unix') && s:tmux_enabled() && s:splittable(dict)396  if prefer_tmux && use_tmux397    let use_height = 0398    let use_term = 0399  endif400  if use_height401    let height = s:calc_size(&lines, dict.down, dict)402    let optstr .= ' --height='.height403  elseif use_term404    let optstr .= ' --no-height'405  endif406  let command = prefix.(use_tmux ? s:fzf_tmux(dict) : fzf_exec).' '.optstr.' > '.temps.result407408  if use_term409    return s:execute_term(dict, command, temps)410  endif411412  let lines = use_tmux ? s:execute_tmux(dict, command, temps)413                 \ : s:execute(dict, command, use_height, temps)414  call s:callback(dict, lines)415  return lines416finally417  let &shell = oshell418  let &shellslash = useshellslash419endtry420endfunction421422function! 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 --',446    \ &lines, &columns, fzf#shellescape(s:fzf_tmux), size, (has_key(a:dict, 'source') ? '' : '-'))447endfunction448449function! 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')456    let cwd = s:fzf_getcwd()457    if get(a:dict, 'prev_dir', '') ==# cwd458      return 1459    endif460    let a:dict.prev_dir = cwd461    execute 'lcd' s:escape(a:dict.dir)462    let a:dict.dir = s:fzf_getcwd()463    return 1464  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:launcher491if s:is_win || has('win32unix')492  let s:launcher = '%s'493else494  let s:launcher = function('s:xterm_launcher')495endif496497function! 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 1508endfunction509510function! s:execute(dict, command, use_height, temps) abort511  call s:pushd(a:dict)512  if has('unix') && !a:use_height513    silent! !clear 2> /dev/null514  endif515  let escaped = (a:use_height || s:is_win) ? a:command : escape(substitute(a:command, '\n', '\\n', 'g'), '%#!')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, []) : Launcher519    if has('unix')520      let escaped = "'".substitute(escaped, "'", "'\"'\"'", 'g')."'"521    endif522    let command = printf(fmt, escaped)523  else524    let command = escaped525  endif526  if s:is_win527    let batchfile = s:fzf_tempname().'.bat'528    call writefile(s:wrap_cmds(command), batchfile)529    let command = batchfile530    let a:temps.batchfile = batchfile531    if has('nvim')532      let fzf = {}533      let fzf.dict = a:dict534      let fzf.temps = a:temps535      function! fzf.on_exit(job_id, exit_status, event) dict536        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)541      endfunction542      let cmd = 'start /wait cmd /c '.command543      call jobstart(cmd, fzf)544      return []545    endif546  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 = shellscript551  endif552  if a:use_height553    let stdin = has_key(a:dict, 'source') ? '' : '< /dev/tty'554    call system(printf('tput cup %d > /dev/tty; tput cnorm > /dev/tty; %s %s 2> /dev/tty', &lines, command, stdin))555  else556    execute 'silent !'.command557  endif558  let exit_status = v:shell_error559  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 above567    let command = join(['cd', fzf#shellescape(a:dict.dir), '&&', command])568  endif569570  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')608      execute 'keepalt' a:dict.window609    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()635  let pbuf = bufnr('')636  let [ppos, winopts] = s:split(a:dict)637  let b:fzf = a:dict638  let fzf = { 'buf': bufnr(''), 'pbuf': pbuf, 'ppos': ppos, 'dict': a:dict, 'temps': a:temps,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.buf643      if bufexists(self.pbuf)644        execute 'keepalt b' self.pbuf645      endif646      " No other listed buffer647      if bufnr('') == self.buf648        enew649      endif650    endif651  endfunction652  function! fzf.on_exit(id, code, _event)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' }760761function! s:shortpath()762  let short = pathshorten(fnamemodify(getcwd(), ':~:.'))763  let slash = (s:is_win && !&shellslash) ? '\' : '/'764  return empty(short) ? '~'.slash : short . (short =~ slash.'$' ? '' : slash)765endfunction766767function! s:cmd(bang, ...) abort768  let args = copy(a:000)769  let opts = { 'options': ['--multi'] }770  if len(args) && isdirectory(expand(args[-1]))771    let opts.dir = substitute(substitute(remove(args, -1), '\\\(["'']\)', '\1', 'g'), '[/\\]*$', '/', '')772    if s:is_win && !&shellslash773      let opts.dir = substitute(opts.dir, '/', '\\', 'g')774    endif775    let prompt = opts.dir776  else777    let prompt = s:shortpath()778  endif779  call extend(opts.options, ['--prompt', prompt])780  call extend(opts.options, args)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