2

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?

h-rai
  • 3,636
  • 6
  • 52
  • 76

2 Answers2

3

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.

h-rai
  • 3,636
  • 6
  • 52
  • 76
1

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'

webdev4422
  • 113
  • 8
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/30155602) – krmogi Oct 23 '21 at 19:41