I Can’t Believe I Didn’t Know Ctrl + o in Vim
Aug. 2, 2025 by John Rei Enriquez
Working in vim, when I add a new class or function and I need to import it while in the middle of a file, I’d instinctively hit gg to jump to the top of the file, add the import, then think - Wait, how do I get back to where I was again?
Most of the time, I just move the cursor over the new import and hit * to go to the next occurence or /search for the function or class name I just imported. These always felt like I am doing more than 2 steps just to go back.
Other times (when I feel like being smart), I use marks.
I would mark my spot before jumping away:
ma " mark current line as 'a'
gg " go to top of file
'a " return to mark a
It works great! But the problem is remembering to do it. What always happens is I’d already be at the top of the file when I remember it. No marks to go back to
90% of the time I just hit / and go search for the new imported thing or a text I know exists in the section I was working at before. This works but it always felt like it was a workaround...
until I discovered CTRL + o.
This command changed everything and now I have something that felt natural and intuitive.
Here’s how I work now:
- gg to jump to top, add the import
- CTRL + o to jump back to where I was
It’s like time travel for your cursor. 🤯
Even better? It works across files and buffers — as long as I stay in the same window! 🤯🤯
Notes:
CTRL + o: jump backward in the jump list
CTRL + i: jump forward in the jump list
Vim automatically tracks cursor movements in what's called the jump list.
TLDR: If you're not already using CTRL + o in Vim/Neovim, start now! Your future self will thank you.