How do I move the cursor to a specific row and column?

Vim

Vim Problem Overview


:30 will move my cursor to the beginning of line 30.

How can I tell Vim to place the cursor at line y, column x? Is this possible without using the arrow keys or h, j, k, l keys?

I am running Vim version 7.3.429.

Vim Solutions


Solution 1 - Vim

Try a number followed by a pipe to get to the specified column in that line.

80| should get you to position 80 in that line.

EDIT: If you are looking to go to a specific x,y position, I am not sure on that one.

Solution 2 - Vim

Not sure it's in any way more convenient, but you can call the cursor function directly:

:cal cursor(30, 5)

will jump to line 30, column 5.

Solution 3 - Vim

In command mode:

Type a number followed by G (uppercase) to go to that line number.
Example: 30G goes to line 30.
Example: G goes to the last line of the buffer.

Type a number followed by | (pipe) to go to that column in the current line.
Example: 80| goes to column 80.

So: 30G80| goes to line 30, column 80.

Solution 4 - Vim

Another option using execute <line_num>. For example,

function GotoLine(line)
     execute a:line
endfunction

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpacvView Question on Stackoverflow
Solution 1 - VimWebDevNewbieView Answer on Stackoverflow
Solution 2 - VimJeen BroekstraView Answer on Stackoverflow
Solution 3 - Vimuser910028View Answer on Stackoverflow
Solution 4 - VimplafrattView Answer on Stackoverflow