vi Tutorial
• Why spend time learning a text editor?
• Why vi?
• vim – vi improved
• vi has two basic modes, command mode and insert mode
The Bare Minimum
vi vitest Open a new or existing file (starts in command mode)
i Enter insert mode
Your Name Type your name
[Enter] Press the enter key to start a new line
Your favorite food Type the name of your favorite food
[Enter] Press the enter key to start a new line
[Esc] Press the escape key to enter command mode
:w [Enter] Save (write) the file
i Enter insert mode
Use the arrow keys to place the cursor below favorite food
Your favorite element Type the name of your favorite chemical element
[Enter] Press the enter key to start a new line
The quick brown fox jumps over the lazy dog.
[Enter] Press the enter key to start a new line
[Esc] Press the escape key to enter command mode
:w [Enter] Save (write) the file
:q [Enter] Exit (quit) vi
OR
:x [Enter] Save and exit vi
less vitest Have a look at your file in less
Moving Around in Command Mode
w Move one word to the right
gg Move to the beginning of the file
G Move to the end of the line
^ Move to the beginning of the line
$ Move to the end of the line
:line_number [Enter] Move to a specific line
Different ways of entering insert mode
a Insert after cursor
I Insert at the beginning of the line
A Insert at the end of line
Undo
:u [Enter]
[Esc]:q!
Deleting Text
x Delete the character under the cursor
dd Delete the current line
d$ Delete to the end of the line
Repeating Commands
. Repeat last command
nc Repeat command c n times
3dd Delete three lines
4w Move four words to the right
Changing text
~ Change the case of the current character
r Change the current character
R Overwrite
Copy and Paste
yy Copy (yank) the current line
y$ Yank to the end of the line
p Paste the last thing that was copied
Visual Mode
v Enter visual mode
Use arrow keys to select text
y Copy selected text
p Paste text
V Enter visual line mode
Search
/text Search for text
:%s/text/newtext/ Search for text and replace with newtext
Other
:e file Edit another file
.vimrc