17

I recently found this command line tool called fzf. I installed it according to the instructions and it does work, except for the CTRL-T key binding. Even though, I installed the special stuff with the key bindings as per their instructions, and I also tried installing fzf downloaded from the git repo as opposed to via homebrew, all the CTRL-T key binding does, still, is swap the last two characters.

I found this discussion about this, but none of the answers offered worked for me.

edit: you can see it in the first video here what I want to achieve. edit 2: I'm using the Terminal of MacOs.

L Y E S - C H I O U K H
  • 4,765
  • 8
  • 40
  • 57
samuset
  • 275
  • 1
  • 2
  • 13
  • In my case, `ctrl+t` split current window and `fzf` runs in a `tmux` pannel, is this what you want? – nbari Mar 10 '18 at 09:29
  • @nbari what I want to achieve is what is shown in the first embedded video here: http://brendandawes.com/blog/fzf – samuset Mar 10 '18 at 11:43
  • I guess something overwrote your ctrl-t mapping. type `:call fzf#vim#maps('n')` and search for `'`. what do you see? – sudavid4 Mar 11 '18 at 18:23
  • @sudavid4 doesn't work, that line entered into the mac terminal gives me this error: -bash: syntax error near unexpected token `(' – samuset Mar 11 '18 at 22:15
  • not in the terminal in vim! – sudavid4 Mar 12 '18 at 08:24
  • @sudavid4 ok, right, sorry. typed it into vim, got this `E117: Unknown function: fzf#vim#maps` – samuset Mar 12 '18 at 12:08
  • that's odd... what about `:FZF` is this defined? do you have [fzf-vim](https://github.com/junegunn/fzf.vim) installed?(if you run `:scriptnames` do you have some `fzf.vim` entry? – sudavid4 Mar 13 '18 at 10:55
  • @sudavid4 no, I dont' have fzf-vim installed, I am simply trying to use fzf to find and open files quickly from the command line, as in typing `open ` then pressing CTRL-t and, when, ideally, fzf appears, I press Enter on the file I need, which then opens. – samuset Mar 13 '18 at 11:22
  • I suggest you install fzf.vim, it'll solve your issue. If you'd rather "do it yourself" then I wish you good luck. – sudavid4 Mar 13 '18 at 13:08

6 Answers6

10

I use zsh with Oh My Zsh on Mac.

If I put fzf before vi-mode in the plugin setting in .zshrc like

plugins=(... fzf ... vi-mode ...) 

Ctrl-t does not work showing ^T. Ctrl-r does not work, either.

But, if fzf comes AFTER vi-mode like

plugins=(... vi-mode ... fzf ...) 

no problem arises.

T_T
  • 1,202
  • 16
  • 22
6

If you clone fzf from the repository it contains a file called fzf/shell/key-bindings.zsh which refers to

fzf-file-widget() {
  LBUFFER="${LBUFFER}${__fsel}"
  local ret=$?
  zle redisplay
  typeset -f zle-line-init >/dev/null && zle-line-init
  return $ret
}
zle -N fzf-file-widget
bindkey "^T" fzf-file-widget

the Control-T keybinding. This is normally sourced by your .zshrc

[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh

which should contain its reference in .fzf.zsh:

source "$HOME/.fzf/shell/key-bindings.zsh"

If your keybinding does not work then your keybinding may be overwritten by your zshrc or may not be invoked by your zshrc.

What
  • 304
  • 1
  • 12
  • hi, I did pretty much what you outlined here, but still failed to get the key-bindings to work. i am using zsh; installed using homebrew and ran that `/usr/local/opt/fzf/install` which prompted me to install key-bindings and added those lines to my .zshrc. the **TAB works however. can you please provide some troubleshooting assistance? – Spencer Trinh Jan 15 '20 at 04:48
3

If you are using zsh-vi-mode, then replace this line

[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh

with this

zvm_after_init_commands+=('[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh')

From zsh-vi-mode GitHub page


Psst! if you use fzf-tab, you might want to enable that also

zvm_after_init_commands+=('[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh && enable-fzf-tab')
neovr
  • 147
  • 1
  • 2
  • 10
2

I put the below script in my .zshrc and sourced it using source ~/.zshrc

if [ -x "$(command -v fzf)"  ]
then
    source /usr/share/fzf/key-bindings.zsh
fi

and now key bindings (CTRL-T, CTRL-R, and ALT-C) work for me.

got the above script from how to enable hotkeys for fzf

explanation

you have key-bindings.zsh inside /usr/share/fzf or a few directories deeper. Above script only sources key-bindings.zsh if fzf is installed.

rest of the working is part of the key-bindings.zsh, which frankly I did not bother to understand.

OS: Manjaro GNU-Linux

1

I have noticed CTRL-T does not work (in bash) when I have the "vi mode" enabled by set -o vi.

SHR
  • 7,940
  • 9
  • 38
  • 57
Michele
  • 53
  • 5
0

I managed to make the CTRL-t key combo work as desired. There was one step I had missed.

After installing useful keybindings and fuzzy completion with /usr/local/opt/fzf/install, I updated fzf.bash manually with [ -f ~/.fzf.bash ] && source ~/.fzf.bash. After restarting the Terminal, it now works.

Edit: Also, this line needs to be added to your .bash_profile or .bashrc: source ~/.fzf.bash.

samuset
  • 275
  • 1
  • 2
  • 13