Tmux is a great alternative to gnu screen. I’ve previously posted my cygwin tmux config in 2020, and I figured I’d update with my additions since then, including running under real linux. So here it is. Its features include:
- Uses ctrl+a, like gnu screen, instead of ctrl+b
- Mouse interaction is enabled
- Tab bar/windows:
- Current tab is highlighted in cyan
- Cycle through tabbed windows with a click on its tab or ctrl+shift+alt+arrow_keys
- Reorder tabbed windows with a drag of its tab
or alt+arrow_keys
- ctrl+a,/ to rename a tab on the tab bar
- Create new window with ctrl+a,c
- Panes
- Create split panes with vertical=ctrl+a,| and horizontal=ctrl+a,- (and start in the cwd)
- Move around panes with click or ctrl+shift+arrow_keys
- Resize panes by dragging on the separator bar or use alt+shift+arrow_keys
- Swap panes directionally with alt+arrow_keys
- Panes automatically resize to fit OS window
- Clipboard/highlighting
- Copy text to clipboard by highlighting it
- Paste from clipboard with right click
- Middle mouse button+drag highlights and copies too. I did this since nano takes over normal mouse click+drag.
- Copy mode
Key* | Action |
Ctrl+PageUp | Start copy mode, scroll page up |
Ctrl+PageDown | Start copy mode |
Enter | Copies selected text to clipboard and ends copy mode |
Shift+(Left/Right) | Starts selection mode on previous/next character (or continues selection navigation like normal left/right) |
Escape | If something is selected, end current selection. Otherwise, exit copy mode |
Ctrl+(Home/End) | Go to top/bottom of the buffer |
Ctrl+(Left/Right) | Moves to previous/next word like when not in copy mode |
Ctrl+F3, Ctrl+F3 | Start incremental search in copy mode |
F3/Shift+F3 | Search next/previous (Note, if you use gnome-terminal it may override this) |
* When bolded/cyan the key is for when in copy mode
- Start the session on the current bash directory
- Escape time is lowered for quicker response to copy mode access
To use this, save the file to ~/.tmux.conf
#Mouse interaction
set -g mouse on
#Lower escape timing from 500ms to 50ms for quicker response to copy-mode access
set -s escape-time 50
#Window always takes up largest possible max size
set-window-option -g aggressive-resize
#Highlight active window in tab-bar at bottom in cyan
set-window-option -g window-status-current-style bg=cyan
#Reorder windows in status bar by drag & drop
bind-key -n MouseDrag1Status swap-window -t=
#Copy to clipboard on text selection
bind -Tcopy-mode MouseDragEnd1Pane { send -X copy-selection-and-cancel; run-shell -b "tmux show-buffer | xclip -selection clipboard" }
#Paste from clipboard with right click
bind-key -n MouseDown3Pane { run-shell 'tmux set-buffer -b winclip "$(xclip -o -selection clipboard)"'; paste-buffer -db winclip }
#Middle drag runs copy (Since some programs like nano take control of the mouse for normal selection)
bind -n MouseDrag2Pane copy-mode -M
bind -Tcopy-mode MouseDragEnd2Pane { send -X copy-selection-and-cancel; run-shell -b "tmux show-buffer | xclip -selection clipboard" }
bind-key -n MouseDown2Pane run-shell -b "echo '' > /dev/null"
#Remap prefix to Control+a
set -g prefix C-a
unbind C-b
#bind 'C-a C-a' to type 'C-a'
bind C-a send-prefix
#Start in CWD when creating or splitting tabs; move the splitting planes keys to | and -
bind '|' split-window -h -c '#{pane_current_path}' # Split panes horizontal
bind '\' split-window -h -c '#{pane_current_path}' # Split panes horizontal
bind '-' split-window -v -c '#{pane_current_path}' # Split panes vertically
bind c new-window -c '#{pane_current_path}' # Create new window
unbind '"'
unbind %
#Select next/prev window with Ctrl+Shift+Alt+(Left|Right)
bind-key -n C-S-M-Right next-window
bind-key -n C-S-M-Left previous-window
#Reorder panes with Alt+arrow
bind-key -n M-Left swap-pane -t '{left-of}' -d
bind-key -n M-Right swap-pane -t '{right-of}' -d
bind-key -n M-Up swap-pane -t '{up-of}' -d
bind-key -n M-Down swap-pane -t '{down-of}' -d
#Switch panes using Ctrl+shift+arrow - I rather would have used Ctrl+arrow, but that can interfeer with other programs like nano
bind -n C-S-Left select-pane -L
bind -n C-S-Right select-pane -R
bind -n C-S-Up select-pane -U
bind -n C-S-Down select-pane -D
#Resize panes using Alt+Shift+arrow
bind-key -n M-S-Up resize-pane -U 1
bind-key -n M-S-Down resize-pane -D 1
bind-key -n M-S-Left resize-pane -L 1
bind-key -n M-S-Right resize-pane -R 1
#Ctrl+F3 starts searching in copy mode
bind -n C-F3 { copy-mode; command-prompt -T search -ip'(search down)' -I'#{pane_search_string}' { send -X search-forward-incremental '%%' } }
#prefix, / -- Renames window, but starts blank
bind-key / command-prompt "rename-window '%%'"
#---Copy mode---
#Enter key in copy mode copies to clipboard and ends copy mode
bind-key -Tcopy-mode Enter { send -X copy-selection-and-cancel; run-shell -b "tmux show-buffer | xclip -selection clipboard" }
#Ctrl+PageUp = Copy mode, scroll page up
bind-key -n C-PageUp copy-mode -u
#Ctrl+PageDown = Copy mode
bind-key -n C-PageDown copy-mode
#Shift+Left = Start selection mode on previous character (if selection mode is active, do not restart selection)
bind-key -Tcopy-mode S-Left { run-shell "tmux display-message -p \"#{selection_active}\" | awk '{print ($0 == 1) ? \"\" : \"tmux send -X begin-selection\"}' | sh"; send -X cursor-left }
#Shift+Right = Start selection mode on current character (if selection mode is active, do not restart selection)
bind-key -Tcopy-mode S-Right { run-shell "tmux display-message -p \"#{selection_active}\" | awk '{print ($0 == 1) ? \"\" : \"tmux send -X begin-selection\"}' | sh"; send -X cursor-right }
#Escape = If something is selected, end current selection. Otherwise, exit copy mode.
bind-key -Tcopy-mode Escape run-shell "tmux display-message -p \"#{selection_active}\" | awk '{print ($0 == 1) ? \"tmux send -X clear-selection\" : \"tmux send -X cancel\"}' | sh"
#Ctrl+Home = Go to top of buffer
bind-key -Tcopy-mode C-Home send -X history-top
#Ctrl+End = Go to bottom of buffer
bind-key -Tcopy-mode C-End send -X history-bottom
#Ctrl+Left = Previous work
bind-key -Tcopy-mode C-Left send -X previous-word
#Ctrl+Right = Next work
bind-key -Tcopy-mode C-Right send -X next-word
#Ctrl+F3 = Start incremental search
bind -Tcopy-mode C-F3 { command-prompt -T search -ip'(search down)' -I'#{pane_search_string}' { send -X search-forward-incremental '%%' } }
#F3 = Search next (Note, if you use gnome-terminal it may override this)
bind -Tcopy-mode F3 send -X search-again
#Shift+F3 = Search previous (Note, if you use gnome-terminal it may override this)
bind -Tcopy-mode S-F3 send -X search-reverse