how to scroll faster in vim

25,413

Solution 1

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)

Solution 2

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.

Solution 3

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"'

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).

Share:
25,413

Related videos on Youtube

Lev
Author by

Lev

Updated on July 09, 2022

Comments

  • Lev
    Lev almost 2 years

    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.

    • Andy Ray
      Andy Ray over 5 years
      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 ;)
    • jeremysprofile
      jeremysprofile over 5 years
      @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.
  • Haggra
    Haggra over 3 years
    As a side note, these also work with less, man and the like without the ctrl modifier.
  • Drenai
    Drenai over 3 years
    On a mac with only left Ctrl key, I find Ctrl+e hard to press two handed as e isn't a right hand key. How do other's deal with this?
  • Victor Augusto
    Victor Augusto over 2 years
    Ctrl+e Ctrl+y. That's what i needed! Many thanks!
  • neldeles
    neldeles about 2 years
    @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.