A file is open in vi normal mode.
Move the cursor directly to line 40.
Which key sequence is appropriate?
In normal mode, a number before G moves to that line. G by itself moves to the last line.
Detailed explanation
G40Incorrect. G40 treats 40 as a following command rather than a line-count prefix.
40GCorrect. 40G moves directly to line 40.
40jIncorrect. 40j moves down 40 lines from the current position.
GIncorrect. G alone moves to the last line.
Try it yourself
An example you can run in a temporary verification environment.
seq 1 50 > lines.txt; vim -Nu NONE -n -es lines.txt -c 'normal! 40G' -c 'execute "normal! Iselected-\<Esc>"' -c 'wq'; sed -n '40p' lines.txtExpected result
selected-40Key points
- 40G moves to line 40
- G moves to the last line
- gg moves to the first line
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.