2

I set the following on my ~/.vimrc which sets the current directory to the location of the file on the buffer.

au BufEnter * silent! :lcd%:p:h

However, when I run the fzf command to search for a file, then the search starts on the current directory, althogh the file I like to get is often in other directories. So I want to set it to ~/ whenever I run fzf.

But I'm not sure if it is possible. Is it possible to set it in fzf?

Blaszard
  • 545
  • 1
  • 9
  • 27

2 Answers2

2

The following info can be found in the official docs of fzf:

You can execute :FZF with an argument for the starting dir. So you can just run :FZF ~ instead of :FZF. If you open the fzf buffer from a mapping just change that mapping:

map <c-space> :FZF ~<cr>

(Unrelated to the question but related to the autocomand you mentioned: 'autochdir')

Lucas
  • 1,629
  • 10
  • 21
1

You can provide a default path to fzf if you configure it to use fd (or rigrep or ag) in your .bashrc.

Then calling fzf from vim will also use this path as a starting point.

My .bashrc has the following line so all searches being from my home directory:

export FZF_DEFAULT_COMMAND="fd . $HOME"

(note that on Debian Buster, the command would be "fdfind . $HOME)

I found that this produced too many results, so I implemented a solution to have a subset of the directories in $HOME searched (see a blog post about it here)

mattb
  • 1,111
  • 4
  • 15