In vim, often I will jump to a mark I made, or a search result, and the cursor will be at the very bottom or very top of the screen. At this point, in order for the screen to be easier to read, I want to scroll the buffer so that the text under the cursor is in the middle of the screen.
Is this possible in vim? How do you do it?
You can make Vim scroll the text using the shifted up/down arrows by mapping Shift-Up to Ctrl-Y and Shift-Down to Ctrl-E. Shift-Down will then scroll down (like moving a scroll-bar down, or like moving a cursor at the bottom of a window down), and Shift-Up will then scroll up (like moving a scroll-bar up, etc).
Did you know you can center align text in vim? From a visual selection, run :center . This aligns the text on the assumption that the width of the document is textwidth , or 80 characters by default. You can also manually set the range by running :center N , where N is the total width of the line.
In Vim, Ctrl e is normally used to scroll the window up, and it can keep scrolling the window to the point where the bottom edge of the file goes above the bottom edge of the window. This enables us to center the bottom of a file in the middle of our window, allowing for easier viewing.
This will center the current line
zz
Optionally you could set scrolloff
to something large like 999
and the working line will always be in the center, except when you are towards the start or end of the file.
:set scrolloff=999
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With