Beruflich Dokumente
Kultur Dokumente
Vi For Smarties
Lesson One
Basic Concepts
1. Start by typing vi followed by the file(s) you want to edit.
Example: vi one.txt two.txt etc.txt
2. There are two modes: command mode and insert mode. You will begin in command mode. (Unless you have a config file which changes this. Rare.)
3. Hitting the Esc key always puts you in command mode.
It never takes you out of command mode.
4. Commands only work in command mode. Get used to hitting Esc a lot.
5. Esc is your friend. If you begin to issue a command and then change your mind, always hit Esc a few times to cancel.
6. Remember: ALL COMMANDS ARE CASE-SENSITIVE!!!
Until you have mastered everything on this page, you are not ready for Lesson Two.
http://jerrywang.net/vi/ 1/1
06/04/2017 Vi For Smarties - Lesson Two
Vi For Smarties
Lesson Two
Until you have mastered everything on this page, you are not ready for Lesson Three.
http://jerrywang.net/vi/vitutor2.html 1/1
06/04/2017 Vi For Smarties - Lesson Three
Vi For Smarties
Lesson Three
Until you have mastered everything on this page, you are not ready for Lesson Four.
http://jerrywang.net/vi/vitutor3.html 1/1
06/04/2017 Vi For Smarties - Lesson Four
Vi For Smarties
Lesson Four
Useful Tricks
1. G by itself goes to the last line of the file.
2. ~ (tilde) toggles the case of the character under the cursor.
3. When deleting blocks of text, move to the first line of the block, type ma to mark it, then move to the last line of the block and type d'a to delete the
block.
4. Use the above trick with y'a to yank blocks of text.
Useful Symbols
1. Outside a colon command, $ stands for the end of the current line.
Inside a colon command, $ stands for the last line in the file.
Example: $ goes to the end of the current line.
Example: d$ deletes from the cursor to the end of the current line.
Example: :$ goes to the last line in the file.
Example: :24,$ d deletes everything from line 24 through the last line in the file, inclusive.
2. Outside a colon command, 0 (zero) stands for the beginning of the current line.
Inside a colon command, 0 (zero) stands for line 0, or the line that is going to be created above the first line in the file.
Example: 0 goes to the beginning of the current line.
Example: :10,20 m 0 moves lines 10 through 20, inclusive, above the first line of the file.
Shell Operations
1. Use :!command to execute command without leaving Vi.
Example: :!date will execute the shell command date and display its output.
2. Use :sh to spawn a new command shell inside Vi.
Use exit to leave that shell when done.
Until you have mastered everything on this page, you are not ready for Quiz One.
http://jerrywang.net/vi/vitutor4.html 1/1
06/04/2017 Vi For Smarties - Lesson Five
Vi For Smarties
Lesson Five
Dangerous Pitfalls
1. When you abort a command, ALWAYS hit Esc before continuing. It's easy to lose a lot of work if you forget this!
Example: If you hit d to begin deleting a chunk of text, then change your mind and decide to go look at the last line of your file by hitting G, you'll lose
the rest of your file starting from your current cursor position.
2. Use :w to save your file regularly.
3. Start vi with vi -r filename to recover the swap file of filename if you lost your editing session prematurely. The swap file may or may not be
complete, but it's better than nothing.
Display Control
1. If you hit Q you will enter the line editor, ex. Type vi followed by the enter key to return to vi mode.
2. Use z. (remember the dot) to redraw the screen. Rarely necessary.
Until you have mastered everything on this page, you are not ready for Lesson Six.
http://jerrywang.net/vi/vitutor5.html 1/1
06/04/2017 Vi For Smarties - Lesson Six
Vi For Smarties
Lesson Six
Until you have mastered everything on this page, you are not ready for Lesson Seven.
http://jerrywang.net/vi/vitutor6.html 1/1
06/04/2017 Vi For Smarties - Lesson Seven
Vi For Smarties
Lesson Seven
Customizing Vi ( .exrc)
1. Any of the colon (ed/ex) commands may be put into a setup file in your home directory called .exrc so that you may customize Vi to act however you
want without having to type in each setting by hand every time you start the editor. Your .exrc should contain one complete command per line. When
entering commands into the file, omit the beginning colon. Thus, a line that would normally begin with :map would instead begin with map when it is in
your .exrc file.
2. Users of the various Vi clones, such as Vim, Nvi, and Elvis, should consult their documentation to see if there is a more appropriate name for the
setup file. Vim, for example, uses .vimrc instead.
Until you have mastered everything on this page, you are not ready for Quiz Two.
http://jerrywang.net/vi/vitutor7.html 1/1
06/04/2017 Vi For Smarties - Lesson Eight
Vi For Smarties
Lesson Eight
Advanced Vi Invocation
1. Use vi +/foo when invoking Vi from the command prompt to have it automatically move the cursor to the first occurrence of the string foo in the
first file being edited.
2. Use vi +24 myfile.txt when invoking Vi from the command prompt to have it start with the cursor on line 24 of myfile.txt. Replace the line
number and filename with whatever is appropriate.
3. Use view myfile.txt to start Vi in read-only mode on the file myfile.txt. On systems which do not support symbolic links, such as MS-DOS, try vi
-R myfile.txt instead.
4. NOTE: It is sometimes necessary to invoke clones of Vi by their appropriate program name, such as vim under MS-DOS.
Congratulations, you're done with Vi For Smarties! For a more advanced tutorial, see Walter Alan Zintz's The Vi/Ex Editor.
http://jerrywang.net/vi/vitutor8.html 1/1