08 - What is tmux and how to use it in macOS
Contents
- YouTube video
- If you like this, and want to support me
- Follow me on Twitter
- What is tmux and why do I use it?
- Install
- tmux configuration file
- Delete tmux resurrect settings
- Tmux basics
YouTube video
If you like this, and want to support me
- This helps me to keep creating content and sharing it
- Share a tip here
Follow me on Twitter
- Or as kids call it these days “X”
- Here’s the link
What is tmux and why do I use it?
- NOTE TO SELF: Git access and private keys, access to my other repos
- Tmux is a terminal multiplexer, I use it to create different windows and sessions to work on different tasks.
- Tmux has what is known as the
command mode
. In this mode you enter tmux commands or shortcuts that perform different actions - To enter command mode you press
ctrl+b
- In the karabiner video we configured my keymappings, so I use
hyper+b
instead. It’s easier to type - Demonstration in the video, I cover:
- How tmux is useful when sshing to multiple hosts
- Synchronize commands across panes
- Have 2 files open to compare or work with
- Have different windows open with different workloads
Install
- We already installed tmux when we ran the installed multiple apps with brew (video 3)
- Notice the green line at the bottom
- My tmux configuration file is already pointing to the file that we cloned from my dotfiles-latest repo as seen below
1
cd && ls -al
- So now I need to install the tmux plugin manager, so that the theme I have configured gets applied, and other tmux plugins are also installed
1
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
- Now we need to install the plugins
- If you have issues installing the plugins below, close alacritty and open it again
- Press
ctrl+b
in the terminal to execute tmux commands - Then capital I
shift+i
to install
- Press
- Notice that the pane shows at the bottom
tmux configuration file
- We’ll go over the tmux configuration file in the video. I have comments In the file that will help you navigate around and better use tmux
Delete tmux resurrect settings
- I wanted to delete my resurrect data to start fresh with tmux, so all you need to do is delete this folder below. You can
mv
it instead of deleting it in case you want to back it up
1
rm -rf ~/.local/share/tmux
Tmux basics
- To start a new tmux session without sourcing the
.tmux.conf
file this is useful to see if your config is causing any issues
1
tmux -f /dev/null
- From inside tmux to view the list of all the commands run
ctrl+b?
- Create a new session with a name outside tmux
1
tmux new -s xcp
- Create a new session with a name from within tmux
- So press
ctrl+b
- Then
:
- So press
1
new -s dotfiles
- Detach from the session (this even closes Alacritty for me)
ctrl+b d
- from within tmux
1
tmux detach
- See list of sessions
ctrl+b s
- from within tmux
1
tmux ls
- See list of windows and sessions
ctrl+b w
- When in here, you can type
x
to kill a session and typeyes
at the bottom
- Attach to a session
1
2
tmux a -t xcp
tmux a -t 0
- To create a new window inside a session
ctrl+b c
- Kill current window (or just type exit on the terminal)
C-b &
- To navigate between windows inside a session
ctrl+b n
- nextctrl+b p
- previous (I remapped this to ‘m’)ctrl+b #
- specify a number
- Maximize and minimize back a pane
ctrl+b m
- I remapped this toctrl+b M
- Rename a session
ctrl+b $
- Rename current window
ctrl+b ,
- Scroll in a tmux pane
ctrl+[
- Then scroll with vim navigation
- When inside this mode you can also use the following and the cursor will be kept in a fixed position
- shift J
- shift K
- When in this mode:
- We can select text with
v
- And copy the text with
y
- This is because the
bind-key -T copy-mode-vi 'v' send -X begin-selection
lines in our tmux config file
- We can select text with
q
to stop scrolling- or
ctrl+c
- or
This post is licensed under CC BY 4.0 by the author.