Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fzf.vim changing working directory on the fly

When I use :Files in fzf.vim, it searches for the files in the current directory and the subdirectories. The current working directory is fixed. In the screenshot below, it is in light blue. Is there a way to dynamically change the working directory on which FZF is run? For example, if I just delete "Documents" path, then FZF starts on ~ instead of ~/Documents.

Such functionality is possible in Emacs helm package, which allows this through helm-execute-persistent-action.

enter image description here

like image 661
zcadqe Avatar asked Nov 29 '19 22:11

zcadqe


1 Answers

You could change the current working directory vim is currently using the :chdir or the familiar :cd command. See :h cd for more info.

And if you don't want to change the working directory of vim and just want fzf to use a different directory, you could run fzf (:h fzf#run) with a custom dir option.

This is an example mapping I have in my ~/.vimrc to open a file within my /.vim directory:

nnoremap <leader>fv :call fzf#run({'options': '--reverse --prompt "VimFiles"', 'down': 20, 'dir': '~/.vim/', 'sink': 'e' })<CR>

For dynamic path you add a command that takes the path as an argument, make sure to use the completion as file for tab completing the path. see this answer for more info on file completion.

The sink option tells what to do/perform when a match is found. and e is for editing the main window.

like image 154
Harish Avatar answered Nov 19 '22 18:11

Harish