如何将光标移动到特定的行和列?

:30会将光标移动到第30行的开头。

我如何告诉 Vim 将光标放在 y 行 x 列? 这可能吗 不使用箭头键或 hjkl键?

我正在运行 Vim 版本7.3.429。

56540 次浏览

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.

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.

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.

Another option using execute <line_num>. For example,

function GotoLine(line)
execute a:line
endfunction