How I learned VIM and flexed in front of other developers

A human friendly way to learn VIM

M. Hammad Hassan
10 min readOct 20, 2023

I would assume that you are here because you wanted to flex too. Honestly, which programmer doesn’t? 😁

At work, I mostly use Ubuntu and since it is not as GUI friendly as Windows, it softly forces us to use the terminal.

I used Nano before, but VIM is supposed to make lives easier for us … or so I thought. The operations I can do with VIM overwhelmed me within a few minutes of reading them on a cheat sheet.

So this is me explaining the way I learned VIM in an efficient way which not only made things easier for me to digest but allowed me to master VIM within a week (almost).

📌 In case you are new to all this, just know that the things you can do with GUI is only a minor subset of what you can do from within the terminal

An absolute Giga-chad who uses his VIM skills to flex on every developer he sees. Quite a rare specie indeed.

Prerequisites

First of all, know that you should not worry if you are starting from scratch, because I have explained everything with newbies in mind.

Second of all, remember that I already said that I have been using Ubuntu for a while, and I am an adept user of the terminal it offers. So in a nutshell I didn’t start from scratch, therefore know that it might take you more than a week to fully understand what is going on. But even so, I will try my best to break it down as much as possible.

📌 It is completely fine if you don’t have VIM installed. You can use it online inside your browser. Go to https://www.vimonlineeditor.com/ for practice without the hassle of setting things up.

With that out of the way, it is better (but not necessary) for you to know the Basic terminal commands like navigation, file creation etc.

But there happens to be one thing that you must have before you start reading onward, that is, patience at its optimum level.

📌 I will exclusively use Linux commands for the actions outside of Vim, such as file creation and listing directory items.

Day 1: How I Began …

You already know that reading the cheat sheet didn’t do any good to me in the first attempt. So I decided to watch some tutorials from YouTube. A daring move indeed.

But as soon I finished the video, I got back to doing my own things, and then after a while in the same day, I returned to do some skill check. More than 70% of the mind-twitching knowledge had escaped from my ear holes … Crap!

Then, after the two failed attempts I mentioned earlier, I said to myself: “I think sticking to ONLY the basics will surely help me get a fair ground.” which is indeed the case with most technologies I or anyone else who starts to learn it.

But then another problem stood before me. What basics exactly? There is still a lot to cover in the basics itself like editing modes, navigation, and common commands etc. I am a working person with a day job, if I had to sacrifice my time learning how to flex in front of other developers, I had to make that sacrifice count.

So I started with the editing modes. It took me about 10 mins hardly to review the concept since I had been watching tutorials before. You might take longer, but no more than 20 mins at max, I guess.

  • To activate the Insert Mode type i or a.
  • To activate the Visual Mode type v.
  • To activate Command Mode type :.

📌 I’m using the term “editing modes” as a comprehensive label for all the modes that VIM has.

Also note that there are more editing modes that VIM offers, but these are enough for the basic usage I was looking forward to.

Then I focused on my use case. Well, my job included to work with remote servers and maintain them, and I used the terminal for that. The most frequent activity I did was to open a file (which is located up on the server) and make some changes to it. After I was finished, I would “Save” and then “exit” the Nano editor.

This is exactly what I started with, but using VIM this time.

That is it! You can check the contents of the file using cat <file_name> command and see if the changes were made or not.

You should know that I did not go for any shortcuts of navigation. I simply learned how to edit and save a file and be done with it. This went extensively for about 1 and a half day. Hey, I was at least starting to use VIM, so I had no complaints.

I also avoided switching into other editing modes, which would force me to go into scenarios I hadn’t prepared for.

The key is to learn small groups of commands and for very specific use-cases at first. This will ensure enough time for muscle memory … 😏 … to build up.

And this is how I got started …

📌 Know that each day I would only practice the new shortcuts that I had learned and in the specific use case it was meant for, while using the previous ones that I had learned before.

Day 2: Learning Basic Navigation

To be honest, I was confused whether I should learn to “copy and paste” or “navigation” first. But in VIM, I could paste just fine, since ctrl+shift+v worked in the normal mode, but this was for pasting whole lines only. The same could not be said for ctrl+shift+c which is not a standard VIM command.

It’s up to you which path you want to take. My circumstances, dictated me to learn navigation first. Since analyzing the contents of a file is what I did most of the time.

You can still use the classic home and end button to jump to either extremes of a line. Even the ctrl+arrow_left or ctrl+arrow_right will skip the words, just as in any normal text editor. So it is a nice thing to have if you have been using these before.

📌 You can also perform scrolling operation using the mouse wheel.

Day 3: Other Basic Necessities

It was time that I took my pace up a notch. This time I went for copy, paste and delete commands as well as undo and redo. These are all the staple operations we should be able to do in a regular text editor.

With this, I could finish doing the basic stuff and move onto more advanced ones.

📌 You may notice that I am only listing out a very carefully selected set of commands to learn. This is to prevent myself from being distracted by too many commands.

Day 4: Search, Replace & Working With Tabs

At this point, I knew how to navigate and perform meaningful tasks. But in order to flex, we need to be “fancy”, and that “fancy” comes with learning the command mode.

In the command mode, you may want to start with search and replace because it is more of a necessity than the tabs.

Although using regex alone would elevate us to heavenly heights, but working with tabs will make it look like that we know a thing or two about VIM, if not all. Therefore, I only selected some of the very essential commands related to tabs as well.

📌 You may notice that the number of commands I learnt each day is gradually increasing. This is because with each passing day I was getting more and more comfortable with using VIM.

Day 5: Marks & Positions

Marking is just like bookmarks for your cursor. A simple flow of this would be like you mark an if...else statement (say on line 32) that you were working on and suddenly switched over to another function in your code (say on line 10) to copy its name.

Now instead of navigating back to the if...else statement using the navigation tools I showed you earlier, you could just use the marking shortcut to jump back on line 32 and on that specific character that you marked. Pretty neat huh?

Although there are some predefined marks present in VIM environment that you can use but in case you want to mark (or overwrite a mark) a specific location in your text file, you can save that as a bookmark by typing m in the Normal Mode and the letter you want to use as a bookmark.

That letter will now act as a trigger to jump back to the specific point in the text file that you marked.

Note that it will not work with characters with length of 2 or more. But it can work with single digit numbers.

By this time, I had almost left Nano for VIM. But I felt a desperate need for the “go to line number” feature, which I previously used in Nano. So I included that in my Day 5 lesson as well.

If you are not able to see line numbers in your VIM editor, you should run :set number as a VIM command.

📌 To jump to a mark you can either use a backtick (`) or an apostrophe (‘)

Day 6: DIFF

Ok, so now we are looking fancy with all those keyboard shortcuts. What’s next? … Work on leveling up of course.

For this I planned to do Diff which stands for difference. It is a VIM mode which enables us to compare two files line-by-line. Text files in this mode look like this:

Sample diff-mode view from inside a terminal

You are not only able to see the differences in both files, but you can also change the contents of both files, either manually typing it or borrowing it from the neighbor file.

Folds are basically when you hide the contents of a block of code by merging them into one line. If you have used any IDE before, you would know what I’m talking about.

Commands to shift changes basically rely on your cursor being inside one of the two files. For the sake of simplicity, I will call the file in which the cursor is present as “Current Buffer” and the file in which the cursor is not present as “Adjacent Buffer”.

diffput command captures the changes in the Current Buffer (from where your cursor stands) and replaces the text in the Adjacent Buffer with it (in the same line number)

diffget is similar, but instead of putting the changes into the Adjacent Buffer, it gets and replaces the text in the Current Buffer.

Sometimes when you undo after doing changes in the files, the highlighting will not be present anymore, although the changes are back to normal. To fix this, you will need diffupdate to do a fresh scan of the two files for differences.

To be honest, it was like using tmux. I think I’ll do a similar blog post on tmux as well if people loved this one.

Day 7: Registers

Registers are your typical clipboard, but the difference is that it can hold several copied texts at once.

Yes! It is super useful.

There are 2 types of register commands here. One which copy/paste within the editor, and one which copy/paste outside the editor. Both of them are no doubt useful.

Apart from your custom registers, there are some predefined registers which keep track of all the generic stuff, as can be seen below:

You will encounter the word “yank” several times in the VIM cheatsheet. It is used as an equivalent to “copy” (don’t ask me why though).

Similarly, “delete” here refers to the “cut” operation we are so fond of.

Final Word

This concluded my 7-day sprint of practicing VIM. Of course, there are lots of other commands which I haven’t covered yet. And I didn’t plan on doing so in one go.

But what I had covered in these 7 days, allowed to me to perform most of my daily routine tasks without the need for looking up the cheat sheet before typing every command. That fluency in keystrokes alone is enough to flex like an absolute Chad in front of other developers.

But do you know what can level you up to a Giga Chad? … Learning Macros.

So you have 2 choices now. Either you can learn more commands related to the exercises I showed you above, or you can further expand your horizons by delving into new topics such as Macros. In both the cases, there is plenty to learn.

But before you further your efforts mindlessly, I must implore you to plan small chunks of practice commands and stick to them for a whole day or two.

The only thing making VIM difficult is its plethora of commands and its unconventional shortcuts.

Thank you for reading till the end 🥳

Now you are ready to flex. Be sure to do it on every other developer you see. No one escapes your character … 😏

If you found this article helpful and learned something new, be sure to leave a 👏 or let me know your thoughts 📣on it. I’d love to listen to your feedback.

--

--

M. Hammad Hassan

Hey there! I'm a Data Scientist and a Full Stack Developer.