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

How do I jump back to my previous cursor position?

Answer

<C-o>

Explanation

The <C-o> (Ctrl+o) command jumps the cursor backward through the jump list, returning you to previous cursor positions. This is one of the most powerful navigation commands in Vim, letting you retrace your steps after jumping to a different part of the file or even a different file.

How it works

  • <C-o> moves backward through the jump list (older positions)
  • <C-i> (or <Tab>) moves forward through the jump list (newer positions)
  • The jump list records positions whenever you make a "jump" — a large cursor movement like G, gg, /pattern, *, %, (, ), {, }, or switching files

Example

You are editing on line 10 of a file. You press G to jump to the end of the file to check something. Now you want to return to line 10.

Press <C-o> and the cursor jumps right back to line 10 where you were before.

Viewing the jump list

To see your full jump history, use the :jumps command. It shows each jump point with its line number, column, and file.

:jumps

Tips

  • Use <C-i> to move forward through the jump list (the opposite of <C-o>)
  • Small motions like j, k, w, b, e do not create jump list entries
  • Use '' (two single quotes) to jump between the current position and the last jump position
  • Use . (backtick period) to jump to the position of the last edit
  • Use 3<C-o> to jump back three positions at once
  • The jump list works across files — you can jump back to a different buffer entirely
  • Vim stores up to 100 entries in the jump list; use :clearjumps to reset it

Next

How do I edit multiple lines at once using multiple cursors in Vim?