Tmux Tutorial : Part I

vamsi
4 min readAug 21, 2021

--

Who is this post for?

Well if you are a beginner at Tmux , have just installed it and want to improve your Tmux pipeline, then this is where you should be. In this post I will cover all the useful commands and shortcuts that would be helpful in managing your projects in Tmux.

Prefix Key

By default in Tmux “Ctrl + b” is mapped as Prefix key. This key would be used frequently when you are using shortcuts in Tmux. So in the following commands where ever I am using Prefix key combination I would be referring to that combination using “<Prefix>” this symbol.

Creating Panes

We can create panes by splitting tmux window vertically or horizontally. In the below clip we can see the related commands.

split panes vertically and horizontally
split panes vertically and horizontally

Split vertically : <Prefix> , “

Split horizontally : <Prefix> , %

Switching between Panes

switch between panes
switch between panes

We can easily switch between panes by using prefix key and arrow keys.

up : <prefix> , 🠕

down : <prefix> , 🠗

left : <prefix> , 🠔

right : <prefix> ,

We can even change the size of panes using arrow keys.

change size of panes : <prefix> ,<ctrl> + arrow keys

Creating and Switching between Windows

We have panes then why do we need windows 💁. We can create panes but things will get complicated when you create over 4 panes or you may want to run something unrelated to these files and you don’t want it to appear in this window. Windows will be useful when you start working with multiple files at a time 😉. Observe the bottom line for changes in the windows.

creating and switching between windows
Creating and Switching between windows

In the following clip I am manually adding the text “window 0,1,2,3” to distinguish between windows, it doesn’t print out by default

create window : <prefix> , c

previous window : <prefix> , p

next window : <prefix> , n

x numbered window : <prefix> , x

Renaming Windows

renaming windows
renaming windows

rename window : <prefix> , , (after pressing prefix key press ,)

Attaching and Detaching Sessions

One of the main reasons behind the popularity of tmux is that we can detach from a session and it will be running in background till we kill the session. If you don’t understand what I am saying, no problem below is a clip demonstrating this feature 😃

attach and detach sessions
attach and detach sessions

If we observe the above clip we can see that we can easily detach and attach to our sessions. Whenever we detach from a session it keeps running in the background and we can view those sessions and windows. When we list the sessions by default tmux allocates a number to a session starting from 0. So when we want to connect to a particular session we have to use this number.

detach session : <prefix> , d

list windows : tmux list-windows (for last active session)

list all windows : tmux list-windows -a

list sessions : tmux list-sessions

attach session : tmux a -t session_name

If we want to create a session with specific name then we can make use of the following command:

session with specific name : tmux new-session -s session_name

Rename and Killing Sessions

renaming and killing sessions
renaming and killing sessions

From the above clip we can see various commands to rename and kill a session. We even have a command to kill a window which is present inside of a session. Following are the commands :

rename-session : tmux rename-session -t old_name new_name

kill-session : tmux kill-session -t session_name

kill-window : tmux kill-window -t window_name

Conclusion

All the above commands would be helpful in your daily usage of tmux for various projects. In this tutorial we haven’t covered how we can configure tmux and how we can change key mappings things like that. But you would be good to go if you have learned the above commands and shortcuts. If you have any suggestions and any doubts please feel free to drop a comment. Hope you have enjoyed the read !!

--

--