2

I know i can scroll down using ctrl+e and up using control ctrl+y. Any idea how I can scroll multiple lines with ctrl+e ? I am looking for a quick solution for scrolling down in vim ?

7

You can use a count before Ctrl-E − 15<C-e> moves down 15 lines. Ctrl-D moves down half a screen by default, although the amount it moves can be configured via the "scroll" option.

:help motion.txt will provide this and a whole lot more details.

4

As others have noted, you can prefix both <C-e> and <C-y> with counts, to "expose" that many more lines up or down.

Another handy quick scrolling option lets you scroll so that the current line is at the top, middle, or bottom of your screen:

  • z<CR> - scroll so current line is at the top of your screen
  • z. - scroll so current line is in the middle of your screen
  • z- - scroll so current line is at the bottom of your screen

I find the above three versions easiest to type, but Vim does have counterparts for each that leave your cursor in the same column you started in:

  • zt for top
  • zb for bottom
  • zz (LOWERCASE) for middle

See :help scroll-cursor for more.

  • 2
    IIRC the "e" in <C-e> was originally intended as "extra", as in "extra lines". Not expose (although that of course also works well as mnemonic). – Martin Tournoij Mar 26 '16 at 11:03
  • Keep in mind that the scrolloff setting offsets the result of zt and zb by whatever you set it to. – Matijs May 3 '18 at 6:44
3

Ctrl+e takes count, so the quick and simple way is to create a normal mode mapping like the following:

nnoremap <C-e> 10<C-e>

This will simply do Ctrl+e 10 times. You can change the number to the number of lines you want it to scroll at once.

It's important to note that the mapping is of the noremap type. Otherwise VIm will enter an infinite loop once you press the combination.

  • anyway I can repeat that motion ? with a shortcut ? – James Franco Mar 25 '16 at 18:15
  • @JamesFranco Sorry, I don't think I understand what you mean exactly. Could you, please, elaborate a little? – tokoyami Mar 25 '16 at 19:09
  • 1
    I am familiar with the fact that issuing a number with Ctrl+e will scroll to the number of line however i wanted to know if after that I could repeat the last navigation motion by any shortcut. For instance to repeat the last change made we use . . Is there any way to repeat that motion using a shortcut key ? – James Franco Mar 25 '16 at 19:37
  • 1
    No. Motions don't have a repeat option like changes. What my suggestion does is only allowing you to execute C-e 10 times by pressing it once. You can choose a different key combination for this "shortcut" if you want. But it will only be for it. – tokoyami Mar 25 '16 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.