Skip to content

Instantly share code, notes, and snippets.

@chess-seventh
Created April 13, 2022 08:06
Show Gist options
  • Save chess-seventh/10c305ccb53b01200523548f8f98051c to your computer and use it in GitHub Desktop.
Save chess-seventh/10c305ccb53b01200523548f8f98051c to your computer and use it in GitHub Desktop.
# fix problem with vim colorscheme in tmux
# http://stackoverflow.com/questions/10158508/lose-vim-colorscheme-in-tmux-mode
# set -g default-terminal "rxvt"
# this fixes the HOME and END key problem
# set -g default-terminal "screen-256color"
# set -g default-terminal "rxvt-unicode-256color"
# set-option -g default-terminal "tmux-256color"
set-option -g default-terminal "xterm-256color"
set-option -g default-terminal "tmux-256color"
# Needs this line also to overrides the default color, so that the neovim color
# themes work correctly
set-option -ga terminal-overrides ",xterm-256color:Tc"
set-option -g default-shell /bin/zsh
set-option -g default-command /bin/zsh
set-option -g status-keys vi
set-window-option -g mode-keys vi
# On utf8. Update 2016-09-30: no longer necessary
# set -g utf8 on
# set-option -g status-utf8 on
# set-window-option -g utf8 on
# Change prefix to Ctrl+a
set -g prefix C-a
bind C-a send-prefix
unbind C-b
# address vim mode switching delay (http://superuser.com/a/252717/65504)
# https://github.com/tmux-plugins/tmux-sensible
set -s escape-time 0
# increase scrollback buffer size
set -g history-limit 500000
# tmux messages are displayed for 2 seconds
set -g display-time 2000
# refresh 'status-left' and 'status-right' more often
set -g status-interval 5
# focus events enabled for terminals that support them
set -g focus-events on
# super useful when using "grouped sessions" and multi-monitor setup
setw -g aggressive-resize on
# y and p as in vim
bind Escape copy-mode
unbind p
bind p paste-buffer
# bind -t vi-copy 'v' begin-selection
# bind -t vi-copy 'y' copy-selection -x
# Copy selection to system clipboard (make sure xclip is installed)
# It seems xclip does not close STDOUT after it has read from tmux's buffer. As
# such, tmux doesn't know that the copy task has completed, and continues to
# /await xclip's termination, thereby rendering the window manager unresponsive.
# So we redirect STDOUT of xclip to /dev/null, or you can use an
# alternative command like xsel (https://wiki.archlinux.org/index.php/Tmux)
# bind-key -t vi-copy y copy-pipe 'xclip -in -selection clipboard >/dev/null'
# bind -t vi-copy 'Space' halfpage-down
# bind -t vi-copy 'Bspace' halfpage-up
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'V' send -X select-line
bind-key -T copy-mode-vi 'r' send -X rectangle-toggle
bind-key -T copy-mode-vi 'y' send -X copy-pipe-and-cancel "xclip -in -selection clipboard"
bind-key C run-shell "TMUX= tmux new-session -d -s $($PWD | awk 'F' '/' ' {print $NF}' \; ) \;"
# ==============================================================================
#---begin Window and Pane shortcut keys
# easy-to-remember split pane commands
# Start windows and panes at 1, not 0, to match with vim and bspwm
set -g base-index 1
set -g pane-base-index 1
# Split/create new pane with current directory
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
unbind '"'
unbind %
# moving between panes with vim movement keys
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# move the current pane TO become a new window
bind T break-pane
# move the current window BACK to a window to join as a pane
# -h : split vertical?
bind B command-prompt -p "Send pane BACK to: " "join-pane -h -t '%%'"
## swapping:
bind-key J swap-pane -D
bind-key K swap-pane -U
bind-key H swap-pane -U
bind-key L swap-pane -D
# rotate layout with `C-r`
bind -r C-r next-layout
# Use F10 to toggle zoom the current pane
bind-key -n F10 resize-pane -Z
# moving between windows with vim movement keys
# Press the prefix (Ctrl+a) then hold Ctrl key and press h or l to cycle through
bind -r C-h select-window -t :-
bind -r C-l select-window -t :+
# Use Ctrl+[0..9] to select window in tmux
bind -n C-0 select-window -t :10
bind -n C-1 select-window -t :1
bind -n C-2 select-window -t :2
bind -n C-3 select-window -t :3
bind -n C-4 select-window -t :4
bind -n C-5 select-window -t :5
bind -n C-6 select-window -t :6
bind -n C-7 select-window -t :7
bind -n C-8 select-window -t :8
bind -n C-9 select-window -t :9
bind -n C-Tab last-window
# resize panes with similar key binding with my vim settings
bind -r M-h resize-pane -L 5
bind -r M-j resize-pane -D 5
bind -r M-k resize-pane -U 5
bind -r M-l resize-pane -R 5
#---end Window and Pane shortcut keys
# ==============================================================================
##+ window title:
set-option -g set-titles on
set-option -g set-titles-string '[#S:#I] #W'
set-window-option -g automatic-rename on
# Set window notifications
setw -g monitor-activity off
set -g visual-activity off
# split pane border style
# set -g pane-border-style fg=#88C0D0
# set -g pane-active-border-style fg=#D08770
# set -g pane-border-style bg=#88C0D0
# set -g pane-active-border-style bg=#BF616A
# set -g pane-border-fg yellow
# set -g pane-active-border-fg yellow
# set -g pane-active-border-bg yellow
set -g status-left-length 170
set -g status-justify 'centre'
set-option -g status-style bg=colour235
set -g status-left '#[fg=#e5e5e5,bg=colour238] #S #[fg=colour238,bg=black]'
set -g status-right '#[fg=colour235,bg=black,nobold,nounderscore,noitalics]#[fg=#ffffff,bg=colour235]#[fg=#00bfff,bg=colour235] #(uptime -p) #[fg=#ffffff,bg=colour235]#[fg=#00b71b,bg=colour235] @#H #[fg=colour235,bg=black,nobold,nounderscore,noitalics]'
#set -g status-left '#[fg=colour238,bg=colour235,nobold,nounderscore,noitalics]#[fg=#00bfff,bg=colour235] #(uptime -p) #[fg=#ffffff,bg=colour235]#[fg=#00b71b,bg=colour235] @#H #[fg=colour235,bg=default,nobold,nounderscore,noitalics]'
#set -g status-right '#[fg=colour238,bg=default]#[fg=#e5e5e5,bg=colour238] #S '
set -g status-right-length 100
set -g status-bg default
# #P: the pane number
setw -g window-status-format '#[fg=#2E3440,bg=black]#[fg=#aaaaaa,bg=#2E3440] #I #[fg=#aaaaaa,bg=#2E3440] #W  #P #[fg=#2E3440,bg=black]'
setw -g window-status-current-format '#[fg=#5E81AC,bg=black]#[fg=#2E3440,bg=#5E81AC] #I #[fg=#5E81AC,bg=#616E88]#[fg=#2E3440,bg=#616E88] #W  #P #[fg=#616E88,bg=black]'
# Faster Command Sequences, fix neovim switching to command mode problem?
# set -s escape-time 0
set -g escape-time 10
# allow Neovim in tmux to change cursor shape to vertical bar in insert mode
# previously it worked fine, but after neovim commit 0e546d8 we need the below
# See `man nvim`
set -ga terminal-overrides ',*:Ss=\E[%p1%d q:Se=\E[2 q'
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-sidebar'
set -g @plugin 'tmux-plugins/tmux-sessionist'
# set -g @plugin 'jbnicolai/tmux-fpp'
set -g @plugin 'wfxr/tmux-fzf-url'
set -g @plugin './.tmux/plugins/tmux-fzf-url-fire'
set -g @plugin './.tmux/plugins/tmux-fzf-url-qute'
set -g @resurrect-strategy-vim 'session'
set -g @resurrect-capture-pane-contents 'on'
run -b '~/.tmux/plugins/tpm/tpm'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment