(concat user-full-name " " (format-time-string "%Y-%m-%d %5z"))# Created: Fang lungang 2010-11-08
# Updated: <<tangle-time-stamp()>>
In case tmux is not available, below are some basic usage of Screen:
| new session foo | screen -S foo |
| attach to session foo | screen -x foo |
| list all sessions | screen -ls |
| create a new window | C-a C-c |
| list and switch window | C-a ” |
| detach | C-a C-d |
| kill window | C-a k |
Force tmux to use “true color”:
set -g default-terminal "xterm-256color"
set -ag terminal-overrides ",xterm-256color:RGB"
Ideally, tmux should detect the terminal emulator’s color capability automatically, but this does not always work. Hence, sometimes we need to explicitly tell tmux that the terminal emulator is capable of that.
set -g prefix F12 # if not work, check if TERM=xterm
bind-key F12 send-prefix
Use F12 as the prefix. Pressing F12 twice sends the prefix key (i.e. F12 per my configuration) to the underlying window. This is makes working with nested tmux sessions much easier:
- “F12 <key>” sends the key to the outer tmux session.
- “F12 F12 <key>” sends the key the inner tmux session.
- Press Shift+F12 once
- Enter nested mode. The outer session’s status bar is hidden, and subsequent keys (except Shift+F12) are sent to the inner session, allowing interaction as if it is not nested.
- Press Shift-F12 again
- Exit nested mode.
bind -T root S-F12 set prefix None \; set key-table off \; set status off \; refresh-client -S
bind -T off S-F12 set -u prefix \; set -u key-table \; set status on \; refresh-client -S
bind -n F11 copy-mode
set -g status on
set -g status-position bottom
# Key to toggle status bar on/off
bind-key b set status
# colors
set -g status-style 'bg=#1e1e2e fg=#cdd6f4'
# Left side
set -g status-left-length 60
set -g status-left '#[fg=#1e1e2e,bg=#a6e3a1,bold] #H #[fg=#89b4fa,bg=#1e1e2e] | #[fg=#1e1e2e,bg=#89b4fa,bold]#{?session_grouped, #{session_group}:,} #S #[fg=#89b4fa,bg=#1e1e2e] | '
set -g status-justify left # the window list
# Right side of status bar
set -g status-right-length 0
set -g status-right ''
# Window status
set -g window-status-format ' #I:#W '
set -g window-status-current-format '#[fg=#1e1e2e,bg=#cba6f7,bold] #I:#W #[fg=#cba6f7,bg=#1e1e2e]'
set -g window-status-activity-style fg=red
# Window Behavior
setw -g automatic-rename on
setw -g monitor-activity on
set -g status-interval 1
If you do not hide the title bar of the terminal emulator, the following sets its title.
set -g set-titles on
set -g set-titles-string '#h: #S'
# pre-load a frequently used text into the buffer named "hw"
set-buffer -b hw "hello world"
#* Timers
set -g display-time 3000
set -g history-limit 50000
set -g repeat-time 500
#* Mouse support
set -g mouse on
#** Enter copy mode directly on mouse wheel
## Check #{alternate_on} to determine if the underlying application uses the
## alternate display and shall we pass the event alone or not.
bind-key -T root WheelUpPane if-shell -F -t = "#{alternate_on}" "send-keys -M" "select-pane -t =; copy-mode -e; send-keys -M"
#** Speedup (based on Thomas Sattler at
## https://groups.google.com/forum/#!topic/tmux-users/TRwPgEOVqho)
bind-key -T root C-WheelUpPane if-shell -F -t = "#{alternate_on}" "send-keys -M" "select-pane -t =; copy-mode -e; send-keys -M"
bind-key -T copy-mode-emacs C-WheelUpPane send-keys -X halfpage-up
bind-key -T copy-mode-emacs C-WheelDownPane send-keys -X halfpage-down
#* Key bindings
set -g status-keys emacs
set -g mode-keys emacs
bind-key | split-window -h -c "#{pane_current_path}" # default is "
bind-key _ split-window -v -c "#{pane_current_path}" # default is %
bind-key -r Tab select-pane -t:.+ # easier to key-chord than F12+<arrow>
bind-key -r BTab select-pane -t:.-
bind-key -T copy-mode-emacs C-g send-keys -X cancel # C-g (instead of ESC) to quit copy-mode
bind-key -T edit-mode-emacs C-g send-keys -X cancel # C-g to quit command editing
bind-key C-s setw synchronize-panes
bind-key < set automatic-rename on
bind-key -r n next-window # same as default ones but are repeat-able
bind-key -r p previous-window
bind-key -r Space next-layout
# Conflicts with my emacs settings.
# bind-key -nr C-Up select-pane -U
# bind-key -nr C-Down select-pane -D
# bind-key -nr C-Left select-pane -L
# bind-key -nr C-Right select-pane -R
bind-key c new-window -c "#{pane_current_path}"
bind-key m command-prompt -p "move (swap) current pane with: " "swap-pane -s %1"
bind-key j command-prompt "join-pane -h -d -s '%1'"
bind-key C command-prompt "new-window '%1'" # open a new window running given command
bind-key S command-prompt "new-session -s '%1'"
# Similar to mouse scroll
bind-key -T root PPage if-shell -F "#{alternate_on}" "send-keys PPage" "copy-mode -e; send-keys PPage"
#** Screen log
# `C-h' to save log
bind-key C-h command-prompt -p "save log to:" \
"copy-mode; send-keys 'M->' C-e C-space 'M-<' C-a C-w; save-buffer %%"
# # if "setw -g mode-keys vi", use this one:
# bind-key C-h command-prompt -p "save log to:" \
# "copy-mode; send-keys g 'space' G 'enter'; save-buffer %%"
# ## NOT recommended
# bind-key h pipe-pane "cat >>$HOME/#S-#I-#P.log" \; \
# rename-window "log" \; \
# display-message "Start logging($HOME/#S-#I-#P.log)"
# bind-key H pipe-pane \; \
# setw automatic-rename on \; \
# display-message "Stopped logging(#S-#I-#P.log)"
#* Copy/paste buffer
#** Paste from system clipboard (and save it to tmux buffer). Bind it to "C-]"
#** not "]" so that you need to explicitly request copying from system clipboard
#** by pressing an additional key (i.e. Control). This decision is made because
#** tmux buffer is for copying/pasting among CLIs but the system clipboard may
#** contain a large chunk of documentations or source code. Pasting such
#** contents into command line can be troublesome. Also see my .bashrc for the
#** function clean_tmux_buffers.
bind-key C-] run "tmux set-buffer \"$(pbpaste)\"; tmux paste-buffer"