Os 5 Thnew
Os 5 Thnew
05
THEORY:
There are many ways to edit files in Unix and one of the best way is using screen-oriented
text editor vi. This editor enables you to edit lines in context with other lines in the file. Now
days you would find an improved version of vi editor which is called VIM. Here VIM
stands for Vi Improved.
OPERATION MODES
COMMAND MODE: This mode enables you to perform administrative tasks such as
saving files, executing commands, moving the cursor, cutting yanking and pasting lines or
words, and finding and replacing. In this mode, whatever you type is interpreted as a
command.
INSERT MODE: This mode enables you to insert text into the file. Everything that's typed
in this mode is interpreted as input and finally it is put in the file.
EXAMPLE:
$vi testfile
TO EXIT VI
Command Description
:x Quit vi, writing out modified file to file
named in original invocation
:wq Quit vi, writing out modified file to file
named in original invocation
:q Quit vi even though latest changes have not
been saved for this vi call
Page 1 of 5
MOVING WITHIN A FILE
Command Description
k Moves the cursor up one line.
j Moves the cursor down one line.
h Moves the cursor to the left one character position.
l Moves the cursor to the right one character
position.
0 (zero) Move cursor to start of current line(the one with the
arrow)
$ Move cursor to end of the current line
w Move cursor to beginning of next word
b Move cursor back to beginning of preceding word
:0<return> or 1G Move cursor to first line in file
:n<return>or nG Move cursor to line n in file
:$<return>or G Move cursor to last line in file
Page 2 of 5
new text
DELETING CHARACTERS
Command Description
x Deletes the character under the cursor location.
X Deletes the character before the cursor location
D Deletes from the cursor position to the end of the
current line.
dd Deletes the line the cursor is on.
ndd delete the next N lines,including the current line
ADVANCED COMMANDS
Command Description
J Join the current line with the next one. A count joins
that many lines
:w newfile Write current contents to a new file named
newfile
:12,35w smallfile Write the contents of the line numbered 12 through
35 to a new file named smallfile
Page 3 of 5
1) Create a file using vi editor Commands
output:
Page 4 of 5
Page 5 of 5