As a Computer Science student and software developer, I have always read about various tools which supposedly improve your productivity and efficiency when coding. One of them is Vim, an editor which takes a different approach to editing and writing text.
People who are Vim advocates, usually software engineers, suggest that after switching to Vim, they see an extreme increase in productivity, an increase so significant that they don’t want to go back to other editors. They smugly try to persuade you into learning Vim, because it’s so fucking great. You’re missing out if you’re not using Vim! You’re not a real programmer if you’re not using Vim!
Trying to be open-minded, I had an attempt at using Vim a couple of years ago - and failed miserably. In retrospective, my mistake was using Vim - the editor - from the beginning, and trying to do it like it has been advertised on internet by fanatics, i.e. “just spend two weeks fully concentrating on learning Vim and you’ll get passed that initial dip”.
So I began reading a tutorial on Vim and started doing exercises to learn it like a pro. Long story short, I quit after a couple of days.
Fast-forward a couple of years later, I started using PyCharm when working on my 3rd year project. One of the recommended plug-ins was IdeaVim, a Vim emulator for PyCharm. I had tried Atom with Vim, but Vim inside a proper IDE was something of a different beast.
Not only do you get the powerful refactoring capabilities and more intuitive user interface of an IDE out-of-the-box, but you also get the editing effectiveness of Vim. Because, you see, that’s the idea I understood only after a long time:
Vim is for editing, not for writing.
That is its philosophy. Most of the time, people who write a lot, e.g. programmers, writers, journalists etc, spend most of their time editing, rather than producing new material. This is what Vim has optimized for, and armed with this knowledge, you can start to appreciate its design and features more readily.
Now, why did it stick this time?
Because I didn’t force it.
I didn’t force it by completely abandoning the arrow keys
in favour of
l for moving the cursor. I
didn’t stop copy pasting with
Ctrl+V. I didn’t
stop jumping over words with
Ctrl or selecting text
Shift. No. PyCharm let me keep my old habits.
At least until I was comfortable enough to use the Vim
So that’s the beauty of JetBrain IDEs. You can easily
customize your Vim experience by overriding shortcuts.
No need to edit your
.vimrc file with arcane commands!
Every time I’ve tried to do that, I’ve given up - too
much effort for too little gain!
How to learn Vim
The trick to learning Vim is to learn a command in order to solve a pain you have when editing text. And also, try to understand its intuitive meaning. Here are a few examples to illustrate what I mean.
- I often wanted to insert at the end of
a line. In Vim, to move to the end of
the line and enter
INSERTmode, you type
A, which stands for “append”.
- Deleting an entire line can be done with
dd. Before Vim, I’d do this by pressing
endto go to the end of the line, then
Shift+Hometo select until the start of the line, then finally
Backspace. It annoyed the hell out of me that I had to press so many keys, so far away one from another.
- Deleting the word under the cursor is done with
daw, which stands for “delete a word”.
I think these three examples are enough to get you started as they provide immense benefits to your productivity and, especially, to your happiness while developing. This is, in my opinion (and other people’s opinion as well), one of the most important things to strive for.
Don’t be afraid to stick to the IDE defaults or use the IDE’s functionality if it seems easier to you. For example, I find it much faster to search and replace using PyCharm’s function, rather than using Vim regex.
Remember to identify and solve your own individual pains.
(By the way, this blog post has been edited with Vim).