Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical line alignment when opening new window in vim

Tags:

vim

How do I keep vertical alignment when opening a new window (split) under current one in vim?

When I edit a file, some lines are visible (say 1-20). Once I open another window the visible lines change to something else (say 5-15). I would like to keep the original window vertically aligned, meaning see lines 1-11 in my example.

like image 297
Xyand Avatar asked Feb 18 '26 22:02

Xyand


1 Answers

The "vertical alignment" changes because Vim is trying to keep the line that your cursor is currently on in view. The simplest way to do what you want is just to press H before you do your split. H moves your cursor to the top line of the window, so when you split the viewport won't have to change to keep your cursor in view.

This will move your cursor of course, but you can just hit `` to return to the mark that was set when you pressed H.

like image 174
ngm Avatar answered Feb 21 '26 14:02

ngm