brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: g; in Vim jumps back to where you last changed something

Vim
~/tips/tip-vim-g-semicolon-changelist

`. go to the last change

Jumps back to the places you edited in Vim, newest first.

You make an edit, scroll off to look something up two hundred lines down, and now you have to find your way back. In Vim that’s two keys: g;. Vim remembers a position for every change you can undo, and g; walks back through that list.

g;          go to the previous change
g,          go forward again
:changes    show the change list
`.          go to the last change

Press g; again and you go one change further back, g, takes you the other way. A count works as well: 3g; goes three changes back, and 999g; goes as far back as Vim remembers. Changes you’ve already undone stay in the list, which is handy when you want to see where something used to be.

If you want to see where you would land, :changes prints the list with line and column numbers and the text on that line. The number in the first column is the count you’d type before g; to get there. For just the most recent change, the backtick mark `. does the same job in one go.

Ctrl-O follows the jump list (searches, G, tags), so it also stops at places you only looked at. The change list only cares about where you edited, which is usually what you’re after when you’re lost in a file.

Two things to keep in mind. Several small changes close together on one line count as a single position, so typing in the same spot doesn’t fill the list. And after you delete lines, the remembered position can be a little off from where the change really was.

Further reading: Vim help: changelist

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Vim tips :%s/<Ctrl-r><Ctrl-w>/newname/g /oldname find . -name "*.conf" | vim – vim --clean file.txt :set textwidth=72 All Vim tips (45) All topics

Link