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=split
Then, enjoy incremental highlighting of the text that will be impacted by any substitutions until you hit [ENTER]:
:%s/foo/bar/g
The operations you can do with the built-in file explorer (aka
netrw
):d
%
D
X
(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
Vim has a biult-in file explorer:
:E
I use it to open existing files or just to explore the filesystem through the terminal
:%!python -m json.tool
Auto pretty formats json files :)
Whenever I want to search for the current word, I just type:
and then n or N to navigate through the results.
I have many tricks on at my "init.vim"
I also like "Ctrl-6" to jump to alternate buffer ":%y+" to copy the entire buffer to the clipboard. "gx" to open links. "gv" to reselect. "gi" to start insert at the last inserting point.
On my ~/.zshrc and ~/.bashrc I have
Currently I have an autoloaded zsh function that goes like this:
My favorite Vim trick is Spacemacs 👀
Anywho, macros. I know it sounds a bit basic but boy are they powerful (and they turn heads, both in a technical and non technical setting).