In vi editor how do I go to a particular line?
For example if I open a file named file.py is there an option for open the file at a particular line, or can I open my file and then go to line with keyboard shortcut?
In vi editor how do I go to a particular line?
For example if I open a file named file.py is there an option for open the file at a particular line, or can I open my file and then go to line with keyboard shortcut?
To make vi start at a particular line in a file, add +line_num to the command you use to start vi. Replace line_num with the line number, for example:
vi +14 file.py
You can also use the ex command line to go to a line. (For information about the ex mode, see Use the vi text editor) For instance, if you wanted to go to line 14, you could press Esc and then enter:
:14
There is also a vi command. The G jump (goto) motion takes an optional count prefix, which is the line number to go to. Hence 14G.
For the kbd addicts, that's
1, then 4, and then Shift+G.
j or cursor down) 13 lines with 13j (or 13 followed by cursor down). Upwards is with k or cursor up. You can jump up and down by page offsets too with the same principle
– Chris Davies
Mar 19 '22 at 11:56
13+ and 13 (Enter) will also move down 13 lines, similar to 13j, and you can use 13- (minus) to go up 13 lines. A subtle difference: j and k are very much like ↓ (Cursor Down) and ↑ (Cursor Up); they will attempt to maintain the horizontal coordinate of the cursor’s position. +, - and (Enter), on the other hand, will move the cursor to the first non-blank character on the destination line.
– G-Man Says 'Reinstate Monica'
Mar 19 '22 at 17:54
:14 was what I was looking for. Nice and simple. Less strokes than 14gg and 14G, with the benefit of seeing and editing what you type. Couldn't find it when I was searching with :h gg or :h go. (Anyone know how to find this in the help pages?)
– mcp
Feb 14 '24 at 20:18
man viyou can read the manual page. With/lineyou can search for occurences of the wordline, withnjump to the next one, just like invi. One of the first matches describes the option you were looking for. This takes less time than searching the web or asking a question here. – Philippos Sep 10 '18 at 15:23