Vim: Introduction

Hello

Quick, look at the calendar, because today, if you are someone who spends more than 6 hours a day in front of a text editor, your life is going to change. Let me repeat that, you won't look at editing text the same way; if you manage to hang around till the end, your brain will be rewired to demand nothing less than a powerful editor like Vim.

Why Vim

There are really just 3 types of editors:

  1. Vim
  2. Emacs
  3. Everything else

Emacs is an magnificient text editor, make no mistake. If you can think of doing any transformation of text–writing code, sending emails, reading news, connecting to databases, creating websites1, taking notes–Emacs does a brilliant job. Emacs just isn't Vim2. And this essay is about Vim.

Some of Vim's niche:

  • Vim has modal interface which makes editing text and navigation extremely efficient.
  • Vim command can be composed: if you know how to delete and know how to jump n lines you can combine these two commands to delete n lines. Know how to copy and now you know how to copy n lines.
  • Omnipresence: Whether you like or not, you will encounter Vim if you are working with remote machines a lot. It is pre-installed in almost all *NIX machines.
  • Fast, not just to start up but also to use.
  • Extensible: Vim was released in 1991 based on vi, which was first released in 1976. And still according to Stack Overflow 2015 survey3 it is 3rd most popular text editor4. This is possible due to great plugins developed by individual contributors which keeps Vim competitive with newer editors.

If you are a power user of any other text editor-like Sublime, Notepad++, atom-and you feel you do not need to learn anything new, that's okay, you are better off spending your time in something else. You may want to read on if you want to know just a few commands to make peace with Vim while sshing, or maybe want to hang around to see what the hype about. There just a sincere request, please do not judge Vim based on emulation done by other editors5. All the Vim emulation that I have used, except for Evil mode in Emacs, simply suck. Besides, Vim is much more than the keyboard bindings.

Dive In, head first

Installation

There is a very good chance that Vim is pre-installed on your system, so head over to your terminal and hit vim. Unless you have already played around with .vimrc, you will be greeted with a black (or any other solid color), dull splash screen which may force you to think that Vim was indeed made in 1991 and wasn't updated after that, except for a few bug fixes. Don't worry about it just yet, you can make your Vim look like any of these quite easily.

If you are using Windows, there are two simple options. The first one includes wiping your OS and installing Linux, if that is not possible then I would recommend installing gvim.

Lesson 0

You can quit Vim using :q
yes, you need to press : too.

:q is short form for :quit, just like :w is short form for :write (writing a file is same as saving a file).

Lesson 1

Vim is our friend, it tries to save us from doing silly things like editing and then writing a file which was meant to be readonly or quitting without saving a file. But sometimes we do want to quit without saving because we want to discard the changes. In such cases, append ! in front command to tell Vim that you know what you are doing.

Append ! to override Vim.

Thus you can type in :q! to discard the changes in the current file and quit or :w! to write a readonly file6

And that's it, you now know how to open Vim and close it. If you wondering if your life has really changed, it's probably not, yet. But now, at least you are a little less intimidated and know how to make your beast sit. Learning Vim takes time, like all the good things in life.

Click here for part 2

Footnotes:

1

In fact, this website is build using Emacs. Emacs Rocks.

2

but it does a very good job in enacting Vim: Evil Mode

4

slipping to 4th position in 2016 in Development Environments which isn't actually text editor segment

5

Trying Vintage mode in Sublime doesn't count as trying Vim.

6

This will only succeed if Vim has permission to write the file on disk.

Creative Commons License

Date: 2017-05-28

Author: Anurag Peshne

Emacs 25.2.2 (Org mode 9.1.14)

Validate