how to scroll faster in vim
Asked Answered
S

4

51

Scrolling while keeping j or k pressed is too slow. Doing 10j multiple times isn't ideal either.

How can I go faster while keeping a key pressed ? I'm using vim for vscode but I imagine the solution probably applies there too.

Stellarator answered 2/1, 2019 at 13:32 Comment(2)
Use your scroll wheel, set up terminal integration if you need to. It's 2019, don't be held back by Vim's clunky design, use modern features ;)Heflin
@AndyRay, one of the selling points of vim is that you don't have to move your hands to the mouse to perform any action, including scrolling.Trencher
L
81

If you are looking to speed up the time to get to a specific spot, having many pages. These commands support to keep the keys press if needed to increase speed:

ctrl + f (page down)

ctrl + b (page up)

ctrl + d (scroll window downwards, normally half a a screen)

ctrl + u (scroll window upwards, normally half a a screen)

Lewendal answered 2/1, 2019 at 13:42 Comment(1)
As a side note, these also work with less, man and the like without the ctrl modifier.Thurlough
R
40

I believe you're looking for a better way to navigate between say code blocks or similar sections without having to do recursive j's or k's. These are my personal favorites :

  • Scrolling through screen with the cursor staying on the same line/present line by Ctrl+y and Ctrl+e
  • Moving between paragraphs. Very useful for moving between code blocks(assuming no newline inside the code block :D) like different functions, classes etc by using the { and } keys.
  • The best and fastest way to go to move around is by using the available visual cues like keywords on certain lines etc and searching and moving cursor to that point. You can use the / or ? key to search for a particular word and either press Esc to stop search and move to original cursor position or Enter to go to that searched keyword.
  • Of course you can advance by full screens using Ctrl+F and Ctrl+B.
  • You can directly go to a particular line by typing the line number in normal mode and pressing capital G. eg:- 10G

if you're still wanting to explore more navigation tricks and commands, i strongly recommend you to watch this wonderful talk.

Rinaldo answered 2/1, 2019 at 16:36 Comment(2)
Ctrl+e Ctrl+y. That's what i needed! Many thanks!Variegated
@Drenai remap caps lock to ctrl. No 3rd party software needed even. System preferences -> keyboard -> modifier keys. I prefer to use hyperkey.app because it has additional features like quick press for caps and hold for ctrl.Cleat
G
35

There are other good jumps

} .......... jump paragraph forward
{ .......... jump paragraph above
H .......... top of the window
M .......... middle of the window
L .......... bottom of the window

Ctrl-d ...... jumps down half screen
Ctrl-u ...... jumps back half screen

If you make jumps with search /pattern you can use

Ctrl-o ...... jump to the last position (jump list)
Ctrl-i ...... jump to the next position (jump list)

Relative to use j and k, they do not add any entry to the jumplist (:h jumplist), but you can do something that in your ~/.vimrc:

" It adds motions like 25j and 30k to the jump list, so you can cycle
" through them with control-o and control-i.
" source: https://www.vi-improved.org/vim-tips/
nnoremap <expr> j v:count ? (v:count > 5 ? "m'" . v:count : '') . 'j' : 'gj'
nnoremap <expr> k v:count ? (v:count > 5 ? "m'" . v:count : '') . 'k' : 'gk'

With the above lines in your config file any jump greater than 5 lines will create a new entry in the jumplist.

To make my search faster, because my laptop makes difficult to reach / I have this mapping:

nnoremap <space> / 

In order to start typing on the last inserting point you can type:

gi

You can reselect and jump to the last visual selection with

gv

Once you have a selection you can use the letter o to jump the selection edges and possible increase or decrease how far the selection goes.

gd  ............. jump to function definition

There is also the "changelist"

g;  ................ goes to the older cursor position on the changlist
g,  ................ goes to the newer cursor postion on the change list

Sometimes you are at the right point, but you want to scrool the widows without moving the cursror.

gg ............ beginning of the file
G .............. end of the file

zt  ............ puts the current line at the top
zz  ............ puts the current line at the middle
zb ............. puts the current line at the bottom

% .............. Jump to corresponding item, e.g. from an open brace to its matching closing brace. 

If you want to open your last edited file on vim you should set an alias like this one:

alias lvim='vim -c "normal '\''0"'

To jump to your last change you can have a map

nnoremap gl `.zz

Now in normal mode you can press gl and the cursor will jump to your last change point, as we are also using zz, the line will be centered on your screen.

An annoying thing I had in the past was how fast my Ctrl-d was. To solve this now I have the "vim-smoothie" plugin - for neovim there is karb94/neoscroll.nvim.

An interesting plugin to help you jump faster on the file is vim-sneak, it remaps your normal s key and shows you a prompt where you type two keys, it will jump to it allowing you to use ; to jump to the next. (It has a slogan: The missing motion for vim).

Gewgaw answered 2/1, 2019 at 16:27 Comment(0)
T
5

Increase the repeat rate in your keyboard settings

Tenuous answered 17/6, 2022 at 11:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.