2 months of vim and tmux
For the last two months I’ve been using 3 tools to effectively work with the terminal on Linux. In this post I’ll try to sum up my experience so far and show you all the tools that I’m using at the moment.
In the post I will add some commands that I find useful everyday. Please bare in mind that in 2 months I barely scratched the surface of both vim and tmux.
A bit of a background
Almost all my life I was relying on IDEs(in the recent years mainly Visual Studio) or text editors(Notepad++, Sublime text, Atom, Visual Studio Code). In November last year I started working as a R&D engineer at Terabee where I’m working a lot with ROS (Robot Operating System).
The thing about ROS is that it usually requires you to run many programs from the terminal at the same time. Being fed up with constantly cycling over multiple terminal windows I was desperate to find something to make my workflow smoother. That’s how I found tmux.
I usually have multiple windows open at once in tmux. In first window I keep my vimwiki (more on that later) and a separate pane for git (only for my vimwiki repo).
My second windows usually contains multiple panes for running ROS nodes, working with topics etc.
Third window is my development window, usually it has only one pane that sometimes I split vertically inside vim.
Sometimes my fourth window is for writing and running unit tests (depending on the project)
I’m quite flexible with the setup, so I will often add or remove windows depending on my needs.
Basic tmux commands that I use
- Split pane vertically
- Split pane horizontally
- Create new window
- Delete pane
- Move to the next window
- Rename current window
- Go to window
- Enable scroll
ctrl-b+[(q to exit scrollig)
- Kill window
- Zoom pane
- Go to previous window
- Go to next window
- Switch panes
- Enter command mode
- Synchronize panes
tmux-ressurect can be used to preserve the tmux session. It allows to preserve windows and panes as well as paths and vim sessions. It’s trivial to use:
- Save session
- Reload session
I only wish it supported restoring bash history better but hopefully it will get there in the future!
It’s crazy how much I still don’t know about vim. I don’t think I even use 1% of its functionality. Currently I use it as you would use any other text editor with an advantage of seamless integration with the terminal.
I will be learning more and more about vim as I go. I heard stories about vim scripting functionality. Currently I’m hoping to explore vim in more detail as on of the projects in 1PPM.
If you want to give vim a try then hopefully some of those command will give you a head start:
- open file
- start vim with two files vsplit
vim -O file1.txt file2.txt
- highlight syntax for xml
- set autoindent
:set autoindent_ | _:set ai
:setlocal spell spelllang=en_gb
- Set tab width to 4 spaces
Tabs and splits
- edit a file in a new tab
- next tab
- previous tab
- split open file
- exit insert mode
- go to normal mode for one command
- Go to beginning of a line
^ or 0(normal mode)
- Go to the end of a line
- Go to the top of window
- Go to last line of file
Vimwiki is a personal wiki for vim. It comes with very nice syntax highlighting and although it allows for exporting documents to html I don’t usually do that as I find really easy to navigate from within vim.
I keep the wiki with all the files as a private repository on gitlab so that I can easily access it anywhere. At the time of writing this post I have 61 files in my wiki and on average I make a single commit to it every day.
I’m trying to minimize customization of both vim and tmux to minimum, mainly for two reasons:
- If I was to lose my configs I would be super confused and it could take time to restore the settings (I would probably keep it as a repository to be honest)
- If I have to work on unfamiliar PC I can do majority of work straight away without having to waste time on customizing things again
The setup is… antisocial
I don’t believe tmux and vim can work efficiently for pair programming (unless both developers are really used to the tools and share the same configurations).
Because you can switch context so quickly in tmux it might become very difficult to follow your train of thoughts, especially if you are working with less experienced people. In such case, do everyone a favour and switch to some neat visual editor where both of you can be equally productive.
I will definitely keep using the tools mentioned in this post as they greatly improve my workflow. I’ll also eventually step up the game with some additional plugins (I’ve been heavily considering Syntastic for vim).
The other day someone at Hacker News posted terminals are sexy curated list of terminal tools. I’m confident that I will find there couple of things that will end up in my toolbox.
What about you?
As I mentioned couple of times I’m just starting out here. Do you have any recommendations? Are there any terminal tools you cannot live without?