vimtricks.wiki Concise Vim tricks, one at a time.

How do I show both the absolute line number on the current line and relative numbers on all other lines?

Answer

:set number relativenumber

Explanation

Enabling both number and relativenumber simultaneously activates hybrid line numbering: the current line displays its true absolute line number while every other line shows its distance from the cursor. This combines the best of both worlds — you always know exactly where you are, and you can jump with precise counts like 5j or 12k without mental arithmetic.

How it works

  • set number — display absolute line numbers in the gutter
  • set relativenumber — display line numbers as offset from the cursor
  • When both are set at the same time, Vim uses absolute for the current line and relative for all other lines
  • Turning off either option reverts to standard behavior

Example

  10  fn main() {          ← cursor is here (absolute: 10)
   1      println!("hi");  ← 1 line away
   2  }                    ← 2 lines away
   3                       ← 3 lines away
   4  fn helper() {        ← 4 lines away

To jump to the println! line from the cursor: 1j. To jump to helper(): 4j.

Tips

  • Add both to your vimrc to make it permanent: set number relativenumber
  • Toggle relative numbers quickly with a mapping: nnoremap <leader>r :set relativenumber!<CR>
  • In Neovim Lua config: vim.opt.number = true; vim.opt.relativenumber = true
  • Some plugins like :winfixbuf windows benefit from norelativenumber — use autocmd InsertEnter * set norelativenumber to disable during insert mode

Next

How do I prevent Vim from automatically resizing a window when others open or close?