Matt-A-Bennett / Matt-A-Bennett.github.io

0 stars 0 forks source link

https://matt-a-bennett.github.io/fzf_search_dirs/fzf_search_dirs.html #4

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Configuring FZF to search useful directories beyond the working directory | Matthew Bennett

I earned my PhD in cognitive neuroscience at the University of Glasgow and I currently work as a postdoc at UCLouvain, Belgium. I work with fmri data and neural networks. I mainly use python, matlab and R programming languages. I favour linux machines, and working in the terminal with Vim as my editor of choice.

https://matt-a-bennett.github.io/fzf_search_dirs/fzf_search_dirs.html

timblaktu commented 2 years ago

Hey, nice article, Matt! Instead of faking out a git repository in your home directory, I would recommend using an .ignore or .fdignore file, both of which are supported by fd, And their syntaxes are identical to the .gitignore. I use ag instead of fd, and use its .agignore file for this purpose.

The next thing I'm trying to figure out is how to make the root search directory dynamically selectable, also using fzf, a la how Alt-C works in the shell bindings. I'm imagining it working like this: my fzf vim command normally operates on ~, but if I hit some magic keys, e.g. , it runs fzf again but this time doing a directory search. When a directory is selected, the normal fzf command is run but with 'dir' set to the selected dir.

I think this would be useful, over and above the static dir filtering you describe, to provide immediate dynamic fzfinding. Bc commands can be chained together like this, the interface could even prompt the user for the search depth..

Matt-A-Bennett commented 1 year ago

Hey @timblaktu thanks for the tips regarding the different types of ignore files! I had no idea such a thing existed - it's much cleaner your way (and solves an issue where R refused to create a package in my home directory since it found my .git directory and doesn't like making a 'project in another project'. I'll have to update the post with this better approach!

As for the dynamic fzf functionality you're working on, I have my :Ag command set to:

"Ag: Start ag in the specified directory e.g. :Ag ~/foo 
function! s:ag_in(bang, ...)
    if !isdirectory(a:1)
        throw 'not a valid directory: ' .. a:1
    endif
    " Press `?' to enable preview window.
    call fzf#vim#ag(join(a:000[1:], ' '),
                \ fzf#vim#with_preview({'dir': a:1}, 'right:50%', '?'), a:bang)
endfunction

" Ag call a modified version of Ag where first arg is directory to search
command! -bang -nargs=+ -complete=dir Ag call s:ag_in(<bang>0, <f-args>)

Alas I didn't create this magic myself and don't fully understand how it works - perhaps you can adapt it to your needs.

splazit commented 1 year ago

thanks for the tip, it's very efficient w/ the search.

Matt-A-Bennett commented 1 year ago

Glad it's helpful @splazit!