Spring 23-24 Os Lab 7
Spring 23-24 Os Lab 7
1. vi Editor
2. Modes of vi Editor
3. Create, Save, and Quit in vi
4. Vi Commands to Start Typing
5. Vi Commands to Move Around a File
6. Vi Commands to Delete Character and Line
7. Vi Commands to cut, copy, and paste
vi Editor
What is vi editor?
Insert Mode: In insert mode, entered text will be inserted into the
file. Esc key will take you to the command mode from insert mode.
Modes of vi Editor (cont’d)
Commands Action
:wq Save and quit
:w Save
:q Quit
:w fname Save as fname //
ZZ Save and quit
:q! Quit discarding changes made
:w! Save (and write to non-writable file) //
To exit from vi, first ensure that you are in command mode. Now, type :wq and press
enter. It will save and quit vi editor Type :wq to save and exit the file.
Vi Commands to Start Typing
Commands Action
i Start typing before the current character
I Start typing at the start of current line
a Start typing after the current character
A Start typing at the end of current line
o Start typing on a new line after the current line
O Start typing on a new line before the current line.
Vi Commands to Move Around a File
commands Action
j To move down
k To move up
h To move left
l To move right
Vi Commands to Delete Character and Line
commands Action
x Delete the current character
X Delete the character before the cursor
r Replace the current character
xp Switch two characters
dd Delete the current line
Delete the current line from current character to the
D
end of the line
Vi Commands to cut, copy, and paste
commands Action
dd Delete a line
yy (yank yank) copy a line
P Paste before the current line
p Paste after the current line
Books
❑ Unix Shell Programming
❑ Written by Yashavant P. Kanetkar