Skip to content

Instantly share code, notes, and snippets.

@AlanJui
Last active December 8, 2019 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlanJui/6703bb2610d63dc3c47f34bd0a27e3d5 to your computer and use it in GitHub Desktop.
Save AlanJui/6703bb2610d63dc3c47f34bd0a27e3d5 to your computer and use it in GitHub Desktop.
適用於 Ubuntu 18.04 的 Tmux 環境設定
# https://tmuxguide.readthedocs.io/en/latest/tmux/tmux.html#tmux-conf
#========================================================
# Tmux Plugins
#========================================================
# Tmux Plugin Manager
if "test ! -d ~/.tmux/plugins/tpm" \
"run 'git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm && ~/.tmux/plugins/tpm/bin/install_plugins'"
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
# Session save and restore
# - continuous saving of tmux environment
# - automatic tmux start when computer/server is turned on
# - automatic restore when tmux is started
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
# Copy to the system clipboard in tmux
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @resurrect-strategy-vim 'session'
# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'git@github.com/user/plugin'
# set -g @plugin 'git@bitbucket.com/user/plugin'
# Tmux Powerline theme
set -g @plugin 'jooize/tmux-powerline-theme'
#========================================================
# Tmux Configuration
#========================================================
# unbind default prefix and set it to ctrl-a
set -g prefix C-t
unbind C-b
bind C-t send-prefix
# make delay shorter
set -sg escape-time 0
# Automatic restore session
set -g @continuum-restore 'on'
# history size
set -g history-limit 10000
# enable mouse support for switching panes/windows
set -g mouse on
### other optimization
# display things in 256 colors
# set -g default-terminal "xterm-256color"
# set -ga terminal-overrides ",xterm-256color:Tc"
# tell Tmux that outside terminal supports true color
set -g default-terminal "screen-256color"
set -ga terminal-overrides ",xterm-256color:Tc"
# stop auto renaming
setw -g automatic-rename off
set-option -g allow-rename off
# renumber windows sequentially after closing
set -g renumber-windows on
# window notifications; display activity on other window
setw -g monitor-activity on
set -g visual-activity on
#
# Status Line
#
# Status Line Format
set-window-option -g status-left ""
set-window-option -g status-right "#[fg=white,bg=colour88] #S #[fg=colour231,bg=colour240] #H #[fg=black,bg=colour252,nobold] %b %d %a #[bold]%H:%M"
# default status bar colors
set -g status-fg colour240
set -g status-bg colour233
# default window title colors
set-window-option -g window-status-style fg=colour220
set-window-option -g window-status-style bg=default
#
# Status bar window in background (not active)
#
# set-window-option -g window-status-format "#I #W "
set-window-option -g window-status-style dim
set-window-option -g window-status-style bg=colour240
set-window-option -g window-status-style fg=colour231
#
# Status bar window currently active
#
# set-window-option -g window-status-current-format "#I #W "
# active window title colors
set-window-option -g window-status-current-style bright
set-window-option -g window-status-current-style bg=colour68
set-window-option -g window-status-current-style fg=colour220
#========================================================
# Key bindings
#========================================================
# reload config file
bind r source-file ~/.tmux.conf \; display-message "Config reloaded..."
# quickly open a new window
bind N new-window
# synchronize all panes in a window
bind y setw synchronize-panes
# "|" splits the current window vertically, and "-" splits it horizontally
unbind %
bind | split-window -h
bind - split-window -v
# Pane navigation (vim-like)
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Pane resizing
bind -r Left resize-pane -L 4
bind -r Down resize-pane -D 4
bind -r Up resize-pane -U 4
bind -r Right resize-pane -R 4
# Move window
bind-key S-Left swap-window -t -1
bind-key S-Right swap-window -t +1
# Cycle prev/next pane
# bind -n S-Left select-pane -t :.-
# bind -n S-Right select-pane -t :.+
# bind -n C-n select-pane -t :.+
# Open current directory
bind f run-shell "open #{pane_current_path}"
# #### copy mode : vim ####
set -g @yank_selection 'primary' # or 'secondary' or 'clipboard'
bind P paste-buffer
# set vi mode for copy mode
setw -g mode-keys vi
# Setup 'v' to begin selection as in Vim
bind -T copy-mode-vi 'v' send-keys -X begin-selection
# Copy to tmux buffer
# For binding 'y' to copy and exiting selection mode
bind -T copy-mode-vi 'y' send-keys -X copy-pipe-and-cancel "xclip -i -f -selection primary | xclip -i -selection clipboard"
bind -T copy-mode-vi 'r' send-keys -X rectangle-toggle
bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -i -f -selection primary | xclip -i -selection clipboard"
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run -b '~/.tmux/plugins/tpm/tpm'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment