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

How do I jump back to the exact cursor position from my last Vim session?

Answer

`0

Explanation

Vim automatically saves your cursor position when you exit, storing it as the 0 mark in the viminfo file (or shada file in Neovim). Running `0 in a fresh session opens the file you were last editing and jumps straight to the exact line and column — no manual bookmarking required.

How it works

  • When you exit Vim, the current position is written as mark 0 in viminfo/shada
  • `0 (backtick zero) jumps to that saved line and column, opening the file if necessary
  • Vim maintains a rolling history: `1 through `9 hold positions from the previous nine sessions
  • This works across files — Vim will switch to or open the correct file automatically

Example

You edit src/app.js at line 87, column 12, then close Vim. The next day you open Vim (on a different file or with no arguments). Type:

`0

Vim opens src/app.js and positions the cursor at line 87, column 12 exactly where you left off.

To see all saved positions:

:marks 0123456789

Tips

  • '0 (apostrophe, not backtick) jumps to the correct line but column 0 (first non-blank)
  • `1`9 let you browse your session history — useful if you've been working across multiple projects
  • If the file has been deleted or moved, the mark silently fails
  • Requires viminfo to be configured (default in Vim: :set viminfo?; Neovim always uses shada)

Next

How do I enable matchit so % jumps between if/else/end style pairs?