Unit 9: vi editor - Practice Quiz

CSE105 — Creative Engineering Workshop 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Which command is used to start the vi editor and open a file named notes.txt?

starting vi Easy
A. open notes.txt
B. vi notes.txt
C. edit notes.txt
D. start notes.txt

2 When vi first opens a file, which mode is it in by default?

starting vi Easy
A. Insert mode
B. Visual mode
C. Replace mode
D. Command mode

3 Which key is pressed to switch from Command mode to Insert mode in vi?

starting vi Easy
A. c
B. e
C. v
D. i

4 In vi Command mode, which key moves the cursor one character to the right?

Navigation Commands Easy
A. k
B. l
C. j
D. h

5 Which key moves the cursor down one line in vi Command mode?

Navigation Commands Easy
A. j
B. k
C. l
D. h

6 Which command moves the cursor to the beginning of the current line?

Navigation Commands Easy
A. G
B. 0 (zero)
C. $
D. ^ then w

7 Which command moves the cursor to the end of the current line in vi?

Navigation Commands Easy
A. 0
B. e
C. b
D. $

8 Which command moves the cursor to the last line of the file?

Navigation Commands Easy
A. G
B. 0
C. gg
D. $

9 Which command scrolls the screen forward by one full page in vi?

Scrolling Commands Easy
A. Ctrl + d
B. Ctrl + u
C. Ctrl + f
D. Ctrl + b

10 Which command scrolls the screen backward by one full page?

Scrolling Commands Easy
A. Ctrl + e
B. Ctrl + d
C. Ctrl + f
D. Ctrl + b

11 Which command scrolls the screen down by half a page?

Scrolling Commands Easy
A. Ctrl + u
B. Ctrl + b
C. Ctrl + d
D. Ctrl + f

12 Which command appends text after the current cursor position?

Insert and Edit Commands Easy
A. a
B. o
C. r
D. i

13 Which command opens a new line below the current line and enters Insert mode?

Insert and Edit Commands Easy
A. o
B. a
C. O
D. i

14 Which command replaces a single character under the cursor with a new one?

Insert and Edit Commands Easy
A. r
B. R
C. c
D. s

15 Which key is used to return from Insert mode back to Command mode?

Insert and Edit Commands Easy
A. Enter
B. Tab
C. Ctrl
D. Esc

16 Which command deletes the single character under the cursor?

Delete Commands Easy
A. dw
B. X
C. dd
D. x

17 Which command deletes the entire current line in vi?

Delete Commands Easy
A. dw
B. x
C. dd
D. d$

18 Which command deletes from the cursor to the end of the current word?

Delete Commands Easy
A. dd
B. db
C. dw
D. x

19 Which command copies (yanks) the current line in vi?

Copy-Paste Operations Easy
A. pp
B. yy
C. cc
D. dd

20 Which command pastes copied text after the cursor or below the current line?

Copy-Paste Operations Easy
A. y
B. x
C. p
D. 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?

starting vi Medium
A. vi -25 report.txt
B. vi report.txt +25
C. vi report.txt -l 25
D. vi +25 report.txt

22 A developer runs vi +/main program.c. What is the effect of this command?

starting vi Medium
A. Opens the file at the last line
B. Opens the file in read-only mode searching for main
C. Creates a new file named main
D. Opens the file with the cursor on the first line containing 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?

starting vi Medium
A. view filename
B. vi +r filename
C. vi --lock filename
D. vi -w filename

24 The cursor is in the middle of a line. Pressing $ followed by 0 produces what result?

Navigation Commands Medium
A. Cursor moves to end of line, then to the beginning of the line
B. Cursor moves down one line, then up one line
C. Cursor moves to the last line, then the first line
D. Cursor moves to the beginning, then to the end of the line

25 In a 100-line file, which command moves the cursor directly to the last line of the file?

Navigation Commands Medium
A. gg
B. 1G
C. L
D. 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?

Navigation Commands Medium
A. brown
B. The
C. fox
D. quick

27 Which command moves the cursor to the matching parenthesis, brace, or bracket of the one under the cursor?

Navigation Commands Medium
A. &
B. @
C. %
D. *

28 While editing a large file in command mode, you press Ctrl+f. What happens?

Scrolling Commands Medium
A. The cursor moves forward one word
B. The screen scrolls forward half a page
C. The screen scrolls forward one full page
D. The screen scrolls backward one full page

29 You want to scroll the display down by half a screen while keeping the cursor context. Which key combination should you use?

Scrolling Commands Medium
A. Ctrl+f
B. Ctrl+b
C. Ctrl+u
D. Ctrl+d

30 What is the difference between Ctrl+u and Ctrl+b in vi?

Scrolling Commands Medium
A. Ctrl+u scrolls up half a screen; Ctrl+b scrolls up a full screen
B. Ctrl+u scrolls up a full screen; Ctrl+b scrolls up half a screen
C. Ctrl+u deletes a line; Ctrl+b moves back a word
D. Both scroll down by a full screen

31 The cursor is on a character in the middle of a line. You press A. Where does insertion begin?

Insert and Edit Commands Medium
A. Before the current character
B. After the current character
C. At the beginning of the current line
D. At the end of the current line

32 You want to open a new empty line above the current line and start typing on it. Which command should you use?

Insert and Edit Commands Medium
A. I
B. i
C. O
D. o

33 The cursor is on the letter t in the word cat. You press r and then p. What is the resulting word?

Insert and Edit Commands Medium
A. cap
B. cpt
C. catp
D. pat

34 Which command changes text from the cursor position to the end of the current line, entering insert mode?

Insert and Edit Commands Medium
A. cc
B. s$
C. c$ then c
D. C

35 The cursor is at the beginning of a line. You type 3dd. What is the result?

Delete Commands Medium
A. Deletes the 3rd line only
B. Deletes 3 words from the cursor
C. Deletes 3 characters from the current position
D. Deletes 3 lines starting from the current line

36 The cursor is on the first letter of the word hello. Which command deletes the word including the space after it?

Delete Commands Medium
A. dw
B. dd
C. de
D. x5

37 What does the command d$ do?

Delete Commands Medium
A. Deletes the entire current line
B. Deletes from the cursor to the beginning of the line
C. Deletes to the end of the file
D. Deletes from the cursor to the end of the line

38 You type 4yy and then move the cursor and press p. What was copied and pasted?

Copy-Paste Operations Medium
A. 4 lines were copied and pasted below the cursor line
B. 4 characters were copied and pasted
C. 4 words were copied and pasted after the cursor
D. The 4th line was copied and pasted above the cursor

39 After yanking a single line with yy, you press P (uppercase). Where is the line pasted?

Copy-Paste Operations Medium
A. Above the current line
B. At the end of the file
C. Below the current line
D. After the cursor on the same line

40 You have made changes but decide to discard them and quit vi without saving. Which command should you use?

Save and Exit Operations Medium
A. :x
B. :q!
C. :wq
D. ZZ

41 A user runs vi +/main prog.c. What is the intended effect when the file opens?

starting vi Hard
A. A new file named main is created alongside prog.c
B. The file opens in read-only mode filtered by main
C. Only lines matching main are loaded into the buffer
D. The cursor is placed on the first line containing the pattern main

42 You execute vi -R notes.txt. Later you make edits and try :wq. What happens?

starting vi Hard
A. vi silently discards changes and exits
B. The file saves normally since -R only affects the initial view
C. vi creates a backup file automatically before writing
D. vi refuses the write because the file was opened read-only, requiring :wq! to override

43 What is the difference between launching vi file1 file2 versus vi -o file1 file2 in vim-compatible editors?

starting vi Hard
A. -o merges the two files into one buffer
B. Both commands do exactly the same thing
C. -o opens both files in horizontally split windows simultaneously, while the plain form loads them into the buffer list one at a time
D. -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?

Navigation Commands Hard
A. On the - between baz and qux
B. On qux at the end
C. On the _ inside foo_bar
D. On baz (the word after the space)

45 You are on line 50 of a 200-line file. You type 35G. What is the result?

Navigation Commands Hard
A. The cursor moves to column 35 of the current line
B. The cursor moves to line 35
C. The cursor moves 35 lines down to line 85
D. 35 lines are deleted starting from line 50

46 In command mode, what is the key difference between 0, ^, and $?

Navigation Commands Hard
A. 0 moves to the very first column, ^ moves to the first non-blank character, and $ moves to the end of the line
B. 0 and ^ are identical; $ moves down one line
C. 0 moves to first non-blank, ^ to column 0, $ to next word
D. 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?

Navigation Commands Hard
A. &
B. %
C. }
D. *

48 What is the precise difference between Ctrl-f and Ctrl-d while scrolling in vi?

Scrolling Commands Hard
A. Ctrl-f moves one line, Ctrl-d deletes the current line
B. Ctrl-f scrolls forward a full screen, while Ctrl-d scrolls down half a screen
C. Both scroll a full screen but in opposite directions
D. 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?

Scrolling Commands Hard
A. The current line is redrawn to the center of the screen without moving the cursor to a different line
B. The current line moves to the top of the screen
C. vi saves and exits the file
D. The screen scrolls down by one full page

50 Which pair correctly maps the scroll commands Ctrl-e and Ctrl-y?

Scrolling Commands Hard
A. Both commands scroll half a screen in the same direction
B. Ctrl-e scrolls up a page, Ctrl-y scrolls down a page
C. 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
D. 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?

Insert and Edit Commands Hard
A. a
B. o
C. I
D. A

52 In command mode you press 3o and type test, then press Esc. What is the result?

Insert and Edit Commands Hard
A. Three new lines each containing test are opened below the current line
B. One new line with test repeated three times is opened
C. The word test replaces three lines below
D. Three lines above the cursor are opened with test

53 What is the difference between r and R in command mode?

Insert and Edit Commands Hard
A. r replaces a single character and returns to command mode, while R enters replace mode overwriting characters until Esc
B. r reads a file, R writes a file
C. r and R both enter insert mode
D. 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?

Insert and Edit Commands Hard
A. The text from the cursor to the end of the word is replaced with set
B. set is inserted before the cursor without deleting anything
C. The entire word configuration is replaced with set
D. The whole line is replaced with set

55 The cursor is at the beginning of a five-line paragraph. You type d3j. How many lines are deleted?

Delete Commands Hard
A. 4 lines (the current line plus the next three)
B. 3 lines
C. 5 lines
D. 2 lines

56 What does d$ accomplish, and how does it differ from D?

Delete Commands Hard
A. d$ deletes backward to line start, D deletes forward
B. d$ deletes to end of file, D deletes to end of line
C. d$ deletes the whole line while D deletes one character
D. They are functionally identical: both delete from the cursor to the end of the line

57 You press x five times rapidly. What is the equivalent single command?

Delete Commands Hard
A. 5dd
B. d5
C. 5x
D. x5

58 You execute 3yy then move the cursor and press p. What is placed and where?

Copy-Paste Operations Hard
A. Three words are pasted before the cursor
B. Three characters are pasted after the cursor
C. Three yanked lines are pasted on the lines below the cursor's current line
D. The three lines are pasted above the current line

59 After deleting a word with dw, you press p. Why does text appear even though you did a delete, not a yank?

Copy-Paste Operations Hard
A. p always regenerates the last typed word from insert mode
B. Deleted text is stored in the unnamed register, and p pastes from that register just like yanked text
C. vi automatically converts deletes to yanks after 5 seconds
D. The 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?

Copy-Paste Operations Hard
A. ayy
B. @a
C. "ap
D. p