Every programmer starts a new language by writing hello world, and as you’ll see, Vim is a small DSL for text editing. So, here goes.
On the command line, tell Vim you want to create a new text document called
hello_world.txt. Note, there are some great
grapical Vim clients if you’re not a fan of
working on the command line.
$ vim hello_world.txt
Once you’re in vim, tell it you want to insert some text into this file
Now, insert some text.
Tell Vim you’re done inserting.
Tell vim you want to write the file out to disk and then quit.
Congratulations, you’ve just written “hello world” in Vim. The “write and quit”
command will work in any Vim, even when you’re
ssh’d into a remote
Things are even easier on the
grapical Vim clients though. Instead of
:wq you could have just hit your standard save and
quit key combos. On macOS that would be
⌘+q. You don’t even have to
Insert mode to save with
Vim’s got a lot of wordy commands, like
:quit, but almost
all of them have shorter variants. The alternatives for
:q Because this is such a common thing to do Vim’s got a
combo command for doing both.
Sooner or later you’ll find a post online with a strange combination of
letters that you aren’t familiar with like
:nohl. People like to use the
really short, and obscure variants, even in their config files. I encourage
you to look them up in Vim’s help docs where you can see the
expanded forms and learn what they do.