vi Tutorial (revision 140721-r02KI)¶
Return to Lab 00
- [Esc] means Escape button on your keyboard.
- If you're not sure whether you're in insert or command mode, push Esc to make it certain that you're in command mode.
- [Enter] means Enter button on your keyboard.
- If you type wrong and want to delete per character, enter command mode by pushing Esc, navigate using arrow buttons and delete using Del button. Do NOT use backspace.
- If you type wrong and want to delete a line, enter command mode by pushing Esc and delete by typing dd (d two times).
- vim (abbreviation of vi improved) is the same text editor as vi, with some additional functions. If you want to use vim instead of vi it is permitted, but in our lab there is only vi installed.
- Create a new text file named NPM.txt. For example my NPM is 1202000818, replace it with your student ID!
$ vi 1202000818.txt
- By executing the above command you will enter vi. By default the first time you enter vi you will be in command mode. This mode is used to access commands in vi, not to write, so that when you try to type (try typing letter g), it's not printed in the text area because vi translate your typing into commands that can be accessed by typing letter g. This command mode can be accessed anytime by pushing Esc (Escape) button on the left side of your keyboard. Now go ahead and press Esc.
Anything that you've pressed before will be cancelled by vi.
- To be able to write we will have to enter insert mode. There are few ways to get into insert mode. For now let's try typing letter i.
- Your writing will be input as a text. Now get back into command mode, then save your work.
- Let's copy and paste the line that you've written before.
- You will be on the second line but in the middle of the line as opposed to the position of the cursor on the first line. We will add "oye" word to the end of this line. So that we can directly jump to the end of this line, we will enter insert mode by typing A (capital A, the capital difference in vim will result on difference treatment, so keep your eye on Caps Lock). Then type "oye".
- Ah, I don't really like the second line because it's actually redundant with the first line, so I decide let's just delete the second line quickly. Let's get into command mode and type dd (d letter twice)
- The whole second line will be deleted. All the above commands are the one that you use the most when typing in vi. If you want to know more about the ability and available commands in vi, please read these articles:
- Last, save your work and exit vi.
Return to Lab 00
Return to Wiki