Skip to content
Sign upLog in
← Back to Community

How to use Vim, part I

Profile icon
CodeLongAndPros

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:

Default vim


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:
hello

You have the text Hello world

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

Add w foo.txt.

Final command:
final

Press enter.

Congrats! You just saved a file!

Exiting Vim

This one's a doozy.

Most people joke about quitting Vim:

Cannot infer image mime type

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!

Voters
Profile icon
StepanChelyshev
Profile icon
programmeruser
Profile icon
jnesis
Profile icon
HahaYes
Profile icon
Highwayman
Profile icon
DynamicSquid
Profile icon
CodeLongAndPros
Comments
hotnewtop
Profile icon
Highwayman

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
Profile icon
Highwayman

YEAS!!

Happy 😊
he coming soon.... lol

Profile icon
jackyliu16

emm, i'm a developer which like to using vim, could you recommend a online ide which support this ?
i have try rust playground but it wasn't support interaction

Profile icon
HahaYes

Nice! I really like this!

Profile icon
CodeLongAndPros

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

Profile icon
HahaYes

@CodeLongAndPros
noice

Profile icon
CodeLongAndPros

@HahaYes
Darn, you incd

Profile icon
HahaYes

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

Profile icon
CodeLongAndPros

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

Profile icon
HahaYes

@CodeLongAndPros
it is a realtime chat

Profile icon
CodeLongAndPros

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

Profile icon
HahaYes

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

Profile icon
Highwayman

What stuff won’t work on replit?

Profile icon
CodeLongAndPros

@Highwayman
Ctrl input and meta key.

Profile icon
Highwayman

@CodeLongAndPros
oh alright. Ty

Profile icon
CodeLongAndPros

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

Profile icon
Highwayman

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

Profile icon
DynamicSquid

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

Profile icon
CodeLongAndPros

@DynamicSquid
Wdym?

Profile icon
DynamicSquid

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

Profile icon
Highwayman

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

Profile icon
DynamicSquid

@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?

Profile icon
Highwayman

@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 :/

Profile icon
DynamicSquid

@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 :)

Profile icon
CodeLongAndPros

@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.

Profile icon
Highwayman

@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!

Profile icon
DynamicSquid

@Highwayman
oh, I see

Profile icon
Highwayman

@DynamicSquid
👍 :)

Profile icon
Highwayman

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

Profile icon
CodeLongAndPros

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

Profile icon
CodeLongAndPros

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

Profile icon
Highwayman

@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 :(

Profile icon
CodeLongAndPros

@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.
Profile icon
Highwayman

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

Profile icon
CodeLongAndPros

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

Profile icon
Highwayman

@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..?

Profile icon
CodeLongAndPros

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

Profile icon
Highwayman

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