Some Vim tips

I’ve been using Vim alongside VSCode (with Vim emulation) since 2015. Depending on the language involved and the amount of autocompletion provided I would prefer using VSCode instead of Vim. It was only recently that I took some time to upgrade my Vim setup – and it was completely worth it!

VSCode emulation is getting very good, and you have the option of switching between panes with vim keys. I’m still on tmux + vim because that matches my current workflow where I also keep a wiki (2nd brain) opened and also switch and zoom to other panes.

The more time I spent on Vim and learned about its features and commands, the less I was satisfied with the emulation in VSCode. The nail in the coffin was the integration with tmux, which allowed me to control multiple processes and windows without touching the mouse.

When learning Vim is very easy to hit a skill plateau and stagnate – keep in mind that there’s always room for improvement to help you save time and avoid spending energy to just edit text.

Below are some tips that were helpful for me in the past years:

Improve your typing game

I believe that this is the most important tip. The less you are using the arrow keys or the mouse, the better. Aim to completely remove their use – the transition is hard and your muscle memory will probably fight against this. As a former (bad) Starcraft player, I used to be proud of my “mouse skills” and delayed my transition to a keyboard-only workflow longer than I should have. There are many resources and videos online teaching how to properly type, use the home row and place your fingers. As time goes by and you are getting practice, you will notice that not only your typing speed improves, but that you direct less attention and energy to it.
For those that use a localized keyboard layout, consider switching to the US one – you will notice that some commands and keys will become more “natural” with this layout, notably these characters: []{}"';.

Learn how to move between windows.

With Ctrl+w then h|j|k|l you can switch the focus between windows. As a tmux user, it is also possible to use these shortcuts to switch between split panes. If you need to read a login detail, you can press ctrl+b z to make it “zoomed” (this is actually a tmux tip, not a vim one). When finished you can cancel the zoom with the same command and go back to vim.

Avoid Insert Mode as much as possible

Assume this mindset when editing files: before entering Insert mode, analyze what you need to change and which command will be the easier one to accomplish the desired change. Don’t enter Insert mode and press the arrow keys to move the cursor, as you would do with a regular text editor. When you are done, press ESC and start the process once again.
Insert mode should be used only to actually type your text – avoid moving your cursor using it.

NERDtree can also help you manage directories and files

By pressing m while the cursor is over a file or directory in NERDtree, you will present some options like that (the actual list might be different according to your OS):

(a)dd a childnode
(m)ove the current node
(d)elete the current node
(r)eveal the current node in file manager
(o)pen the current node with system editor
(q)uicklook the current node
(c)opy the current node
copy (p)ath to clipboard
(l)ist the current node
This provides nice shortcuts to commands like mv, cp and rm. Some examples of manipulations:
  • Renaming a file: mm;
  • Adding a node to a directory: ma;
  • Deleting a file: mdy;

This is especially handy when you want to remove directories and move files.

Create your own website, free on WordPress.com.Create your own website.
Start free