a) Assume you are using ‘vi’ and are in insert mode. Describe what you need to d
ID: 3852761 • Letter: A
Question
a) Assume you are using ‘vi’ and are in insert mode. Describe what you need to do to save the changes you’ve made and quit the editor (assuming that the file has been saved previously and exists). Give specific commands/keystrokes.
b) Other than the arrow keys on your keyboard, how do you move the cursor left/right/up/down with vi?
c) What do each of the following vi commands do (if you see a command we haven’t talked about, just do a quick internet search to find out what the command does): - 5G - 9dw - 10yy - 3dd - 2o - 5~
d) How do you tell vi to open the file ‘assignments.txt’ with the cursor starting on line 128?
e) How do you tell vi to open the file ‘assignments.txt’ as a read-only file?
Explanation / Answer
In VI editor there are two types of modes-- insert mode and command mode.
If we type at unix terminal like
$ vi assignments.txt
then the vi editor opens in command mode and at this mode what ever we type will be interpreted as a command! When we press 'i' the vi editor goes to insert mode.To get back to command mode just press escape button from the keyboard.
a) Given vi editor is in insert mode and some changes are made to opend document.
To save the changes to a file and quit from the editor use the following command.
first press escape key to move the editor from insert mode to command mode then type colon followed by w and q
:wq (save and quit)
to save the changes to a file and not to move from the cursor---- press escape key then type colon followed by w
:w (save)
just to quit with out saving type --- press esacpe key then type colon followed by q
:q (quit without saving)
b. Other then the arrow keys on your keyboard, how do you move the cursor left/right/up/down with vi
If the editor is in command mode first press escape key to come to commad mode. When the cursor in the command mode then:
press h ----> to move the cursor left one character
press l -----> to move the cursor right one character
press k -----> to move the cursor up one line
press j -----> to move the cursor down one line
( make sure to use the above commands the cursor must be in command mode)
c. What do each of the following vi commands do 5G,9dw,10yy,3dd,2o,5~
If the vi editor is in insert mode then press escape key to change from insert mode to command mode. When the editor is in command mode. Then
pressing 5G in command mode at vi editor ----will move the cursor to move to the fifth line of the opend file.
pressing 9dw in command mode at vi editor---- deletes 9 words from the cursor pointing position
pressing yy in command mode at vi editor --- point the cursor at any line and press yy (yanked). This will copy the line and now move the cursor to any location and press p so that the copied line is pasted there.
pressing 3dd in command mode at vi editor ---- will delete three lines from the cursor pointing position.
pressing 2o in command mode at vi editor---- will move the cursor to new second line from the cursor pointing position. ( equivalent to pressing two enter keys)
pressing 5~ in command mode at vi editor------the cursor will move five locations further and convert upper case to lower case letter if the fifth character is upper case or vice versa.( used for type conversion)
d. how do you tell the vi to open the file "assignments.txt" with the cursor starting on line 128?
Just add the line number between vi and file name with an + symbol and press enter( vi + line_number filename).
At the unix terminal type
$ vi +128 assignments.txt
opens the assignments.txt with the cursor starting on like 128
e. How do you tell vi to open the file assignments.txt as a read-only file?
To open the file assignments.txt in read-onlymode:
At the unix terminal type we can use any of the following threee statements
$ view assignments.txt
or
$ vi -R assignments.txt
or
$ vi -M assignments.txt
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.