Improving your VIM workflow

July 17, 2021

If you’re anything like me, you strive to bring as much efficiency into your process as possible. For a while now I have been slowly migrating from VS Code to vim as my primary text editor for work and fun. At first I tried to go cold turkey, that went horribly wrong. I was lost navigating, I was confused about performing efficient file opening, I lacked easy search-and-replace without manual greps, etc. Once I’ve solved that, through plugins (and more importantly, education on how vim really works), I have found myself fighting one of the last (hopefully) battles. This time it’s about being able to pop back and forth between having the vim window open, tmux window zoom and using vim-like navigation ‘anywhere’ which in the context of this blogpsot means “in the browser, and tmux copy-view mode”.

Job management

The main problem for me was twoflod, on the treshold of managing my tmux setup and ability to switch between the editor and shell. My initial solution was to always do a good ‘ol :wq, do whatever shell business I had, and come back by means of vim ./file_to.edit. It got old pretty quickly cause now every time I quit vim, I would end up losing all my markers and buffers. My solution:

  • When I want to quickly get into the shell, I use ctrl+z in vim to suspend the process. That drops me back into shell and I can do what I need to.
  • In order to get back to vim, all I do is use fg to bring the most recently put-to-background job on the stack back. If you end up ctrl+zing too many jobs, make sure to inspect them by typing jobs and fging the one that you need. Side note: I really recommend installing tldr to look up most important invocations for many commands. I’ve just used it a few times writing this.
  • Profit. Now I can neatly and quickly jump between vim and shell, without having to deal with exiting, or using the :! command within vim.

That is all great, apart from when the shell command that you’ve just run needs some time to execute but you want to come back and keep editing your files. Worry not, there’s salvation.

Tmux zoom

This is a neat trick that I picked up from RJ. When you’ve got multiple panes within a window, you can use the C-z command to ‘zoom’ it. What it does is self-explanatory, and it basically maximizes the current pane to take up the whole window. This way you can have two panes, but for the majority of time you can work in them just as if it was one. Any attempt to navigate away from it the way you normally do will turn it off. Otherwise you can just do C-z again. Nice an quick.

Vim everywhere

It is probably a safe assumption that if you’re still reading this, you’re interested in vim enough to use it in more places than vim itself. What does it mean depends, and for most of the vim-enabled tools it means it supports vimlike navigation. My favourite tools are:

  • Vimium - the hacker’s browser is a browser extension that enables you to navigate webpages without mouse, click items, interface with the browser’s API, etc. Absolute must. As soon as you install it, try typing ? and browse the manual to see what’s possible.
  • Using vim navigation within tmux. Self-explanatory. If you’re a tmux user, you will appreciate being able to scroll, highlight, and copy with the bindings you love.
  • If you’re like me, slowly navigating away from <insert IDE of your choice> towards vim, but you don’t want to get burned, it’s great to practice navigation and other features within an environment you’re familiar with. For VSC I recommend VSCode Vim.

Closing

That’s all, folks. Thanks for reading. Happy efficient navigating!


Written by Daniel Kaczmarczyk, a software engineer and educator. you can find me on twitter or email me at daniel.kaczmarczyk@hey.com

a pale blue and yellow circle