Unit 9: vi editor - Practice Quiz
1
Which command is used to start the vi editor and open a file named notes.txt?
open notes.txt
vi notes.txt
edit notes.txt
start notes.txt
2 When vi first opens a file, which mode is it in by default?
3 Which key is pressed to switch from Command mode to Insert mode in vi?
c
e
v
i
4 In vi Command mode, which key moves the cursor one character to the right?
k
l
j
h
5 Which key moves the cursor down one line in vi Command mode?
j
k
l
h
6 Which command moves the cursor to the beginning of the current line?
G
0 (zero)
$
^ then w
7 Which command moves the cursor to the end of the current line in vi?
0
e
b
$
8 Which command moves the cursor to the last line of the file?
G
0
gg
$
9 Which command scrolls the screen forward by one full page in vi?
Ctrl + d
Ctrl + u
Ctrl + f
Ctrl + b
10 Which command scrolls the screen backward by one full page?
Ctrl + e
Ctrl + d
Ctrl + f
Ctrl + b
11 Which command scrolls the screen down by half a page?
Ctrl + u
Ctrl + b
Ctrl + d
Ctrl + f
12 Which command appends text after the current cursor position?
a
o
r
i
13 Which command opens a new line below the current line and enters Insert mode?
o
a
O
i
14 Which command replaces a single character under the cursor with a new one?
r
R
c
s
15 Which key is used to return from Insert mode back to Command mode?
Enter
Tab
Ctrl
Esc
16 Which command deletes the single character under the cursor?
dw
X
dd
x
17 Which command deletes the entire current line in vi?
dw
x
dd
d$
18 Which command deletes from the cursor to the end of the current word?
dd
db
dw
x
19 Which command copies (yanks) the current line in vi?
pp
yy
cc
dd
20 Which command pastes copied text after the cursor or below the current line?
y
x
p
c
21
You want to open the file report.txt in vi and place the cursor directly on line 25 as soon as the file opens. Which command achieves this?
vi -25 report.txt
vi report.txt +25
vi report.txt -l 25
vi +25 report.txt
22
A developer runs vi +/main program.c. What is the effect of this command?
main
main
main
23 You accidentally opened an important system file and want to ensure you cannot modify it while viewing. Which command opens the file in read-only mode?
view filename
vi +r filename
vi --lock filename
vi -w filename
24
The cursor is in the middle of a line. Pressing $ followed by 0 produces what result?
25 In a 100-line file, which command moves the cursor directly to the last line of the file?
gg
1G
L
G
26
The cursor is at the start of the sentence The quick brown fox. You press w three times. On which word does the cursor land?
brown
The
fox
quick
27 Which command moves the cursor to the matching parenthesis, brace, or bracket of the one under the cursor?
&
@
%
*
28
While editing a large file in command mode, you press Ctrl+f. What happens?
29 You want to scroll the display down by half a screen while keeping the cursor context. Which key combination should you use?
Ctrl+f
Ctrl+b
Ctrl+u
Ctrl+d
30
What is the difference between Ctrl+u and Ctrl+b in vi?
Ctrl+u scrolls up half a screen; Ctrl+b scrolls up a full screen
Ctrl+u scrolls up a full screen; Ctrl+b scrolls up half a screen
Ctrl+u deletes a line; Ctrl+b moves back a word
31
The cursor is on a character in the middle of a line. You press A. Where does insertion begin?
32 You want to open a new empty line above the current line and start typing on it. Which command should you use?
I
i
O
o
33
The cursor is on the letter t in the word cat. You press r and then p. What is the resulting word?
cap
cpt
catp
pat
34 Which command changes text from the cursor position to the end of the current line, entering insert mode?
cc
s$
c$ then c
C
35
The cursor is at the beginning of a line. You type 3dd. What is the result?
36
The cursor is on the first letter of the word hello. Which command deletes the word including the space after it?
dw
dd
de
x5
37
What does the command d$ do?
38
You type 4yy and then move the cursor and press p. What was copied and pasted?
39
After yanking a single line with yy, you press P (uppercase). Where is the line pasted?
40 You have made changes but decide to discard them and quit vi without saving. Which command should you use?
:x
:q!
:wq
ZZ
41
A user runs vi +/main prog.c. What is the intended effect when the file opens?
main is created alongside prog.c
main
main are loaded into the buffer
main
42
You execute vi -R notes.txt. Later you make edits and try :wq. What happens?
-R only affects the initial view
:wq! to override
43
What is the difference between launching vi file1 file2 versus vi -o file1 file2 in vim-compatible editors?
-o merges the two files into one buffer
-o opens both files in horizontally split windows simultaneously, while the plain form loads them into the buffer list one at a time
-o opens the files read-only
44
The cursor is at the start of a line reading foo_bar baz-qux. In command mode you press w twice. Where does the cursor land?
- between baz and qux
qux at the end
_ inside foo_bar
baz (the word after the space)
45
You are on line 50 of a 200-line file. You type 35G. What is the result?
46
In command mode, what is the key difference between 0, ^, and $?
0 moves to the very first column, ^ moves to the first non-blank character, and $ moves to the end of the line
0 and ^ are identical; $ moves down one line
0 moves to first non-blank, ^ to column 0, $ to next word
0 moves to the last line, ^ to the first line, $ to end of file
47 Which command places the cursor on the matching bracket of the one currently under it?
&
%
}
*
48
What is the precise difference between Ctrl-f and Ctrl-d while scrolling in vi?
Ctrl-f moves one line, Ctrl-d deletes the current line
Ctrl-f scrolls forward a full screen, while Ctrl-d scrolls down half a screen
Ctrl-f scrolls forward half a screen, while Ctrl-d scrolls a full screen
49
The cursor is somewhere in the middle of the screen. You press zz. What happens?
50
Which pair correctly maps the scroll commands Ctrl-e and Ctrl-y?
Ctrl-e scrolls up a page, Ctrl-y scrolls down a page
Ctrl-e scrolls the window down one line, Ctrl-y scrolls up one line, both keeping the cursor on the same text line when possible
Ctrl-e moves cursor to end of file, Ctrl-y to start
51 The cursor is on the last non-blank character of an indented line. You want to start typing after that character but at the true end of the line's content. Which single command is correct and efficient?
a
o
I
A
52
In command mode you press 3o and type test, then press Esc. What is the result?
test are opened below the current line
test repeated three times is opened
test replaces three lines below
test
53
What is the difference between r and R in command mode?
r replaces a single character and returns to command mode, while R enters replace mode overwriting characters until Esc
r reads a file, R writes a file
r and R both enter insert mode
r replaces the whole line, R replaces a single word
54
The cursor is in the middle of the word configuration. You press cw and type set. What is the outcome?
set
set is inserted before the cursor without deleting anything
configuration is replaced with set
set
55
The cursor is at the beginning of a five-line paragraph. You type d3j. How many lines are deleted?
56
What does d$ accomplish, and how does it differ from D?
d$ deletes backward to line start, D deletes forward
d$ deletes to end of file, D deletes to end of line
d$ deletes the whole line while D deletes one character
57
You press x five times rapidly. What is the equivalent single command?
5dd
d5
5x
x5
58
You execute 3yy then move the cursor and press p. What is placed and where?
59
After deleting a word with dw, you press p. Why does text appear even though you did a delete, not a yank?
p always regenerates the last typed word from insert mode
p pastes from that register just like yanked text
p command re-runs the previous dw
60
You yank a line into named register a using "ayy, then perform several deletes. To paste the originally yanked line, which command works?
ayy
@a
"ap
p
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →