Live data from Hacker News

Fzf – a command-line fuzzy finder

github.com

61–70 of 93 posts

Re: Fzf – a command-line fuzzy finder

#63
post #58

It has replaced vim’s “open file” and “switch to buffer” for me. I occasionally use it in the command line, by expanding *. Not that often as in Vim, but very useful. I still need to find a satisfactory way to do “find in files” with vim. I use a custom script to call ag and it’s enough, but a bit clunky at times.

If you're using fzf.vim ( https://github.com/junegunn/fzf.vim ) then you can use :Rg or :Ag. This will run ripgrep or silver-searcher and present the results in a fuzzy finder window.

This is great when you want to jump to a specific place.

I also use vim-grepper (mapped to leader-g) for finding in files and populating the quickfix list.

https://github.com/mhinz/vim-grepper

Re: Fzf – a command-line fuzzy finder

#64

If you still don't know how useful fzf is, you should start with integrating fzf and ctrl+r (reverse search).

I tried it, and removed the next day. In my experience it's too fuzzy, and makes it impossible to find anything.

Try using it with the -e flag, it gives exact matches for each space-separated word you type, ignoring order and case. This is usually the most useful way to search in my experience. For example, if I'm searching through my filesystem I can give it "pdf pascal", it will give me all the Pascal-related PDF files. But it won't match paths like this just because the letters appear throughout the string:

  ~/books_and_papers/causal_inference.pdf
              ^^   ^ ^^   ^           ^^^

Re: Fzf – a command-line fuzzy finder

#65
post #58

It has replaced vim’s “open file” and “switch to buffer” for me. I occasionally use it in the command line, by expanding *. Not that often as in Vim, but very useful. I still need to find a satisfactory way to do “find in files” with vim. I use a custom script to call ag and it’s enough, but a bit clunky at times.

If you're using neovim I suggest checking out telescope.nvim. In addition to searching for files, it comes with a Live Grep mode for searching the current buffer (or all files in a given directory).

For find and replace, I use spectre.

Re: Fzf – a command-line fuzzy finder

#66
post #58

It has replaced vim’s “open file” and “switch to buffer” for me. I occasionally use it in the command line, by expanding *. Not that often as in Vim, but very useful. I still need to find a satisfactory way to do “find in files” with vim. I use a custom script to call ag and it’s enough, but a bit clunky at times.

>I occasionally use it in the command line, by expanding *.

You can use zsh's fzf-tab as a supercharged tab-completion. e.g. you can just do

  some-command 
and it will put a fzf interface where the tab-completions would usually be, and you can pick whatever files you want. And if you instead do

  some-command -
it will instead show you all the possible flags and their descriptions, which you can also pick from.

I use this all the time on the terminal now. It cuts out so much pointless flow-breaking invocations of ls and man and --help.

Re: Fzf – a command-line fuzzy finder

#67

Another wonderful tool is "entr". It just runs a program when files change. It's incredible. I use it 20-40 times an hour to do very fast Dev/DevOps development: - "run Pytest when Python files change" - "I forgot how to use ps, run my-ps.sh when it changes and show me the output" - "rebuild all these Kubernetes resources when I edit the YAML files" - "run fast lint, then unit test Python files, then invoke one and s…

I use https://watchexec.github.io/ for this, which looks similar. Anyone who tried both and knows which one is better?

I love watchexec! Really fast when doing TDD

Re: Fzf – a command-line fuzzy finder

#68
post #58

It has replaced vim’s “open file” and “switch to buffer” for me. I occasionally use it in the command line, by expanding *. Not that often as in Vim, but very useful. I still need to find a satisfactory way to do “find in files” with vim. I use a custom script to call ag and it’s enough, but a bit clunky at times.

I bind Ctrl-J to ":Ag " so I'll simply have to type in roughly what I'm searching for and then get the pop-up to refine the search and do selections. I imagine you have a similar approach, what's clunky about it for you?

Lack of auto completion on filenames/dirs. Not seeing results while I type, like with fzf

Re: Fzf – a command-line fuzzy finder

#69
post #55

Another wonderful tool is "entr". It just runs a program when files change. It's incredible. I use it 20-40 times an hour to do very fast Dev/DevOps development: - "run Pytest when Python files change" - "I forgot how to use ps, run my-ps.sh when it changes and show me the output" - "rebuild all these Kubernetes resources when I edit the YAML files" - "run fast lint, then unit test Python files, then invoke one and s…

I just use inotifywait for that. What does entr do differently? This will run a binary when any file on the directory tree changes: #!/usr/bin/env sh set -e while true; do inotifywait -e modify,create,delete,move -r $1 $2 done and then just call it: run_on_modify path/to/dir path/to/bin If someone thinks this is magic or wizardy, instead of teaching them that fire exists (entr), teach them how to make fire first (ino…

inotifywait does a decent job of exposing the inotify primitive from the Linux kernel to userspace, but it's, well, primitive. Using that loop, if you change a file twice in quick succession, what happens? It'll trigger off the first change, but potentially ignore the second change if $2 takes longer to run than you can edit a file.

You can improve the basic loop somewhat, but a more thoroughly written program (whatever the language) rather than a 3 LOC loop is going to have more features and be more ergonomic. In particular, to truly be useful, it should be able to kill the command and restart it every time the file is saved.

Re: Fzf – a command-line fuzzy finder

#70
Fzf is brilliant. Recently I found fzrepl (https://github.com/danielfgray/fzf-scripts/blob/master/fzrep...), which blew my mind. It uses fzf and its preview window to create a repl for other programs, such as jq. That's great for figuring out a query for jq since I use it so rarely.
Post reply on HN