What's that Vim trick that blew your mind the first time you learned about it? A feature that has a big (or small) impact on your workflow, or just a command you use a lot. Anything goes! 🤯
I'll start with my go-to trick: I usually only notice a match should be replaced after searching for it with / (/foo). After learning that substitutions with empty search patterns (%:s//bar/) replace the previously found matches, I've never had to re-type a pattern again.
Latest comments (31)
Say you've changed a function signature, like:
and you want to update all the references across all files of a project, you can do this with quickfix +
:cdo:src/directory.This will load all results into a quickfix list.
You can see this list by typing:
This is a simple subsitituion which replaces all references to
add3(toadd(3,and saves the changes.For more information about quickfix lists and what you can do with them, check out the vim docs and feel free to search "vim quickfix" online (lots of good blog posts & youtube videos dive into this feature of vim).
I set up a shortcut to print in my .vimrc.
I run this command to see available printers.
I set a default printer.
In my .vimrc I have this line to print the current file.
To me one of the most usefull features I have discovered is how to manipulate varoius registers type like:
Load a function from the clipboard:
On insert mode, paste any register with
Ctrl-r + Register, for example insert last searchthen space space to switch between two files
NeoVim has a "preview" functionality when you're doing substitutions.
First:
set inccommand=splitThen, enjoy incremental highlighting of the text that will be impacted by any substitutions until you hit [ENTER]:
:%s/foo/bar/gThe operations you can do with the built-in file explorer (aka
netrw):d%DX(upper-case):help netrw-quickhelp<Esc><Esc><Esc>:q!😆cit
Macro! Definitely macro! (Although it is a feature not a trick)
I like to encrypt files sometimes.
vim -x /path/to/file/somefile.txt