views:

122

answers:

3

Hi,

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 idea ?

+1  A: 

Vim requires the cursor to be in the current screen at all times, however, you could bookmark the current position scroll around and then return to where you were.

mg  # This book marks the current position as g (this can be any letter)
<scroll around>
`g  # return to g
GWW
note that if you only care about going to the bookmarked line, you could use 'g
Matt Briggs
Good idea. Didn't thought of bookmarks (I use them often but still).
ereOn
+1  A: 

You may find aswers to this question useful: http://stackoverflow.com/questions/3102446/scrolling-vim-relative-to-cursor-custom-mapping: you can use ScrollToPercent(0) from that question to do this.

ZyX
Indeed, nice function. Thanks.
ereOn
+9  A: 
  • zz - move current line to the middle of the screen
  • zt - move current line to the top of the screen
  • zb - move current line to the bottom of the screen
Kevin
Exactly what I needed ;) Many thanks !
ereOn