Vim. Three letters that strike fear in the hearts of millions. By chance, I stumbled upon Vim (Vi-Improved) a couple of months ago. It was love at first sight. I proceeded to devour every article I could find on the mythical beast. This post is the advice I wish I would have found in an article when I was first starting out.
# Build Your Own .vimrc
At first, I started out by downloading one of the pre-configured Vim distrosâââthe Ultimate Configuration. It was exciting, but I didnât have the first idea how to do anything. I had a tricked out machine gun, but didnât have the slightest clue on how to take off the safety. This seems to be a common problem when starting out with someone elseâs configuration. So, while intimidating, it is recommended to start from scratch. The best way to get up and running is to follow this guide. It will coach you through setting up your initial configuration. One of the cooler aspects of this process is that youâll start to understand how personal your config is. Your .vimrc, or init.vimâââfor Neovimmers, really becomes and extension of who you are as a programmer. It will reflect what you care about and how you spend your time. The journey of going from 50 lines to 500, or 5,000, is riveting. Plus, it is one of the best ways to help yourself grok Vim, both in philosophy and usage.
# Relative Numbers
This tip was the initial catalyst in understanding Vimâs value proposition. Before relative numbers I was hulk smashing jjjjjjjjjjjjjj and kkkkkkkkkk like a possessed loon. Clearly, missing the point of Vim. Then I uncovered a post that outlined the benefit of relative numbers. I was intrigued, so I set it up in my .vimrc and started cooking.
Immediately it made a profound difference. I started to be able to jump efficiently. This is a fairly common process in Vim: do something like a caveman, then learn the 007 method. At this point, you should continue on and read this holy text.
# f &Â F
While my vertical precision was improving, my horizontal movements were still barbaric. Llllllll, hhhhhhhh. Not the ideal method of transport across long lines. I learned about w and b, which, while convenient, still led to a lot of wwwww and bbbbbbbâs. It wasnât until I uncovered the f & F command that I made headway. In essence, f & F can be thought of as find. Lower case f will search forward, while F searches backward. Either case will position your cursor on the character in question. If you desire a placement right before a character use t & T. These two simple keys are impressively dynamic. For instance, dfs, which will delete everything until Vim finds the next occurrence of s.
# c
At this point, I was starting to get my feet under me. I could navigate up, down and left, right with ease. One of the next major keys in furthering my development was c. This key analogizes to change.
cwâââchange to next word
ccâââchange entire line
ceâââchange from cursor to end of word
c$âââchange to end of line
ciââââchange inside double quotes
caââââchange around double quotes
cfxâââchange until next found occurrence of x
While powerful, this key gains further might when paired with targets.vim.
wellle/targets.vim_targets.vim - Vim plugin that provides additional text objects_github.com
# Remap Caps Lock ->Â CTRL
At first, this seems preposterous. Youâll now have to hold shift anytime you want an uppercase letter, but this remapping is more practical than it appears. The control key lies at the heart of numerous operations within Vim.
CTRL + (insert key)
vâââvisual block mode
wâââwindow adjustments
râââredo
bâââback one full screen
fâââforward one full screen
dâââforward half screen
uâââback half screen
[âââbuilt in <esc> mapping
Hopefully, youâre starting to get the picture. Often times, people will remap CTRL to ESC for alternating back to Normal mode. While logical, it doesnât appear to be the optimal solution. This becomes quite evident once CTRL-[ becomes second nature for escaping modes. Furthermore, CTRL plays a large part in Vimâs built-in completion methods. It will feel awkward at first, but with repeated use will become engrained.
# Plugins Arenât The Solution
Out of the box, Vim seems like a deserted wasteland, so it makes sense that youâll need to give it wings to soar. This notion makes sense until you learn the dark truth.
Want a file explorer? Type :Sex. Remove all trailing spaces? Try :%s/\s\+$//e. The list goes on and on. Itâll seem mystifying, but most plugins arenât nearly as useful as they appear. This isnât to say that all plugins are bad. There are certainly some that are worth their weight in gold. Iâm quite fond of Nvim-R myself, but remain wary. In general, look for solutions to your problems via Vim itself. This can be done with a quick :help âyour query hereâ within Vim. This process will save you a variety of headaches, while getting yourself further acquainted with the internal docs.
For a complete PDF of Vimâs legendary help navigate here.
# Keep It Vanilla
Vim tends to lead to heavy customization. This isnât necessarily bad, but can bite you in the end. For me the moment came when trying to use Vim keybindings within R Studio. I had become so dependent on all my mappings and shortcuts that my skills were nonexistent. Sure, using H and L instead 0 and $ is more convenient, but this misses the point. The value of Vim lies in the language. Once you master vanilla Vim youâve gained a lifelong skill. One that will diminish in value with each custom mapping you set in your config. This isnât to say avoid them at all costs, but more a friendly warning.
# Bonus Section
- Powerline, Airline, Lightline: Theyâre certainly visually appealing, but largely useless. Plus, making your own statusline is fun and a great introduction to Vim scripting. Look here and here to get started.
- Getting use to J & K: One way to tackle this transition is to use Vim keybindings in your browser of choice. Vimium for Chrome and Vimmy for Safari.
- Learn from the masters: https://www.reddit.com/r/vim/
- Watch and learn: youtube
- Good books: Practical Vim + Mastering Vim Quickly
- If all else fails
- Read about Vimâs hidden jumping feature ->