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

How do I jump back to where the cursor was when I last left a buffer?

Answer

`"

Explanation

The " mark is an automatic mark Vim sets whenever you leave a buffer — switching to another file, hiding the buffer, or quitting Vim (with viminfo/shada enabled). Pressing `" returns you to the exact line and column from your last visit, so you can pick up exactly where you left off.

How it works

  • Vim automatically updates the " mark each time you exit a buffer
  • `" (backtick + ") jumps to the exact line and column
  • '" (apostrophe + ") jumps to the start of that line
  • With viminfo (Vim) or shada (Neovim) enabled, the position persists across sessions

Example

You're editing server.go with the cursor on line 214. You switch to client.go to check something, then come back. Press:

`"

Vim jumps straight to line 214, column preserved — no searching required.

Tips

  • Add this to your vimrc / init.vim to auto-restore position on every file open:
    autocmd BufReadPost * silent! normal! g'"
    
  • The " mark is distinct from `. (last change position) and `^ (last insert-mode exit)
  • Works across all buffer types: source files, help pages, quickfix, etc.
  • Check all marks for the current buffer with :marks

Next

How do I open the directory containing the current file in netrw from within Vim?