Skip to content

Instantly share code, notes, and snippets.

@ooola
Last active June 30, 2023 18:46
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 ooola/698c336a455bcd1f7e0cf76ea87e067a to your computer and use it in GitHub Desktop.
Save ooola/698c336a455bcd1f7e0cf76ea87e067a to your computer and use it in GitHub Desktop.
# Ola's ~/.tmux.conf
#
# This config file was originally based on the tmux config that ships with tmux.
# See https://github.com/tmux/tmux/blob/master/example_tmux.conf
#
# It has been modified so that the prefix is <Ctrl>-a and the CapsLock
# key also acts as a Ctrl via an OS keymap change.
#
# On OS X be sure to install 'reattach-to-user-namespace' via brew.
set -g default-terminal "screen-256color"
# Set the prefix to ^A.
unbind C-b
set -g prefix ^A
bind a send-prefix
# prefix r shortcut for reloading your tmux config
bind r source-file ~/.tmux.conf
# Fix delay to not interfere with vim
set -s escape-time 4
# Enable OS X mouse support
setw -g mouse on
# Vim like pane navigation
unbind-key k
bind-key k select-pane -U
unbind-key j
bind-key j select-pane -D
unbind-key h
bind-key h select-pane -L
unbind-key l
bind-key l select-pane -R
# From https://github.com/nicknisi/dotfiles/blob/master/tmux/tmux.conf.symlink
# set vi mode for copy mode
setw -g mode-keys vi
# more settings to make copy-mode more vim-like
## keep both [ and Escape to allow entering copy-mode
#unbind [
bind Escape copy-mode
unbind p
bind p paste-buffer
bind -Tcopy-mode-vi 'v' send -X begin-selection
bind -Tcopy-mode-vi 'y' send -X copy-pipe-and-cancel "tmux save-buffer - | reattach-to-user-namespace -l zsh pbcopy"
# Important must do `brew install reattach-to-user-namespace`
# Buffers to/from Mac clipboard, yay tmux book from pragprog
bind C-c run "tmux save-buffer - | reattach-to-user-namespace pbcopy"
bind C-v run "tmux set-buffer $(reattach-to-user-namespace pbpaste); tmux paste-buffer"
set -g default-shell $SHELL
set -g default-command "reattach-to-user-namespace -l ${SHELL}"
## To start
$ tmux
# note that my config Ctrl-b is Ctrl-a (reaching all the way to 'b' is crazy IMHO)
- Split Screen into 2 Panes:
Ctrl-b %
- Split current Pane horizontally into 2 Panes:
Ctrl-b "
- Switch between Panes:
Ctrl-b o
- Create new Window:
Ctrl-b c
- Switch between Windows:
Ctrl-b n # next
Ctrl-b p # previous
- New session within a session
Ctrl-b :new
- Detach
Ctrl-b d
- List active sessions
$ tmux ls
- Attach to the last session
$ tmux a
- List commands
Ctrl-b :list-commands
## More Commands
From Tmux 2 Book I bought
- prefix 0..9 - select window
- prefix w - display windows
- prefix f - find window with text
- prefix , - prompt to rename window
- prefix % - split window in half vertically
- prefix ‘’ - split window horizontally
- prefix q - display pane number
- prefix x - close pane
- prefix Space - cycle through pane layouts
### Copy
To copy,
1. Select the shit with the cursor, THEN
2. CTRL-a, CTRL-v
3. This copies the shit to the system clipboard buffer
## Daniel Messler Tutorial
- source <http://danielmiessler.com/study/tmux/>
By default, tmux uses Ctrl-b as its shortcut activation chord but my config changes it to Ctrl-a
#!/bin/bash
# a shell script
tmux new-session -s bzmono -n bzmono -d
tmux send-keys -t bzmono:0 'cd ~/code/bzmono' C-m
tmux new-window -n tomcat -t bzmono:1
tmux send-keys -t bzmono:1 'cd ~/code/dev-vagrant' C-m
tmux send-keys -t bzmono:1 './watchTomcatLog' C-m
tmux new-window -n webui -t bzmono:2
tmux send-keys -t bzmono:2 'cd ~/code/dev-vagrant' C-m
tmux send-keys -t bzmono:2 './watchWebuiLog' C-m
tmux new-window -n all -t bzmono:3
tmux send-keys -t bzmono:3 'cd ~/code/dev-vagrant' C-m
tmux new-window -n tmp -t bzmono:4
tmux send-keys -t bzmono:4 'cd ~/code/dev-vagrant' C-m
# only run this if you have the github 'gh' command installed and the 'dash' plugin
#tmux new-window -n dash -t bzmono:5
#tmux send-keys -t bzmono:5 'cd ~/code/bzmono && gh dash' C-m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment