Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move screen without moving cursor in Vim?

I recently discovered Ctrl+E and Ctrl+Y shortcuts for Vim that respectively move the screen up and down with a one line step, without moving the cursor.

Do you know any command that leaves the cursor where it is but moves the screen so that the line which has the cursor becomes the first line? (having a command for the last line would be a nice bonus).

I can achieve this by manually pressing Ctrl+E (or Ctrl+Y) the proper number of times, but having a command that somehow does this directly would be nice.

Any ideas?

like image 258
ereOn Avatar asked Aug 11 '10 13:08

ereOn


People also ask

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.

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 move my screen horizontally?

To flip your screen, hit the Ctrl + Alt + up/down arrow keys at the same time. Hold down and press the Ctrl + Alt + Up arrow. Holding down and pressing these keys will rotate your screen to its default position, which is the horizontal orientation. Hold down and press the Ctrl + Alt + Down arrow.


1 Answers

  • zz - move current line to the middle of the screen
    (Careful with zz, if you happen to have Caps Lock on accidentally, you will save and exit vim!)
  • zt - move current line to the top of the screen
  • zb - move current line to the bottom of the screen
like image 148
Kevin Vaughan Avatar answered Sep 25 '22 02:09

Kevin Vaughan