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 toward the beginning from the current cursor position.
/ERRORIncorrect. /ERROR searches forward toward the end.
Incorrect. /ERROR searches forward toward the end.
:ERRORIncorrect. : starts an Ex command rather than a search pattern.
Incorrect. : starts an Ex command rather than 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 begin 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のノーマルモード
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.