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

How do I jump back to where I last inserted text and continue typing?

Answer

gi

Explanation

The gi command moves the cursor to the position where you last exited insert mode and immediately enters insert mode again. This saves you from manually navigating back to your previous editing spot and pressing i — it combines both actions into a single two-key command.

How it works

  • gi jumps to the '^ mark (the position where insert mode was last stopped) and enters insert mode
  • It remembers the exact line and column where you pressed <Esc> or otherwise left insert mode
  • The position is tracked per-buffer, so each file remembers its own last insert location
  • If you haven't entered insert mode yet in the current buffer, gi inserts at the beginning of the first line

Example

You are typing a function body on line 25:

function process(data) {
    let result = |
}

You realize you need to check something at the top of the file. Press <Esc>, navigate to line 1 with gg, read what you need, then press gi. Your cursor jumps back to line 25, right after result = , and you are in insert mode ready to continue typing.

Without gi, you would need to press <C-o> or '' to jump back, then find the exact column and press i or a — multiple steps instead of one.

Tips

  • gi is different from g;g; jumps to the last change position but stays in normal mode, while gi jumps to the last insert position and enters insert mode
  • The '^ mark that gi uses is set every time you leave insert mode — it always points to the most recent insert location
  • Use gi when you need to briefly check something elsewhere in the file (a variable name, an import, a type definition) and then return to continue typing
  • If you need to check something without leaving insert mode at all, use <C-o> which lets you execute a single normal mode command and then returns to insert mode automatically
  • gi is one of the most efficient "resume work" commands in Vim — it combines navigation and mode switching into a single action
  • Combine with global marks for cross-file workflows: set a global mark with mA, navigate to another file, then come back with 'A and use gi to resume editing

Next

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