In vi normal mode, /error was entered and the first match was selected.
Move to the next error in the same search direction.
Which key should be pressed?
n repeats the previous search in the same direction. N repeats it in the opposite direction.
Detailed explanation
NIncorrect. N repeats the search in the opposite direction.
Incorrect. N repeats the search in the opposite direction.
nCorrect. n moves to the next match in the original direction.
Correct. n moves to the next match in the original direction.
?Incorrect. ? starts a new backward search.
Incorrect. ? starts a new backward search.
*Incorrect. * searches for the word under the cursor.
Incorrect. * searches for the word under the cursor.
Try it yourself
An example you can run in a temporary verification environment.
printf 'start\nerror one\nok\nerror two\n' > sample.txt; vim -Nu NONE -i NONE -n -es sample.txt -c '/error' -c 'normal! n' -c 'execute "normal! Iselected-\<Esc>"' -c 'wq'; sed -n '4p' sample.txtExpected result
selected-error twoKey points
- / searches forward
- n repeats in the same direction
- N repeats in the opposite direction
Notes
- Environment: Vim 9.x(vi互換操作)
- 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.