Skip to content

Instantly share code, notes, and snippets.

@yarko3
Created December 19, 2017 16:43
Show Gist options
  • Select an option

  • Save yarko3/02a27d8ffb76d499a41ba94eb6233d8c to your computer and use it in GitHub Desktop.

Select an option

Save yarko3/02a27d8ffb76d499a41ba94eb6233d8c to your computer and use it in GitHub Desktop.
Tmux Basics (Navigation, Tabs, Splits)

Basics

  • there is the concept of a trigger in tmux; a key combo that allows you to follow up with other keys to do some tmux specific stuff
  • the default trigger is ctrl+b; this is awkward for some people so they use ctrl+a (I do this)
  • hitting ctrl+b followed by : will let you go into a mode similar to the vim command mode (where you can type out some commands)

Working with Tabs

  • open a new tab
    • trigger (ctrl+b) followed by c
    • c stands for create
  • go to next tab
    • trigger (ctrl+b) followed by n (for next)
  • go to previous tab
    • trigger (ctrl+b) followed by p (for previous)

Opening New Splits

  • idk how to do this without my mappings so here are some mappings you can put in your tmux.conf:
# opening new splits
bind-key v split-window -h
bind-key h split-window -v

This means that hitting the trigger (ctrl+b) followed by v will open a vertical split; ditto for h and horizontal split

Navigating Between Splits

  • I use a plugin so that I can hit ctrl+vim direction to jump between vim panes and tmux splits seamlessly (would highly recommend)
  • I assume you use a vim plugin manager like vundle or vim-plug so follow the instructions https://github.com/christoomey/vim-tmux-navigator from the vim side
  • You also need to add this to your tmux.conf or use the TPM plugin (like in the link above)
# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
    bind-key -n C-h if-shell "$is_vim" "send-keys C-h"  "select-pane -L"
    bind-key -n C-j if-shell "$is_vim" "send-keys C-j"  "select-pane -D"
    bind-key -n C-k if-shell "$is_vim" "send-keys C-k"  "select-pane -U"
    bind-key -n C-l if-shell "$is_vim" "send-keys C-l"  "select-pane -R"
    bind-key -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
    bind-key -T copy-mode-vi C-h select-pane -L
    bind-key -T copy-mode-vi C-j select-pane -D
    bind-key -T copy-mode-vi C-k select-pane -U
    bind-key -T copy-mode-vi C-l select-pane -R
    bind-key -T copy-mode-vi C-\ select-pane -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment