From e7d60aac9cb7bd3c98d8ffd544f653278313bb56 Mon Sep 17 00:00:00 2001
From: Junegunn Choi <junegunn.c@gmail.com>
Date: Thu, 28 Mar 2019 10:50:38 +0900
Subject: [PATCH] [vim] Do not restore cwd when autochdir is set and buffer
 changed

Close #1539
---
 plugin/fzf.vim | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index e1047d04..8f2bc26a 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -457,7 +457,8 @@ function! s:pushd(dict)
     let cwd = s:fzf_getcwd()
     let w:fzf_pushd = {
     \   'command': haslocaldir() ? 'lcd' : (exists(':tcd') && haslocaldir(-1) ? 'tcd' : 'cd'),
-    \   'origin': cwd
+    \   'origin': cwd,
+    \   'bufname': bufname('')
     \ }
     execute 'lcd' s:escape(a:dict.dir)
     let cwd = s:fzf_getcwd()
@@ -493,7 +494,7 @@ function! s:dopopd()
   " matches 'dir' entry. However, it is possible that the sink function did
   " change the directory to 'dir'. In that case, the user will have an
   " unexpected result.
-  if s:fzf_getcwd() ==# w:fzf_pushd.dir
+  if s:fzf_getcwd() ==# w:fzf_pushd.dir && (!&autochdir || w:fzf_pushd.bufname ==# bufname(''))
     execute w:fzf_pushd.command s:escape(w:fzf_pushd.origin)
   endif
   unlet w:fzf_pushd
-- 
GitLab