2

Consider you are editing the left table in Vim. Your cursor (■) is at Line 14, Column 12.

Where you are now          Move the cursor

11 +-------+-----+         11 +-------+-----+
12 | Name  | Age |         12 | Name  | Age |
13 +=======+=====+         13 +=======+=====+
14 | Alice | 5■  |   -->   14 | Alice | 5   |
15 +-------+-----+         15 +-------+-----+
   ...                        ...
95 +-------+-----+         95 +-------+-----+
96 | Zoe   |     |         96 | Zoe   |  ■  |
97 +-------+-----+         97 +-------+-----+

What's the easy way to move your cursor at Line 96, Column 12, i.e., jump to this specific line without moving horizontally?

3

Turn off :h 'startofline' :

set nostartofline

And execute one of the following command:

96G
:96
:/Zoe

It will place cursor at target line without moving horizontally if target line is longer enough.

Commands starts with : are ex command, check this question if you are confused about / and :/ .

  • 1
    Confirmed. I already like this behavior so much that I have added set nostartofline to my .vimrc to enable this by default, globally. – Culip Dec 6 '19 at 11:26
0

Assuming the 96th line actually has column no. 12 (or set virtualedit=all), you can do 96zz (or 96zt, or 96zb).

See :h scroll-cursor for more information.

  • zz, zt and zb work but they also scroll the window which is confusing.. Any way not to scroll/redraw the window? – Culip Dec 5 '19 at 19:36
  • @Culip Is 84j okay? – Matt Dec 5 '19 at 19:40
  • In this case I have to use relative line numbers or do the math (line 96 - 14). Um.. – Culip Dec 5 '19 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.