getcwd() is not correct after using :FZF
- Dominant language
- Go
- Stars
- 83k
- Forks
- 2.9k
- Avg merge
- 17h 8m
- Merged PRs (30d)
- 10
Description
- [x] I have read through the manual page (`man fzf`)
- [x] I have the latest version of fzf
- [x] I have searched through the existing issues
## Info
- OS
- [x] Linux
- [ ] Mac OS X
- [ ] Windows
- [ ] Etc.
- Shell
- [x] bash
- [ ] zsh
- [ ] fish
## Problem / Steps to reproduce
In vim, after calling `:FZF` with `autochdir` set, `echo getcwd()` gives the original directory (or root directory of a git repo if called inside of a git repo) instead of the one containing the selected file. `:pwd` does update to the new directory.
1. Open vim
2. Run `:set autochdir`
3. Run `:FZF` and select a file in a different directory
4. `:echo getcwd()` shows the original directory
5. `:pwd` correctly shows the parent of the selected file
I made the following change in plugin/fzf.vim which is working for me so far but is probably an ugly hack:
```
@@ -254,6 +254,13 @@ function! s:common_sink(action, lines) abort
finally
let &autochdir = autochdir
silent! autocmd! fzf_swap
+ if autochdir
+ let new_path = getcwd() . "/" . item
+ if !isdirectory(new_path)
+ let new_path = fnamemodify(new_path, ":h:p")
+ endif
+ exe "lcd " . new_path
+ endif
endtry
```
This problem leads to issues with other plugins like the one mentioned in https://github.com/junegunn/fzf.vim/issues/993
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.