Fzf: Open Vim with Ctrl+T

Created on 11 Nov 2017  路  2Comments  路  Source: junegunn/fzf

  • Category

    • [x] fzf binary

    • [ ] fzf-tmux script

    • [x] Key bindings

    • [ ] Completion

    • [x] Vim

    • [ ] Neovim

    • [ ] Etc.

  • OS

    • [x] Linux

    • [ ] Mac OS X

    • [ ] Windows

    • [ ] Windows Subsystem for Linux

    • [ ] Etc.

  • Shell

    • [x] bash

    • [ ] zsh

    • [ ] fish

Hi and thanks a lot for your software!

I would like to modify the behavior of fzf's Ctrl + t:
Instead of writing the file the user chose to stdout, Vim should open the file.

As suggested here I've tried to add a key binding:

export FZF_CTRL_T_OPTS="--bind 'enter:execute(vim {1} < /dev/tty);"

But this didn't work, Vim doesn't open the file.

Is there a way to configure what happens after the user has chosen a file using Ctrl + t?

Thanks!

question

Most helpful comment

Thanks @xalexalex!

Based on your answer, I came up with this function that takes care of the case when the user hasn't selected a file:

# Search a file with fzf inside a Tmux pane and then open it in an editor
fzf_then_open_in_editor() {
  local file=$(fzf-tmux)
  # Open the file if it exists
  if [ -n "$file" ]; then
    # Use the default editor if it's defined, otherwise Vim
    ${EDITOR:-vim} "$file"
  fi
}
bind -x '"\C-t": fzf_then_open_in_editor'

All 2 comments

The most basic thing you can do is

vim_fzf() {
vim "$(fzf)"
}
bind -x '"\C-t": vim_fzf'

There's more stuff in the wiki (for example the fe() function)

Thanks @xalexalex!

Based on your answer, I came up with this function that takes care of the case when the user hasn't selected a file:

# Search a file with fzf inside a Tmux pane and then open it in an editor
fzf_then_open_in_editor() {
  local file=$(fzf-tmux)
  # Open the file if it exists
  if [ -n "$file" ]; then
    # Use the default editor if it's defined, otherwise Vim
    ${EDITOR:-vim} "$file"
  fi
}
bind -x '"\C-t": fzf_then_open_in_editor'
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ahmedelgabri picture ahmedelgabri  路  3Comments

jberglinds picture jberglinds  路  3Comments

asilvadesigns picture asilvadesigns  路  3Comments

ghost picture ghost  路  3Comments

nordlow picture nordlow  路  3Comments