How to use vim vertical movements

Vertical movements in Vim refer to the commands and techniques used to navigate and move the cursor up and down within the editor

Vim offers various commands to facilitate vertical movement, allowing users to efficiently traverse through lines, paragraphs, and larger blocks of text. They enable users to swiftly navigate through their code or text, making it easier to locate specific sections, review content, or perform targeted editing tasks.

The best way to learn how to use the vim movements is to disable the arrows and PageUp/PageDown keys. That way, you will force yourself to use the vim key combinations to move around. These are the instructions that you can add to your .vimrc to disable those keys:

" DISABLE Arrows keys and PageUp/PageDown
noremap <Up>       <Nop>
noremap <Down>     <Nop>
noremap <Left>     <Nop>
noremap <Right>    <Nop>
noremap <PageUp>   <Nop>
noremap <PageDown> <Nop>

Apart from that, enabling relative numbers allows you to use relative jumping, which once you get used to it, is a very fast way of moving around the screen:

set number
set relativenumber

The main vertical movements are the following:

  • File Scope
    • gg: beginning of the file
    • G: end of the file
  • Screen:
    • H: top of the screen
    • M: middle of the screen
    • L: bottom of the screen
  • Relative jumping:
    • <number>k: jump above that number of lines
    • <number>j: jump below that number of lines
There are a couple of movements that are really useful for moving around a file:
  • Ctrl+u: half-page up
  • Ctrl+d: half-page down
But they are a bit disorienting because you lose track where the cursor is. In order to fix that, you can add a key binding to keep the cursor in the middle:


" Scroll half page up keeping cursor in the middle
nnoremap <C-u>         <C-u>M
" Scroll half page down keeping cursor in the middle
nnoremap <C-d>         <C-d>M

[Tip] For capital letter key bindings press the shift key with your left hand and the letter with the right hand.

Here is an example of how those movements look like in action:

vim vertical movements


Popular posts from this blog

How to setup NeoVim configuration file

WebAssembly (Wasm): Fixing the Flaws of Applets

How to query Outlook from PowerShell