Tmux and Vim

another level of procrastination, but really fun

Tmux and Vim

I have changed my workflow to tmux and vim lately. I'd like to share my experience with adopting these tools and focus on tmux and later post on vim. It's also in memory of Bram Moolenaar, the creator of vim, who passed away recently.

Perspetive on tmux and vim

tmux is a terminal multiplexer (manager tool). It allows you to run multiple terminal sessions in one terminal window as illustrated below.

tmux is easy to learn and set-up. You won't probably need to learn more than 10 commands to use it. If you use the terminal a lot, you should use tmux.

vim is a text editor. It allows you to edit text files very lightly and fast very great learning curve. When people talk about vim, they are referring to two things:

  • vim motion: the way you navigate and text editing in vim

  • vim editor: the text editor itself

I mainly adopted the vim motion in my workflow and use vscode as my text editor (don't call me out on this, I like vscode too). I love vim but I am biased. The learning curve is steep and it takes time to get used to it.

Please treat learning vim as a long-term investment if you enjoy coding and editing a lot of stuff. My philosophy is to treat learning vim as a learning instrument. You will feel like playing the piano on the keyboard once you get used to it.

Bram Moolenaar puts a lot of effort into vim to allow faster editing as long as you follow the vim way. Learning its pattern like [count]{operation}{motion}, you can do a lot of things very fast. It's also closely tied with sed and regex which are very powerful tools.

In short, if you are a terminal user, you should use tmux. The overhead is very low and you can learn it in 10 mins and instantly boost your productivity. If you are really serious about your craft and you want to learn an instrument on the keyboard. Please start using vim.

I will cover vim in another post. In this post, we will focus on tmux.

Three pillars of tmux

Tmux has main three pillars,

  • session: each session is a collection of windows

  • window: each window is a collection of panes

  • pane: panes are split of the terminal screen

tmux treats each session as a process for you to attach and detach. Once you understand that there are only sessions, windows and pane in tmux, you can categorize all the commands into these three categories,

  • navigate between session, window and pane

  • navigate in session, window and pane

  • create/destroy session, window and pane

Then you will be good to go.

Install

There are loads of tutorials on how to install tmux. I will just list the commands here and give some recommendations at the end.

# mac
brew install tmux

# ubuntu
apt-get install tmux

Sessions

For the session just remember, new, kill and attach (a)

tmux new-session -s <session_name>

tmux kill-session -t <session_name>

# attach to tagged session
tmux attach -t <session_name>

Windows and Panes

Everything in windows and panes starts from Ctrl + B. You can refer to this amazing cheatsheet with vi that I found on reddit for more details.

Summary

In this post we covered,

  • perspective on tmux and vim

  • understanding tmux basics

  • some pointers to tmux cheatsheet and tmux tutorial to grab the concept faster

References