0

I recently installed fzf CLI fuzzy search utility, and the accompanying fzf.vim file with it. They both work great, and I have been enjoying my experience with them thus far.

However, I'd like to keep the default key bindings of ctrl+j and ctrl+k to move up and down through things like the buffer list when invoking fzf within vim.

Unfortunately I tend to use Neovim / Vim within tmux sessions quite frequently, and I have ctrl+j and ctrl+k to move about the various panes within a tmux window, thus not allowing me to move about the buffers list presented by fzf.

Does Vim / Neovim support a "contextual key binding"? Not sure if that is what it should be called or not", but basically I'd like to have ctrl+j work within fzf when a buffer list "window / modal" is present, and then also work to move about tmux panes when the buffer list presented by fzf is not present.

Basically I'd like to have my cake 🎂 and eat it 🍰 at the same time.

Update

fzf can be brought up within the context of the Vim command mode, I hope that helps clarify things.

Also, forgot to mention I'm using vim-tmux-navigator to seamlessly switch between panes from a Vim session and those of a tmux session.

Below is a picture of what I attempted to describe above using words.

fzf-context-within-vim

cheers 🍻
Chris

2
  • 1
    I may be misunderstanding but this seems like a tmux/fzf interaction, not anything to do with vim. How would tmux know what you mean when you type ctrl+j?
    – Mass
    Mar 20, 2018 at 17:06
  • @Mass see my amendment please.
    – ipatch
    Mar 20, 2018 at 17:19

1 Answer 1

1

I have the following lines in my ~.tmux.conf, and they allow me to continue to use Ctrl-H, Ctrl-J, Ctrl-K, and Ctrl-L for navigation within Vim (between windows and also between CtrlP results), and yet also use them for navigating between tmux panes:

# smart pane switching with awareness of vim splits and of emacs (but not emacs splits)
bind-key -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(vim|emacs)' && tmux send-keys C-h) || tmux select-pane -L"
bind-key -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(vim|emacs)' && tmux send-keys C-j) || tmux select-pane -D"
bind-key -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(vim|emacs)' && tmux send-keys C-k) || tmux select-pane -U"
bind-key -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(vim|emacs)' && tmux send-keys C-l) || tmux select-pane -R"

A quick google suggests that I stole the idea from here, although I bear sole responsibility for the addition of the half-completed support for emacs.

2
  • thanks for sharing, I'll give this a test drive 🚗 here in a sec.
    – ipatch
    Mar 20, 2018 at 17:26
  • worked as described 👍, thanks again for sharing, and sorry you have to use emacs. ¯\_(ツ)_/¯
    – ipatch
    Mar 20, 2018 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.