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: gv in Vim selects the last visual selection again

Vim
~/tips/tip-vim-gv-reselect

gv

Brings back your previous selection to work on it again.

You select a block, run something on it, and then realise you need to do one more thing to the same lines. Selecting them again by hand isn’t needed.

gv

gv starts visual mode with the same area, and the same type of selection, as the last time. That includes line selections with V and blocks with Ctrl-v.

A pattern that works well: indent a block with >, which drops you out of visual mode, then press gv and > again for a second level. Or sort the selection and then run a substitute on exactly those lines:

:'<,'>sort
gv
:s/^/  /

The '< and '> marks that Vim puts in front of the command are the same start and end that gv uses, so you can also type them yourself in any later command.

Inside visual mode, gv swaps the current selection with the previous one, which I find handy when you have two areas to compare.

If the lines changed in between, for example because a filter added or removed some, the remembered area is still the same line numbers. It may no longer cover what you meant, so check before you run something destructive on it.

Further reading: Vim help: gv

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