A log is open in vi normal mode.
Search backward from the current position for ERROR, toward the beginning of the file.
Which search command should be entered?
?pattern searches backward toward the beginning. /pattern searches forward toward the end, and n repeats the previous direction.
Detailed explanation
?ERRORCorrect. ?ERROR searches toward the beginning from the current cursor position.
Correct. ?ERROR searches backward from the cursor.
/ERRORIncorrect. /ERROR searches forward toward the end.
Incorrect. /ERROR searches forward toward the end of the file.
:ERRORIncorrect. : starts an Ex command rather than a search pattern.
Incorrect. A colon begins an Ex command, not a search pattern.
nERRORIncorrect. n repeats the previous search and does not begin a new pattern.
Incorrect. n repeats the previous search and does not introduce a new pattern.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s\n' 'viで末尾付近へ移動し、?ERRORと入力してEnterを押す'Expected result
現在位置より前にある直近のERRORへカーソルが移動するKey points
- ? starts a backward search
- / starts a forward search
- n repeats the search
Notes
- Environment: vi/Vimのノーマルモード
- Use a temporary file and harmless edits when testing vi commands.
- Confirm the behavior on the target vi/Vim implementation.
Foundation review
Place the operation
The two search delimiters use the same pattern syntax but travel in opposite directions.
Check the side effect
Place the cursor after a known match and compare ?ERROR with /ERROR.