0

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

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
    Apr 28 '20 at 12:07
  • Thanks @D.BenKnoble :-) Apr 29 '20 at 13:04
0

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
    Nov 24 '20 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
    Nov 24 '20 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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