Reputation: 3974
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
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
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