Probably, the most important action to do with a text editor is inserting text. Vim makes this task very easy and powerful at the same time.
Before we start, let us specify some symbolic conventions:
- I will use ESC and ENTER to refer to the escape and ENTER keys respectively
- All the keys you are expected to press without producing any output on the screen will be in boldface. Example: ESC i means you have to press escape and then i, i being a command that does not produce any output
Let us start with vim:
$ vim test.txt
The simplest way of inserting test is using i
iThis is a first line of my document.ENTER
And this is the second line.ESC
~
~
~
~
~
~
2,28 All
The bottom line indicates the position of the cursor (second line,twenty-eighth (mejor con dash) column).
Now, we can use the O command to insert a new line before the current one:
This is a first line of my document.
This is the 1.5th line :)
And this is the second line.O
~
~
~
~
~
~
-- INSERT -- 2,26 All
First we type the command and then, we are in inserting mode in the line above the current one.
The o command does the same thing with the line after the current one. Let us say the cursor is at the beginning of the last line.
This is a first line of my document.
This is the 1.5th line :)
oAnd this is the second line.
After typing the command, we can write in this line.
~
~
Let us imagine the following file content:
iThis is a simple lineESC
~
~
1,21 All
Now we can use the I command to insert text (the Hello word) at the beginning of the current line:
Hello.This is a simple lineI
~
~
-- INSERT -- 1,7 All
Two more similar commands are a and A to insert text immediately after the cursor and at the end of the line respectively.
The last command we are going to see is executed in command line mode. We can enter this mode typing ESC: (notice the colon, which gets written on the command line)
~
~
:r some_file
The r command tells vi to read the file some_file and insert the content into the buffer (so you can see it).
This is a test.
~
~
"some_file" 1L, 16C 2,1 All
The This is a test. sentence was read from file some_file and inserted into your document.
There are more inserting commands, but this is not intended to be an in-depth tutorial. The ones I have presented so far are enough for you to get by with vi. My advice: give vi a try, use it and practice with these commands.
At the bottom of these articles, I will try to write a small sheet with a brief resume.
Enjoy!
Vim Sheet (I)
- i – Insert text at the current cursor position
- I – Insert text at the beginning of the line
- o – open a new blank line below the current one
- O – The same thing with the line above the current one
- a – Insert text at the next column position
- A – Insert text at the end of the line
- ESC:r file_name – reads and inserts the content of the file_name file
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>