Here you are: your first vim lesson!
First off, start vim with a named empty file:
$ vim myfile
Once you have done this, you get a screen similar to this one (I’ve removed some of the blank lines for the sake of clarity):
~
~
~
~
~
~
~
~
"myfile" [New File] 0,0-1 All
Vim opens a new empty file. At the bottom (if this option is set…) you see some information, like the name of the file, whether it is a new one created by vim, and the location of the cursor (line and character).
Now type “i” without the quotes and look at the bottom of the screen. The name of the file has disappeared and instead vim indicates it is in insert mode. From now on, what you type will be shown on the screen. Let us write something:
This is a test
~
~
~
-- INSERT -- 1,15 All
And now, write the contents and exit vim. In order to do that, we need to enter command line mode. Type “ESC” (the escape key) once or several times just to be sure until you hear “the bell”. And now type “:wq” (without the quotes) and press enter. This stands for “write” and “quit”. The “:” tells vim to go to command line mode and execute the commands (write, quit, set options, replace text, etc)
~
~
:wq
After writing the file, vim informs you how many lines and characteres were written:
~
~
"myfile" 1L, 15C written
Now, you can check the contents of the file:
$ cat myfile
This is a test
$
Though this has been a short session, the basics of a common vim session have been shown. Within the next chapters, I plan to show you more aspects of the vim editor. Till then,
Enjoy!
Add your comment below, or trackback from your own site.
Subscribe to these comments.
Be nice. Keep it clean. Stay on topic. No spam.
You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>