Writing text is probably one of the most versatile and productive things you can do with computing devices. I mean, think about it:

  • Throw thoughts, knowledge, and random ideas into text files.
  • Emails, DMs, comments, posts - we communicate mostly through text - and memes, ofc.
  • Write Documents, reports, novels
  • Code up computer programs and make a computer do whatever you want
  • Blog posts to screenplays - text does it all

What’s Vim then?#

TLDR: It’s a text editor.

But really, it’s kinda like flying a helicopter to go grocery shopping. If you think that’s cool, then you’re just being nuts. Have you ever tried flying a helicopter before?

So, in order to write some text, you have to learn to fly a helicopter first (I apologize to people who actually know how to fly a helicopter). But once you do learn it, then you can brag about it to all your friends. They won’t care a single bit. Well, it’s they who’ll still be getting stuck in traffic jams.

Install Vim#

  • If you’re on Linux, just use your package manager to install Vim
  • MacOS: Probably already installed, idk
  • Windows: Switch to a real operating system! If you insist on using it, then go to Vim website, download it and install it.

Vim is a terminal/cli program,

Taking off#

Open your terminal (or CMD I guess) and start Vim with vim.

Let’s now exit Vim right away before doing anything else, I won’t explain why this is important. To exit just type :q and press Enter.

Congrats, you’ve already managed to take off and land. Let’s try doing some flying now. Take off again by typing vim again.

Vim modes#

If you run Vim and try to start typing shit, you’ll quickly notice it doesn’t quite work as expected. You might get some text printed on the screen, though. Before we start typing we need to understand what Vim modes are. In simple terms, it’s different “states” that this text editor can be in. You’re able to do different things depending on which state you’re in. This will make more sense shortly, but let’s take a look what states we’re gonna be dealing with:

  • Normal mode
  • Insert mode
  • Visual mode
  • Command mode

The editor is going to let us know which mode we’re in by writing it out on the bottom left corner. For instance, insert mode would be -- INSERT --. Normal mode won’t have anything written there.

There are some other modes which are not important for now. Let’s check each one.

Normal mode#

This is the default mode when you first enter Vim. As already mentioned, if you just start typing away you might get weird results. This mode allows you to quickly navigate through text, perform operations like copy/pasting, etc.

Insert mode#

This mode allows you to write text as you would normally expect from any other text editor.

Visual mode#

It’s basically selecting parts of the text. Like you can select some text with your mouse.

Command mode#

Issue commands like save file, or quit as we’ve already done with :q, and tons of othr stuff.

Write text#

You’ve got Vim running now, let’s write some text.

We first have to switch to insert mode. To do that, just press i on the keyboard. This will switch the editor into insert mode. We can now see -- INSERT -- being shown on the bottom left corner. Type some text now. Once done, exit the insert mode by pressing Escape key. This brings us back to normal mode.

Let’s now save this as a new file called useless.txt. We can now enter the command mode by typing :, this brings us into command mode and we can see : printed out on the bottom left corner. To save the file, we have to do :w <filename> so that’d be :w useless.txt, then press enter. The file should be written to the disk now. We can then quit again by doing :q. You can do both write and quit at the same time by doing :wq.

Let’s now open our newly created file again by doing vim useless.txt.

Congrats, now you know how to write text files with Vim.

Motions#

Vim has a concept of motions, which allows you to navigate the text really quick and also perform operations on those motions.

The simplest ones are just left down up right. In normal mode you can move the cursor with h, j, k, l - or use arrows.

There are many many more ways to move around. For instane, if you type w you’ll position your cursor to the start of the next word or W which will do the same but ignore punctuation. Do b for reverse. Use f to find the next character and move there, for example f. will move you to the next fullstop, F for reverse.

You can prepend these motions with typing a number, for instance 2f. will move you to the second fullstop from your current position. Or if you do 5k you’ll move 5 lines up instead of one.

There are some actions you can apply to the motions, for instance, if you want to delete everything after the cursor until the end of the line, you can do d$. $ is a motion that moves you to the end of the line (0 goes to the start), and d deletes stuff basically. You can do dd which will delete the whole line of text.

Some of more useful stuff, especially for programming are “change around” and “change between” operations. For instance, you can do ci", which translates to change inside “”. This will delete everything between "" and throw you into insert mode. That way you can make a change in a fraction of a second, how cool is that? ca" does the same but gets rid of quotes as well.

If you enter visual mode with v, you can select text from your current position to wherever with these same motions. Once selected, you can then copy the text using y (in vim copying is essentially named yanking or yank) or cut using x and then paste somewhere using p.

One useful shorthand to duplicate a whole line is yyp, where yy yanks the whole line and pastes it straight away.

Undo changes with u, redo with Ctrl + r.

There’s too many to list out and too many combinations to write about.

Why would anyone do this#

Yeah, I know, why? And the learning curve starts to pick up too. I’m not gonna go into depths of Vim, the rabbit hole goes deep. But Vim is a very powerful tool that allows advanced text manipulations. You can get much faster with practice and developing muscle memory, and much much faster and precise with text manipulation compared to any other tool out there. And best of all, it takes a fraction of computer resources out of almost all other text editors out there.

For me, I use Vim for all my programming needs, note taking, writing email drafts, configuring config files over SSH, and even creating invoices.

Other cool Vim things#

Not only does Vim allow you to manipulate text in a crazy manner, it also allows for extensible configuration. You can define your own combinations of motions and actions and create your own macros. You can record the macros and repeat them. With cleverly defined macros, you can reformat and transform hundreds of lines of text in seconds.

Neovim#

There’s an alternative version of Vim called Neovim which retains all the same functionality as standard Vim but allows programming it through Lua and creating plugins. These plugins can manipulate how Neovim works and looks, everything from file navigation, to code highlighting and syntax checking, running tests, connecting to SSH endpoints, nowadays even chatting with AI LLMs and letting it do the code changes for you. I mean, just look at this good looking shit: https://nvchad.com/ - who needs VS Code anyways?

This article was written with Neovim :)