Photo by
Alex Knight
on
Unsplash |
So, now that you installed Vim on your Mac, Windows or Linux workstation, let's review what's next and how to get started with Vim.
Getting started with Vim
The first thing you should understand about Vim is its modes. Vim is not a traditional editor in which you simply type your stuff by using the keys of your keyboard and move you cursor using the mouse and the arrow keys. Vim is way, waaaaaay more than that. And it's exactly because of that that we ๐งก it.
But why get to the theory before we can use Vim? Because it's important to understand it so you can exit it safely ๐.
Vim Modes
We'll keep this straightforward and for simplification, we want you to understand the two modes you will first meet in Vim:
- Normal mode: the default mode. This is where you usually enter your commands or move your cursor
- Insert mode: the mode you type stuff. Equivalent to most text editors.
Starting Vim
This is what you should see:
Scary? Maybe. So let's quickly analyze the above, shall we? There are interesting things there that tell us a lot already about Vim:
- VIM means Vi IMproved. Vi was a text editor originally written by Bill Joy from which Vim is inspired from
- Our version: 8.1.2269
- Bram Moolenaar, Vim's author
- Some commands, including how to quit Vim (yay!) ๐
Typing Text
If you started a text editor, you probably want to type some text. As
previously said, this is our first second contact with modes.
You know already that we're in normal mode and you want to go to
insert mode so you can write your text. The simple way to switch
to insert mode is by typing i. A -- INSERT -- message will
show up on the status bar indicating that you're now in insert mode. Go
ahead and type your stuff. We'll type "Hello Vim4Us!":
From here we may want to save our file or exit discarding the changes. Let's see how to do both.
Saving our file and quitting Vim
The first thing we should do in order to save our file is leaving insert mode and going back to normal mode. Going to normal mode is as simple as pressing <Esc>. Once you press it, you'll realize that the -- INSERT -- label disappears from the status.
To save our file as hello.txt, now type in normal mode:
And exit with:
Exiting Vim discarding the changes
If however you want to discard your changes and thought that using the same :q command would work, you're wrong. This is what you would get:
But why? Because the :q command tells Vim to quit. But Vim on the other hand is helping us and alerts us that we have unsaved changes. To confirm that we want to exit and lose changes we then have to use the ! operator. The ! operator tells Vim to override the command and execute it regardless of the effect it would have.
So to quit Vim ignoring changes, type in normal mode:
Next Steps
Now that you understand the first two basic modes in Vim and knows how to change modes and run some commands in Vim, we suggest that you start your first Vim tutorial. But we'll cover that in a future post.