Skip to content

Instantly share code, notes, and snippets.

@tsl0922
Last active November 18, 2024 10:31
Show Gist options
  • Save tsl0922/d79fc1f8097dde660b34 to your computer and use it in GitHub Desktop.
Save tsl0922/d79fc1f8097dde660b34 to your computer and use it in GitHub Desktop.
vim style tmux config
# vim style tmux config
# use C-a, since it's on the home row and easier to hit than C-b
set-option -g prefix C-a
unbind-key C-a
bind-key C-a send-prefix
set -g base-index 1
# Easy config reload
bind-key R source-file ~/.tmux.conf \; display-message "tmux.conf reloaded."
# vi is good
setw -g mode-keys vi
# mouse behavior
setw -g mouse on
set-option -g default-terminal screen-256color
bind-key : command-prompt
bind-key r refresh-client
bind-key L clear-history
bind-key space next-window
bind-key bspace previous-window
bind-key enter next-layout
# use vim-like keys for splits and windows
bind-key v split-window -h
bind-key s split-window -v
bind-key h select-pane -L
bind-key j select-pane -D
bind-key k select-pane -U
bind-key l select-pane -R
# smart pane switching with awareness of vim splits
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)vim$' && tmux send-keys C-h) || tmux select-pane -L"
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)vim$' && tmux send-keys C-j) || tmux select-pane -D"
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)vim$' && tmux send-keys C-k) || tmux select-pane -U"
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)vim$' && tmux send-keys C-l) || tmux select-pane -R"
bind -n 'C-\' run "(tmux display-message -p '#{pane_current_command}' | grep -iqE '(^|\/)vim$' && tmux send-keys 'C-\\') || tmux select-pane -l"
bind C-l send-keys 'C-l'
bind-key C-o rotate-window
bind-key + select-layout main-horizontal
bind-key = select-layout main-vertical
set-window-option -g other-pane-height 25
set-window-option -g other-pane-width 80
set-window-option -g display-panes-time 1500
set-window-option -g window-status-current-style fg=magenta
bind-key a last-pane
bind-key q display-panes
bind-key c new-window
bind-key t next-window
bind-key T previous-window
bind-key [ copy-mode
bind-key ] paste-buffer
# Setup 'v' to begin selection as in Vim
bind-key -T copy-mode-vi v send -X begin-selection
bind-key -T copy-mode-vi y send -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
# Update default binding of `Enter` to also use copy-pipe
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
# Status Bar
set-option -g status-interval 1
set-option -g status-style bg=black
set-option -g status-style fg=white
set -g status-left '#[fg=green]#H #[default]'
set -g status-right '%a%l:%M:%S %p#[default] #[fg=blue]%Y-%m-%d'
set-option -g pane-active-border-style fg=yellow
set-option -g pane-border-style fg=cyan
# Set window notifications
setw -g monitor-activity on
set -g visual-activity on
# Enable native Mac OS X copy/paste
set-option -g default-command "/bin/bash -c 'which reattach-to-user-namespace >/dev/null && exec reattach-to-user-namespace $SHELL -l || exec $SHELL -l'"
# Allow the arrow key to be used immediately after changing windows
set-option -g repeat-time 0
@tsl0922
Copy link
Author

tsl0922 commented Dec 23, 2019

Thanks @marshal-81, I've updated it for the latest tmux with your changes.

@tsl0922
Copy link
Author

tsl0922 commented Dec 23, 2019

how to change spc key(default select hightlight) to v.
thank you

Usage

  • copy:
    • C a [
    • h j k l
    • v
    • h j k l
    • y or Enter
  • paste:
    • C a ]

@lnguyen639
Copy link

Cool, many thanks!

@wuzyzy
Copy link

wuzyzy commented Apr 14, 2020

Great! Thanks a lot!

Copy link

ghost commented May 17, 2020

Thank you so much.

@cjander18
Copy link

Thank you!!

@forghani77
Copy link

Perfect !

@byteab
Copy link

byteab commented Oct 19, 2020

<c-a> in vim increase a number
e.g => 10<c-a> will change 11 to 21

so it's a conflict

@ThSGM
Copy link

ThSGM commented Dec 28, 2020

This configuration is great! Thanks.

@zstreeter
Copy link

I like to show all tmux sessions with <c-a> + s and you have that remapped to the vi horizontal split. What is the command with this config to show all sessions? Thanks for sharing!!!

@janncm
Copy link

janncm commented Mar 6, 2021

I like to show all tmux sessions with <c-a> + s and you have that remapped to the vi horizontal split. What is the command with this config to show all sessions? Thanks for sharing!!!

Same doubt here. Just couldn't find the unbind or a new bind.

@LuighiV
Copy link

LuighiV commented Jul 9, 2021

Thank you!

@andradefil
Copy link

Nice I added more one keybind to be perfect to me

# Kill pane with no confirm
bind-key x kill-pane

@LasseWolter
Copy link

Great config. Thanks! 🙌
If you want the new splits to open the same directory path use

bind-key v split-window -h -c '#{pane_current_path}'
bind-key s split-window -v -c '#{pane_current_path}'

@minhanghuang
Copy link

Thank you!!😋

@H4ppy-04
Copy link

bind-key v split-window -h -c '#{pane_current_path}'
bind-key s split-window -v -c '#{pane_current_path}'

Great input. Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment