3

Often I am in some 'general' directory when I open files, such as ~ or Desktop. FZF by default opens the user's pwd, for example, if I have:

Desktop $ vim ~/.vim/vimrc

And I do:

:FZF

It will search in Desktop by default. How can I pass a parameter equivalent to:

:FZF dir(current_file)

Or:

:FZF expand('%:p:h')

2 Answers 2

6

You can use :Files [PATH] for this. See the command reference.

To pass in the directory: :Files %:p:h

Alternatively, you can also use lcd to change the directory for the current window, then use FZF as normal.

2
  • 2
    Welcome Michael!
    – D. Ben Knoble
    Commented Apr 28, 2020 at 12:07
  • Thanks @D.BenKnoble :-) Commented Apr 29, 2020 at 13:04
1

As mentioned in accepted reply, to expand the solution I add

nnoremap <Leader>pf :Files %:p:h<CR>

to ~/.vimrc

2
  • 2
    Welcome to Vi and Vim!
    – D. Ben Knoble
    Commented Nov 24, 2020 at 15:00
  • 1
    Welcome! You might want to add <silent> to your normal mode mappings that call Ex commands, such as this one. So that they don't print (or quickly flash) the command being executed. See :help :map-silent for details.
    – filbranden
    Commented Nov 24, 2020 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.