mirror of
https://github.com/samoshkin/tmux-config.git
synced 2026-01-03 08:18:02 +00:00
Fix pane resizing. Add info about iTerm2 and tmux integration
This commit is contained in:
159
readme.md
159
readme.md
@@ -4,6 +4,18 @@ Tmux configuration, that supercharges your [tmux](https://tmux.github.io/) to bu
|
||||
|
||||

|
||||
|
||||
Table of contents
|
||||
-----------------
|
||||
|
||||
1. [Features](#features)
|
||||
1. [Installation](#installation)
|
||||
1. [General settings](#general-settings)
|
||||
1. [Key bindings](#key-bindings)
|
||||
1. [Status line](#status-line)
|
||||
1. [Nested tmux sessions](#nested-tmux-sessions)
|
||||
1. [Themes and customization](#themes-and-customization)
|
||||
1. [iTerm2 and tmux integration](#iterm2-and-tmux-integration)
|
||||
|
||||
Features
|
||||
---------
|
||||
|
||||
@@ -29,7 +41,6 @@ Features
|
||||
**TBD**:
|
||||
- [ ] retain current path when new pane is created
|
||||
- [ ] integration with clipboard
|
||||
- [ ] fix pane resizing
|
||||
- [ ] fix installation script to properly install TPM
|
||||
|
||||
|
||||
@@ -70,125 +81,191 @@ Key bindings
|
||||
-----------
|
||||
So `~/.tmux.conf` overrides default key bindings for many action, to make them more reasonable, easy to recall and comforable to type.
|
||||
|
||||
Let's go through them:
|
||||
Let's go through them.
|
||||
|
||||
If you are an iTerm2 user, third column describes the keybinding of similar "action" in iTerm2. It's possible to reuse very same keys you already get used to and tell iTerm2 to execute analogous tmux actions. See [iTerm2 and tmux integration](#iterm2-and-tmux-integration) section below.
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td nowrap><b>tmux key</b></td>
|
||||
<td><b>Description</b></td>
|
||||
<td><b>iTerm2 key</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap><code>C-a</code></td>
|
||||
<td>Default prefix, used instead of "C-b". Same prefix is used in screen program, and it's easy to type. The only drawback of "C-a" is that underlying shell does not receive the keystroke to move to the beginning of the line.
|
||||
</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap><code><prefix> C-e</code></td>
|
||||
<td>Open ~/.tmux.conf file in your $EDITOR</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> C-r</code></td>
|
||||
<td>Reload tmux configuration from ~/.tmux.conf file</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> r</code></td>
|
||||
<td>Rename current window</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> R</code></td>
|
||||
<td>Rename current session</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> _</code></td>
|
||||
<td>Split new pane horizontally</td>
|
||||
<td>⌘⇧D</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> |</code></td>
|
||||
<td>Split new pane vertically</td>
|
||||
<td>⌘D</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> <</code></td>
|
||||
<td>Move to previous window</td>
|
||||
<td>Select next pane</td>
|
||||
<td>⌘[</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> ></code></td>
|
||||
<td>Select previous pane</td>
|
||||
<td>⌘]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> ←</code></td>
|
||||
<td>Select pane on the left</td>
|
||||
<td>⌘⌥←</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> →</code></td>
|
||||
<td>Select pane on the right</td>
|
||||
<td>⌘⌥→</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> ↑</code></td>
|
||||
<td>Select pane on the top</td>
|
||||
<td>⌘⌥↑</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> ↓</code></td>
|
||||
<td>Select pane on the bottom</td>
|
||||
<td>⌘⌥↓</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> C-←</code></td>
|
||||
<td>Resize pane to the left</td>
|
||||
<td>^⌘←</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> C-→</code></td>
|
||||
<td>Resize pane to the right</td>
|
||||
<td>^⌘→</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> C-↑</code></td>
|
||||
<td>Resize pane to the top</td>
|
||||
<td>^⌘↑</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> C-↓</code></td>
|
||||
<td>Resize pane to the bottom</td>
|
||||
<td>^⌘↓</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> ></code></td>
|
||||
<td>Move to next window</td>
|
||||
<td>⌘⇧]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> M-<</code></td>
|
||||
<td>Move to previous window with alert</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> M-></code></td>
|
||||
<td>Move to next window with alert</td>
|
||||
<td><code><prefix> <</code></td>
|
||||
<td>Move to previous window</td>
|
||||
<td>⌘⇧[</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> Tab</code></td>
|
||||
<td>Switch to most recently used window</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> W</code></td>
|
||||
<td>Move to window by typing it's index</td>
|
||||
<td>^Tab</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> L</code></td>
|
||||
<td>Link window from another session by entering target session and window reference</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> \</code></td>
|
||||
<td>Swap panes back and forth with 1st pane. When in main-horizontal or main-vertical layout, the main panel is always at index 1. This keybinding let you swap secondary pane with main one, and do the opposite.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> o and O</code></td>
|
||||
<td>Select/focus panes in forward and backward direction</td>
|
||||
<td>⌘\</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> C-o</code></td>
|
||||
<td>Swap current active pane with next one</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> +</code></td>
|
||||
<td>Toggle zoom for current pane</td>
|
||||
</tr>
|
||||
<td>⌘⇧Enter</td>
|
||||
</td>
|
||||
<tr>
|
||||
<td><code><prefix> x</code></td>
|
||||
<td>Kill current pane</td>
|
||||
<td>⌘W</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> X</code></td>
|
||||
<td>Kill current window</td>
|
||||
<td>⌘⌥W</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> C-x</code></td>
|
||||
<td>Kill other windows but current one (with confirmation)</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> C-q</code></td>
|
||||
<td><code><prefix> Q</code></td>
|
||||
<td>Kill current session (with confirmation)</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> C-u</code></td>
|
||||
<td>Merge current session with another. Essentially, this moves all windows from current session to another one</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> d</code></td>
|
||||
<td>Detach from session</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> D</code></td>
|
||||
<td>Detach other clients except current one from session</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> C-s</code></td>
|
||||
<td>Toggle status bar visibility</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> m</code></td>
|
||||
<td>Monitor current window for activity</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> M</code></td>
|
||||
<td>Monitor current window for silence by entering silence period</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code><prefix> F12</code></td>
|
||||
<td>Switch off all key binding and prefix hanling in current window. See "Nested sessions" paragraph for more info</td>
|
||||
<td>-</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -279,3 +356,47 @@ move between them
|
||||
zoom window
|
||||
open nested tmux session
|
||||
scroll and copy
|
||||
|
||||
iTerm2 and tmux integration
|
||||
---------------------------
|
||||
|
||||
If you're an iTerm use same to me, most likely you already have a muscle memory for most common actions and keybindings (split pane, focus pane, fullscreen pane, move between tabs, create new tab, etc). When I switched to tmux, I found new key table more difficult: more keys to type, don't forget to enter `prefix` and recall if you've already pressed it or not (compare `C-a, c` with "⌘T", or `C-a ->` with "⌘⌥->"). iTerm2 keybinding was so natural to me, so I decided to remap most common keybindings to tell iTerm2 to execute corresponding tmux actions.
|
||||
|
||||
You can setup new profile in iTerm preferences to override default keybindings, to tell iTerm to send pre-configured sequences of keys, that will trigger corresponding action in tmux.
|
||||
|
||||

|
||||
|
||||
For example, when "^⌘↑" pressed, sequence of bytes `0x01 0x1b 0x5b 0x31 0x3b 0x35 0x41` are sent through terminal to running tmux instance, that interprets them as `C-a C-↑` keybinding and triggers `resize-pane -U` according to our `.tmux.conf` configuration.
|
||||
|
||||
You can get binary representation of any keys, using `showkey` or `od` commands
|
||||
|
||||
```
|
||||
$od -t x1
|
||||
|
||||
^A^[[1;5A // press C-a C-↑ on your keyboard
|
||||
0000000 01 1b 5b 31 3b 35 41
|
||||
0000007
|
||||
```
|
||||
|
||||
```
|
||||
$ showkey -a
|
||||
Press any keys - Ctrl-D will terminate this program
|
||||
|
||||
^A 1 0001 0x01
|
||||
^[[1;5A 27 0033 0x1b
|
||||
91 0133 0x5b
|
||||
49 0061 0x31
|
||||
59 0073 0x3b
|
||||
53 0065 0x35
|
||||
65 0101 0x41
|
||||
```
|
||||
|
||||
You can remap whatever key in this way, but I do this only for those ones, which have similar analogous action in tmux and are most common(resize pane, zoom pane, create new window, etc). See table with keybindings above.
|
||||
|
||||
As additional step, you can setup this new iTerm profile as default one, and tell it to jump into tmux session right off the start.
|
||||
|
||||

|
||||
|
||||
You can then go full screen in iTerm, so iTerm tabs and frame do not distract you (anyway now you're using iTerm just as a tunnel to your tmux, everything else happens inside tmux).
|
||||
|
||||

|
||||
|
||||
@@ -33,6 +33,32 @@ set -g mouse on
|
||||
# === Key bindings ===
|
||||
# ==========================
|
||||
|
||||
# Unbind default key bindings, we're going to override
|
||||
unbind "\$" # rename-session
|
||||
unbind , # rename-window
|
||||
unbind % # split-window -h
|
||||
unbind '"' # split-window
|
||||
unbind } # swap-pane -D
|
||||
unbind { # swap-pane -U
|
||||
unbind [ # paste-buffer
|
||||
unbind ]
|
||||
unbind "'" # select-window
|
||||
unbind n # next-window
|
||||
unbind p # previous-window
|
||||
unbind l # last-window
|
||||
unbind M-n # next window with alert
|
||||
unbind M-p # next window with alert
|
||||
unbind o # focus thru panes
|
||||
unbind & # kill-window
|
||||
unbind "#" # list-buffer
|
||||
unbind = # choose-buffer
|
||||
unbind z # zoom-pane
|
||||
unbind M-Up # resize 5 rows up
|
||||
unbind M-Down # resize 5 rows down
|
||||
unbind M-Right # resize 5 rows right
|
||||
unbind M-Left # resize 5 rows left
|
||||
|
||||
|
||||
# Edit configuration and reload
|
||||
bind C-e new-window -n 'tmux.conf' "sh -c '\${EDITOR:-vim} ~/.tmux.conf && tmux source ~/.tmux.conf && tmux display \"Config reloaded\"'"
|
||||
|
||||
@@ -40,34 +66,23 @@ bind C-e new-window -n 'tmux.conf' "sh -c '\${EDITOR:-vim} ~/.tmux.conf && tmux
|
||||
bind C-r source-file ~/.tmux.conf \; display "Config reloaded"
|
||||
|
||||
# Rename session and window
|
||||
unbind "\$"
|
||||
unbind ,
|
||||
bind r command-prompt -I "#{window_name}" "rename-window '%%'"
|
||||
bind R command-prompt -I "#{session_name}" "rename-session '%%'"
|
||||
|
||||
# Split panes
|
||||
unbind %
|
||||
unbind '"'
|
||||
bind | split-window -h
|
||||
bind _ split-window -v
|
||||
|
||||
# Select windows
|
||||
unbind }
|
||||
unbind {
|
||||
unbind "'"
|
||||
unbind n
|
||||
unbind p
|
||||
unbind l
|
||||
unbind M-n
|
||||
unbind M-p
|
||||
bind -r < previous-window
|
||||
bind -r > next-window
|
||||
bind -r M-< previous-window -a # prev window with alert
|
||||
bind -r M-> next-window -a # next window with alert
|
||||
bind -r Tab last-window # cycle thru MRU tabs
|
||||
bind W command-prompt -p "go to window #" "select-window -t ':%%'"
|
||||
# Select pane and windows
|
||||
bind -r C-[ previous-window
|
||||
bind -r C-] next-window
|
||||
bind -r [ select-pane -t :.-
|
||||
bind -r ] select-pane -t :.+
|
||||
bind -r Tab last-window # cycle thru MRU tabs
|
||||
bind -r C-o swap-pane -D
|
||||
|
||||
# TODO: fix pane resizing
|
||||
# Zoom pane
|
||||
bind + resize-pane -Z
|
||||
|
||||
# Link window
|
||||
bind L command-prompt -p "Link window from (session:window): " "link-window -s %% -a"
|
||||
@@ -78,17 +93,11 @@ bind \ if '[ #{pane_index} -eq 1 ]' \
|
||||
'swap-pane -s "!"' \
|
||||
'select-pane -t:.1 ; swap-pane -d -t 1 -s "!"'
|
||||
|
||||
# select/swap panes (counter)clockwise
|
||||
bind -r o select-pane -t :.+
|
||||
bind -r O select-pane -t :.-
|
||||
bind -r C-o swap-pane -D
|
||||
|
||||
# Kill pane/window/session shortcuts
|
||||
unbind &
|
||||
bind x kill-pane
|
||||
bind X kill-window
|
||||
bind C-x confirm-before -p "kill other windows? (y/n)" "kill-window -a"
|
||||
bind C-q confirm-before -p "kill-session #S? (y/n)" kill-session
|
||||
bind Q confirm-before -p "kill-session #S? (y/n)" kill-session
|
||||
|
||||
# Merge session with another one (e.g. move all windows)
|
||||
# If you use adhoc 1-window sessions, and you want to preserve session upon exit
|
||||
@@ -127,20 +136,15 @@ set -g visual-activity on
|
||||
# ================================
|
||||
# === Copy and scroll ===
|
||||
# ================================
|
||||
unbind "#" # list-buffer
|
||||
unbind = # choose-buffer
|
||||
unbind ] # paste-buffer
|
||||
|
||||
# Prefer vi style key table
|
||||
setw -g mode-keys vi
|
||||
|
||||
# trigger copy mode by
|
||||
bind PageUp copy-mode
|
||||
bind Escape copy-mode
|
||||
|
||||
bind p paste-buffer
|
||||
bind C-p choose-buffer
|
||||
|
||||
# trigger copy mode by
|
||||
bind -n M-Up copy-mode
|
||||
|
||||
# Scroll up/down by 1 line, half screen, whole screen
|
||||
bind -T copy-mode-vi M-Up send-keys -X scroll-up
|
||||
bind -T copy-mode-vi M-Down send-keys -X scroll-down
|
||||
@@ -158,10 +162,6 @@ bind -T copy-mode-vi WheelDownPane select-pane \; send-keys -X -N 2 scroll-d
|
||||
unbind -T copy-mode-vi MouseDragEnd1Pane
|
||||
bind -T copy-mode-vi MouseDown1Pane select-pane \; send-keys -X copy-selection
|
||||
|
||||
# Zoom pane
|
||||
unbind z
|
||||
bind + resize-pane -Z
|
||||
|
||||
|
||||
|
||||
# =====================================
|
||||
|
||||
Reference in New Issue
Block a user