h-rai
h-rai

Reputation: 3974

How to bind fzf to zsh key?

I have fzf fuzzyfinder set up on Ubuntu 18.xx

fzf finds the file but it prints on the terminal when I select it.

How can I add a shortcut to zsh for fzf so that the selected file opens in vim instead of outputting the file name on terminal?

Upvotes: 2

Views: 2192

Answers (2)

webdev4422
webdev4422

Reputation: 157

Answered: https://stackoverflow.com/a/69686155/13658418

Add script to ~/.zshrc

fzf-vi-file() {
   file="$( find '/' -type d \( -path '/proc/*' -o -path '/dev/* \) -prune -false -o -type f -iname '*' 2>/dev/ | fzf -1 -0 --no-sort +m)" && (vi "${file}" < /dev/tty) || return 1
   zle accept-line
}
zle -N fzf-vi-file
bindkey '^e' fzf-vi-file

Bind to Ctrl+E = bindkey '^e'

Upvotes: 1

h-rai
h-rai

Reputation: 3974

Below script binds <Ctrl+e> to fzf search so that the selected file gets opened in vim

bindkey -s '^e' 'vim $(fzf)\n'

Add it to your .zshrc so it loads everytime you open zsh.

Upvotes: 3

Related Questions