DEV Community

Hal Friday
Hal Friday

Posted on

Invader Vim

Every day is a new adventure in code exploration lately. I grew up using computers for their true purpose: video games. The extent of my knowledge on how to navigate a computer reached all the way from how to install a video game to how to play one. That is, until I took an interest in code about 6 months ago. Now, the computer IS the video game, and there are so many Easter eggs my basket is overflowing.

For another frame of reference, back in September I was reading through my first bit of code and it told me that I could copy and paste some stuff into my favorite text editor. So I opened Text Edit, Mac's lightweight notepad.

Master Coder

"I am a master hacker," I thought. It didn't take long to figure out that this was NOT what was meant by text editor, so I re-situated myself with a fancy new code text editor (VS Code).

These days, there are a ton of choices available for which text editor to use. Honestly, I just picked the most popular. Check out this graph from StackOverflow on 2018's top editors:

so many options

Navigating through text editors, as a super new practice for me, feels how I imagine my grandfather must have felt the first time he tried to use a keyboard. Hunt and peck, hunt and peck. Recently in my coding journey I was observing one of my instructors fly through his text editor, manipulating lines of code more quickly than anything I'd seen before. Throughout the lecture I was writing this fat list of questions down to ask him how on earth he got around so quickly -- how to pop to the front of the word? The end of the line? The end of the document? Select inside brackets? The list went on.

It turns out, all of these questions point to the same answer: Vim.

Vim was first released on November 2nd, 1991. If you notice on that graph up there, 27 years later, Vim is still the 5th most popular text editor available. In 2015, it was the 3rd. "But hang on," my brain protested, "that guy wasn't using Vim, he was using VS Code."

The solution to that mystery begins with the fact that Vim wasn't originally built for mac. Vim was built for the Amiga, the raddest looking computer of all time:

Hot

Just look at that floppy disk port. Vim was used in those days to edit your code inside of the command line in an efficient, legible manner. The setup (which works most fluidly with QWERTY keyboards but can totally be used with whatever keyboard you want) is designed to let you hop around the page without having to use the mouse. Vim has been ported for use with a ton of different devices at this point, and you can definitely use it as your primary text editor. It doesn't have all the bells and whistles you might find in a newer editor like Atom or Sublime but it does it's job and it does it damn well. Ok, so next question:

Porque no los dos?

What my instructor was doing was emulating the Vim commands with an extension in his particular text editor. According to him, most all text editors have some way of emulating Vim, because it's so OG.

I added the emulator into my own VS Code extensions, but as a tribute to my programming elders, I decided to check out the Real Deal as well. I quickly asked Google where the Internet keeps its Vim. To my surprise, Google replied,

"Look inside. It is you who has the Vim."

Apparently Vim comes pre-installed with any Unix-based OS (such as Mac OS or Linux). I felt mildly invaded by this, but it did make using it pretty simple. To get started, you just have enter your terminal and open up a file with it using the command "vim filename.ext".

Learning the Vim Basics

At first, I tried to wing it. While the advantages of being fluent in Vim are undeniable, the on-ramp for understanding what the hell is going on in Vim is a little steep without help, so I sought some tutorials instead.

The most important thing to know is that Vim has two main modes: normal and input. Normal is the navigational mode, while input acts as more of a regular typing mode. You can toggle between the two modes by using the i and esc keys. The third mode, visual mode, is used primarily for selection commands.

The following super quick tips are some key examples that you can use while you are in Vim's normal mode:

  • The h and l keys for left and right movement respectively
  • The k and j keys for up and down movement respectively
  • The w key to skip to the next word
  • The b key to skip to the previous word

There are an absolute %&$#-ton of other commands, but a bullet point hay day ain't great blog content. You can find a cheat sheet on Vim commands from this super helpful page, and you can use this interactive Vim tutorial to begin your journey into navigational masterdom.

More importantly, however, video games. You can actually play your way to Vim literacy with this stellar, throwback-style adventure game which only allows you to use Vim commands.

This little bit of history on Vim and keyboard navigation gave me a delightful wave of nostalgia and a deeper sense of understanding for what a Text Editor is and does. In reading through the articles and comments about Vim, you could really feel peoples' attachment to the program. It's easy to see how the soft spot was developed -- after 27 years, Vim has only had 8 total versions released, because it was just built so well in the first place. Now if you'll excuse me, I'm off to my VIM Adventures!

Top comments (0)