Skip to content
April 4, 2013 / Karthikeyan Natarajan

tmux rules

I was using screen to run scripts using ssh and detach it so that I can close ssh after running scripts.  I wanted to work with multiple source files in vi editor and also i don’t want to quit vi and then open all files in vi editor again after compilation and execution. This is where tmux comes in handy with powers of screen and multiple windows and panes.

tmux is extremely convenient if you could play around ~/.tmux.conf file.

First of all, default prefix for tmux is Ctrl+b. Key ‘B’ is bit far from both Control keys. So, I wanted to switch to Ctrl+a. so add following line to ~/.tmux.conf

# remap prefix to Control + a
set -g prefix C-a
unbind C-b
bind C-a send-prefix

Next how to split panes. Instead of %, I used
Ctrl+a \ New vertical pane
Ctrl+a – New horizontal pane
which most of vi editor lovers would like to do. I wanted more like browser interface.
Ctrl+n new vertical pane.
Ctrl+h new horizontal pane.
Ctrl+w Closing current pane

Paste this code in tmux config file (~/.tmux.conf)

unbind %
bind \ split-window -h
bind – split-window -v
bind-key -n C-n  split-window -h
bind-key -n C-h  split-window -v
bind-key -n C-w  kill-pane
set -g mouse-select-pane on

Also to switch between panes, I wanted to use Ctrl+Up, and Ctrl+Down.

bind-key -n C-Up    up-pane
bind-key -n C-Down  down-pane

There are some of customizations using -n option. -n option allows to bind keys without prefix.
In order to load modified tmux file, type once

tmux source ./.tmux.conf

Create tmux session,
tmux
Each session will be numbered as 0, 1, 2 …
Named sessions can started as
tmux new -s name
To detach current tmux session, Press Ctrl+a d
you can configure any new key combination for detaching using -n option.

bind-key -n C-q detach

To resume/attach current session,
tmux attach -t name

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: