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 ?
3 Answers
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.
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.
-
-
@JamesFranco Sorry, I don't think I understand what you mean exactly. Could you, please, elaborate a little?– tokoyamiCommented Mar 25, 2016 at 19:09
-
1I 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 ? Commented Mar 25, 2016 at 19:37 -
1No. 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.– tokoyamiCommented Mar 25, 2016 at 19:46
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 screenz.
- scroll so current line is in the middle of your screenz-
- 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 topzb
for bottomzz
(LOWERCASE) for middle
See :help scroll-cursor
for more.
-
2IIRC 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). Commented Mar 26, 2016 at 11:03 -
Keep in mind that the
scrolloff
setting offsets the result ofzt
andzb
by whatever you set it to.– MatijsCommented May 3, 2018 at 6:44