diff options
author | Yanlin Sun <yanlin.sun@gmail.com> | 2020-07-15 16:20:56 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-15 13:20:56 +0900 |
commit | f79b1f71b86651fe5656eab1c360781e19e97826 (patch) | |
tree | 731fd262b07bd5cae34bd2f0c2e306bae720b60a /plugin | |
parent | 8e027c445f0eb4495e300522843df335c3b54e60 (diff) |
[vim] Preserve current directory in case someone changes it (#2096)
Preserve current directory in case current directory is changed by others
after the call of s:open
Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/fzf.vim | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/plugin/fzf.vim b/plugin/fzf.vim index e1a5d3da..59b030fd 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -236,9 +236,13 @@ function! s:common_sink(action, lines) abort endif try let empty = empty(s:fzf_expand('%')) && line('$') == 1 && empty(getline(1)) && !&modified - let autochdir = &autochdir - set noautochdir + " Preserve the current working directory in case it's changed during + " the execution (e.g. `set autochdir` or `autocmd BufEnter * lcd ...`) + let cwd = exists('w:fzf_pushd') ? w:fzf_pushd.dir : expand('%:p:h') for item in a:lines + if item[0] != '~' && item !~ (s:is_win ? '^[A-Z]:\' : '^/') + let item = join([cwd, item], (s:is_win ? '\' : '/')) + endif if empty execute 'e' s:escape(item) let empty = 0 @@ -252,7 +256,6 @@ function! s:common_sink(action, lines) abort endfor catch /^Vim:Interrupt$/ finally - let &autochdir = autochdir silent! autocmd! fzf_swap endtry endfunction |