Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In vim, how do you scroll a buffer so the cursor location is centered in the screen?

Tags:

vim

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?

like image 330
Cory Klein Avatar asked Sep 13 '11 18:09

Cory Klein


People also ask

How do I scroll in Vim?

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).

How do I center text in Vim?

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.

What is Ctrl E in Vim?

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.


1 Answers

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 
like image 176
Peter Rincker Avatar answered Sep 26 '22 10:09

Peter Rincker