Skip to content

Instantly share code, notes, and snippets.

@davidhcefx
Last active March 1, 2024 11:27
Show Gist options
  • Save davidhcefx/c340e3fc2abfb5dd613ddae817401478 to your computer and use it in GitHub Desktop.
Save davidhcefx/c340e3fc2abfb5dd613ddae817401478 to your computer and use it in GitHub Desktop.
Clipboard Integration, Mouse Selection, Intuition

My Tmux Config

Features

  • More intuitive. (eg. + to create windows, | to split horizontally, Ctrl+C to copy, End to move to end-of-line)
  • System clipboard integration. (support: MacOS, X-Window, Cygwin)
  • Words highlighted by your mouse will stay on the screen; good for explaining stuff to others.

Installation

  1. Install tmux, for example, via apt-get install tmux.
  2. Under home directory, create a file ~/.tmux.conf with the following contents.
  3. If you are using the X-Window-Manager (eg. Ubuntu), be sure to install the xclip.

Config

# This is davidhcefx's custom tmux keybinding.
# Part of it is based on Mr. Opengate's keybinding.

# Prefix setting (screen-like)
set -g prefix C-a
unbind C-b
bind C-a send-prefix

# Reload config without killing server
bind R source-file ~/.tmux.conf \; display-message "Config reloaded..."

# "|" splits the current window vertically, and "-" splits it horizontally
unbind '%'
unbind '"'
bind '|' split-window -h
bind '-' split-window -v

# Swap with prev/next pane
bind '<' swap-pane -U
bind '>' swap-pane -D

# New window
bind + new-window

# Switch between windows
bind [ previous-window
bind ] next-window
bind C-[ previous-window
bind C-] next-window

# Swap with prev/next window
bind '{' swap-window -d -t -1
bind '}' swap-window -d -t +1

# Join pane to this window
bind '@' choose-window 'join-pane -h -s "%%"'

# Copy mode & paste buffer
bind c copy-mode
bind p paste-buffer

# Copy to system clipboard & buffer
# - Linux: xclip -i -selection c
# - Mac: pbcopy
# - Cygwin: cat > /dev/clipboard
bind -T copy-mode-vi C-c send-keys -X copy-pipe "xclip -i -selection c" \; send-keys -X copy-selection

# Paste from system clipboard
# - Linux: xclip -o -selection c
# - Mac: pbpaste
# - Cygwin: cat /dev/clipboard
bind -T prefix C-v run-shell "xclip -o -selection c | tmux load-buffer - ; tmux paste-buffer"

# Leave selected words on screen
bind -T copy-mode-vi MouseDrag1Pane select-pane \; send-keys -X begin-selection
unbind -T copy-mode-vi MouseDragEnd1Pane

# Left click to clear selection, right click to cancel
bind -T copy-mode-vi MouseDown1Pane select-pane \; send-keys -X clear-selection
bind -T copy-mode-vi MouseDown3Pane select-pane \; send-keys -X cancel

# Home & end
bind -T copy-mode-vi End  send-keys -X end-of-line
bind -T copy-mode-vi Home send-keys -X start-of-line

# Word boundaries
bind -T copy-mode-vi M-Right send-keys -X next-word
bind -T copy-mode-vi M-Left  send-keys -X previous-word

# List all key bindings
bind -T prefix '?' list-keys

# Use vi mode
set -g mode-keys vi


### other optimization

# set the shell you like (zsh, "which zsh" to find the path)
# set -g default-command /bin/zsh
# set -g default-shell /bin/zsh

# use UTF8
# set -g utf8
# set-window-option -g utf8 on

# display things in 256 colors
set -g default-terminal "screen-256color"

# mouse is great!
set-option -g mouse on

# history size
set -g history-limit 10000

# fix delay and repeat time
set -g escape-time 0
set -g repeat-time 0

# 0 is too far
set -g base-index 1
setw -g pane-base-index 1

# 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

# tmux messages are displayed for 1 seconds
set -g display-time 1000

# change terminal title according to window title
set -g set-titles on
set -g set-titles-string "#W  (###P)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment