tmux vim select pane

January 4, 2022 - Reading time: 2 minutes

This is a tweak of https://github.com/mislav/dotfiles/blob/master/bin/tmux-vim-select-pane which is linked from https://github.com/christoomey/vim-tmux-navigator as a possible fix for the vim integration.

I couldn't get the original one to work right on tmux 1.8 so I fixed it up.

These go into tmux config file:

bind-key -n C-h run-shell "~/tmux-vim-select-pane -L"
bind-key -n C-j run-shell "~/tmux-vim-select-pane -D"
bind-key -n C-k run-shell "~/tmux-vim-select-pane -U"
bind-key -n C-l run-shell "~/tmux-vim-select-pane -R"
bind-key -n C-\ run-shell "~/tmux-vim-select-pane -l"
bind C-l send-keys 'C-l'

The new script is:

#!/bin/bash
# Like `tmux select-pane`, but sends a `<c-h j="" k="" l="">` keystroke if Vim is
# running in the current pane, or only one pane exists.
#set -e
cmd="$(tmux list-panes -F '#{pane_active} #{pane_tty}' | grep '^1')"
X=$(ps -o comm= -t $(echo $cmd | cut -f2 -d' ') | grep vim)
isvim=$?
pane_count="$(printf %d $(tmux list-panes | wc -l))"
if [[ ($isvim = 0) || ($pane_count = 1) ]]; then
#if [ $isvim -eq 0 ]; then
  direction="$(echo "${1#-}" | tr 'lLDUR' '\\hjkl')"
  # forward the keystroke to Vim
  tmux send-keys "C-$direction"
else
  tmux select-pane "$@"
fi


Useful Vim Settings Without Plugins

April 5, 2021 - Reading time: ~1 minute

Here are some settings that I use in Vim to make it useful without having to install a ton of plugins.

File Search

" Vim File Search Settings
set path+=** set wildmenu

Setting the path variable will allow Vim to search subdirectories and turn on tab completion.

Setting the wildmenu will show a list of matching files in a popup line when tab completion is used.

Once these two are set, you can use :find with tab and * to autocomplete and wildcard-match files.

Tag Jumping

" Vim Tag Jumping
command! MakeTags !ctags -R .

To use this, ctags must be installed. When this command is issued, a tags file is created. Then, you can use ^] to jump to a tag that's under the cursor. Use g^] for an ambiguous tag search. Use ^t to jump back to where you were. Issue the command as needed to update the tags file. (^ means the control key.)

Autocomplete

To autocomplete words while typing, use control x to start the autocomplete.

Then use control n for local completes (from within the file), control f for file name completes, and control ] for tag completes.


Categories