Skip to content

Instantly share code, notes, and snippets.

@riskers
Last active February 9, 2022 07:27
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 riskers/4cf70b3de35906d0df7009ecbfeba3a7 to your computer and use it in GitHub Desktop.
Save riskers/4cf70b3de35906d0df7009ecbfeba3a7 to your computer and use it in GitHub Desktop.
tmux 配置、快捷键
# unbind some default keybindings
unbind C-b
# set prefix key to ctrl-q
set -g prefix C-q
# lower command delay
set -sg escape-time 1
# start first window and pane at 1, not zero
set -g base-index 1
set -g pane-base-index 1
# bind r to reloading the config file
bind r source-file ~/.tmux.conf \; display "Reloaded tmux config file."
# pass through a ctrl-a if you press it twice
bind C-a send-prefix
# better mnemonics for splitting panes!
bind | split-window -h
bind - split-window -v
# window select
bind -r [ previous-window
bind -r ] next-window
# vim / xmonad style bindings for pane movement
bind -r h select-pane -L
bind -r j select-pane -D
bind -r k select-pane -U
bind -r l select-pane -R
# vim / xmonad style bindings for window movement
bind -r C-h select-window -t :-
bind -r C-l select-window -t :+
# shift-movement keys will resize panes
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
# disable mouse support (at least while we're learning)
set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
bind -n C-WheelUpPane select-pane -t= \; copy-mode -e \; send-keys -M
bind -T copy-mode-vi C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-vi C-WheelDownPane send-keys -X halfpage-down
bind -T copy-mode-emacs C-WheelUpPane send-keys -X halfpage-up
bind -T copy-mode-emacs C-WheelDownPane send-keys -X halfpage-down
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -selection c"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"
# turn on 256 color support in tmux
set -g default-terminal "screen-256color"
# fiddle with colors of status bar
set -g status-style "fg=white,bg=colour234"
# change color of active window
set-window-option -g window-status-style "fg=cyan,bg=colour234"
set-window-option -g window-status-current-style "fg=black,bg=white"
set-window-option -g window-status-bell-style "fg=default,bg=red"
set-window-option -g window-status-activity-style "fg=#8ae234,bg=black"
set-window-option -g window-status-format '#I:#{=15:window_name}#F'
set-window-option -g window-status-current-format '#I:#W#F'
# Colors
set-option -g pane-border-style "fg=white"
set-option -g pane-active-border-style "fg=red"
set-option -g display-panes-colour white
set-option -g display-panes-active-colour red
set-option -g mode-style "fg=#ffd787,bg=#5f8700"
set-option -g message-style "fg=black,bg=#8ae234"
# configure contents of status bar
# set -g status-utf8 on
set -g status-left-length 40
set -g status-left "#[fg=green]\"#S\""
set -g status-right "#[fg=green] #h | %d %b %R"
# set -g status-justify centre
# set -g monitor-activity on
# set -g visual-activity on
# navigate using vim-style keys
set -g mode-keys vi
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on
set -g mode-mouse on
# copy/paste using vim-style keys
# bind Escape copy-mode
# unbind p
# bind p paste-buffer
# set up alias for turning on logging
bind P pipe-pane -o "cat >>~/#W.log" \; display "Toggled logging to ~/#W.log"
# increase length of history buffer
set-option -g history-limit 9999
# unbind arrow keys. This prevents cases where you switch
# to a different pane, then use the arrow key to go through
# command history, and accidentally switch back to the previous
# pane
unbind Up
unbind Down
unbind Left
unbind Right
# invoke reattach-to-user-namespace every time a new window/pane opens
set-option -g default-shell /bin/zsh
# Use vim keybindings in copy mode
# setw -g mode-keys vi

install

brew install tmux

usage

vim ~/.tmux.conf

然后添加配置,之后 tmux kill-server,tmux 就会生效了。

hotkey

cmd:

  • tmux ls
  • tmux [new -s sessionName -n windowName]: create new session
  • tmux a -t xxx: open session named xxx

session:

  • Ctrl+q d: close session
  • Ctrl+q r: reload config
  • Ctrl+q $: rename session

window:

  • Ctrl+q c: new window
  • Ctrl+q &: close window
  • Ctrl+q s: list window
  • Ctrl+q <number>: toggle window
  • Ctrl+q [: previous window
  • Ctrl+q ]: next window

pane:

  • Ctrl+q -: split pane -
  • Ctrl+q |: split pane |
  • Ctrl+q x: close pane
  • Ctrl+q q: list pane
  • Ctrl+q <h|j|k|l>: select pane
@riskers
Copy link
Author

riskers commented Oct 21, 2019

@riskers
Copy link
Author

riskers commented Aug 25, 2021

tmux 配合 iTerm2 保持 SSH 登录

iTerm2 选中选项:

image

tmux 登录服务器后,不用的时候尽管退出即可

@riskers
Copy link
Author

riskers commented Aug 25, 2021

copy and paste on mac

配合 iTerm2

image

没试过的方法

https://robots.thoughtbot.com/tmux-copy-paste-on-os-x-a-better-future

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