Learn to Code via Tutorials on Repl.it!

← Back to all posts
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!

Commentshotnewtop
Highwayman (1367)

The first time I opened vim I spent like literally 10 min just writing garbage in insert mode bc I had no idea that normal mode even existed XD I was just

:wq
:q
:x
:fgjotfjkwosoxksbuwpqpqpqdkdbshisjssjheeeeellllppppmeeeeee
Highwayman (1367)

YEAS!!

Happy 😊
he coming soon.... lol

HahaYes (1052)

Nice! I really like this!

CodeLongAndPros (963)

@HahaYes Thanks! Btw, you have the same number of cycles as the LV-909 “terrier”

HahaYes (1052)

@CodeLongAndPros hey codelong, do you want to work on are node.js project?

CodeLongAndPros (963)

@HahaYes Idk, what is it? (Btw, I've never used Node.)

CodeLongAndPros (963)

@HahaYes I can try, but it won't be pretty.

HahaYes (1052)

@CodeLongAndPros alright, will send you link, but you must promise not to share it.

Highwayman (1367)

What stuff won’t work on replit?

CodeLongAndPros (963)

@Highwayman It's one of the limitations of web apps. But you can just replace C- with S- in my autocmds part.

Highwayman (1367)

@CodeLongAndPros hum ok. I’ll have to study that carefully for a bit lol

DynamicSquid (2673)

I heard that Vim is old style, so I prefer VSCode.

DynamicSquid (2673)

@CodeLongAndPros like, isn't Vim a little old school?

Highwayman (1367)

@DynamicSquid isn’t c++ a little old school?

DynamicSquid (2673)

@Highwayman you got me there

but C++ is still relavent, it's not being replaced by newer languages, but with Vim, newer modern text editors are taking it's place, right?

Highwayman (1367)

@DynamicSquid nope. Vim still is a very powerful thing. Vim is like the C++ of text editors. It could be viewed as old and “outdated” I guess, but only in the same way one would view the cli as old or outdated. It’s still being updated and everything and it’s loterally everywhere.

Hm I’m sorry if I’m being rude :/

DynamicSquid (2673)

@Highwayman oh, I see... but does it offer any advantages over modern text editors like VSCode?

and of course not, you're not being rude :)

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.

Highwayman (1367)

@DynamicSquid yes, it does. I don’t know all of the advantages bc I have a very rough knowledge of vim, but yeah it definitely does. Take @CodeLongAndPros editor pics, they show a completely customized editor. That’s a big thing ppl like from editors like atom. Another: configuring commands with the map command. Another: autogroups. Another: um.. idk there’s more. Lol. Point is there is t much that vim doesn’t already have that other editors have, in addition to stuff that nothing but maybe the vi editor has. In addition it has its own lang, so you can see where that goes. Infinite innovation and customization.

Yay!

Highwayman (1367)

@CodeLongAndPros lol I just noticed you had answered! I kinda barged in there didn’t I? 😬😆

CodeLongAndPros (963)

@Highwayman I’ve just installed powerline, haven’t done anything else with it.

CodeLongAndPros (963)

@Highwayman It’s because you don’t reply to messages, just append to a thread.

Highwayman (1367)

@CodeLongAndPros ... I’m sorry I followed the Xkcd link and went down a rabbit hole 😬 what exactly do you mean by append to thread, but don’t reply to messages? Isn’t it the same thing? Or wait like I’m just replying other ppl’s stuff and not my own? Am I even close to what your talking about? I’m lost :(

CodeLongAndPros (963)

@Highwayman So if I make a comment on a post, it looks like this:

Post
|
|-> Comment

If you reply to that comment:

Post
|
|- Comment
|     |- Sub_comment

But if you reply to sub_comment:

Post
|
|- Comment
|     |- Sub_comment
|     |- Actually replying to sub_comment.
(Should be):"
         |- Actually replying to sub-comment.
Highwayman (1367)

@CodeLongAndPros agh gd phone won’t fit the diagram, but I think I get it. Isn’t that just not possible on replit tho?

CodeLongAndPros (963)

@Highwayman Nope, not possible to have sub-sub-threads.

Highwayman (1367)

@CodeLongAndPros Ok, so then from what I have gathered, you are saying:
I did not notice your comment because I am a visitor to this thread and am simply appending to it, so I don’t get notifications for comments because I do not “own” the thread upon which I am commenting..?

CodeLongAndPros (963)

@Highwayman No, it’s just hard to have 3 people talking about different things on one sub-thread

Highwayman (1367)

@CodeLongAndPros oh. Lol! Ye I see what you mean.