How to use Vim, part I
h
CodeLongAndPros (963)

Vim for dummies, part I

A few days ago, @CodeLongAndPros received an anonymous tip, through his penguin minions, to write a tutorial about Vim. He will also stop talking about himself in the third person.

So, here goes!

Vim is a modal editor.

If you type dd in VSCode, dd appears.

But in Vim, you'll delete a line.

This is because Vim has 5 modes. (You'll only use three 90% of the time). They are:

  • normal
  • insert
  • replace
  • last-line
  • ex

Setup.

You'll have two options:

If you go to my repl, keep in mind a lot of stuff, fun stuff, won't work.

If you use Linux you can do:

sudo pacman/apt/emerge/ynm/dnf install/-Syu/-a vim

If you use Micro$oft's trash, you can use GVim

After you've installed Vim, summon it with $ vim ~/.vimrc

For NT, look at this.

From hereon out, I won't support NT. You're on your own.

When you invoke Vim, you'll see this:


Btw, the status bar at the bottom is custom.

Your's may or may not look like mine, but it'll be generally the same.

How to read my commands

If you see some nonsense like ggVGd, enter it as you see it

However, if you see someting in brackets, without a \ before it, do what it says:

<ESC>: Press esc
<CR>: Press enter
<F5>: Press f5

How to type

Please enter cat in your Vim window.
Nothing should happen.

Now, enter iHello world<ESC>

You should see this:

You have the text Hello world

Please enter the char : in normal mode. You should see this:

Add w foo.txt.

Final command:

Press enter.

Congrats! You just saved a file!

Exiting Vim

This one's a doozy.

Most people joke about quitting Vim:

There are a couple ways:
You can do :wq to exit + save, :q! to exit and not save

You can do :x in place of :wq.

You can also do ZZ to s + q and ZQ to q.

Got it?

Homework

Make a text program containing the dialog of Xkcd #149 and save it.

Part II will come out soon!

You are viewing a single comment. View All
CodeLongAndPros (963)

@DynamicSquid Saying Vim is old school is like saying Windows is old school because it has stuff from DOS.

And, yes, it does. Try using it after parts II and III. Life changing.