Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
utterances-bot opened this issue Jun 24, 2022 · 4 comments

Comments

@utterances-bot
Copy link

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

Copy link

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..

Copy link
Owner

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.

Copy link

splazit commented Jan 25, 2023

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

Copy link
Owner

Glad it's helpful @splazit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants