Here are a few useful tricks that are good to be familiar with when using Neovim as your editor. Share in the comments if you have additional tricks!
checkhealth
If you haven’t used the :checkhealth command in Neovim then you should give that a try today.
If you run :checkhealth by itself then you should see a new buffer open with a ton of output about Neovim itself, plugins you have installed, and keymap conflicts you have between plugins if you have WhichKey installed.
If you run :checkhealth <plugin1> and provide a specific plugin then it will run the checkhealth command for just that one plugin. You can also provide multiple plugins to the command that are space separated (e.g. :checkhealth plugin1 plugin2 plugin3).
Additionally, you can run the :checkhealth command against Lua submodules to ensure they are working. Here is an example:
:checkhealth vim.lsp
I’d recommend running :checkhealth regularly, especially after you upgrade plugins to make sure everything is running as expected.
Check out the Neovim docs to know more about health commands.
windo diffthis
Vim and Neovim can be opened up in diffmode by passing the -d option like this:
nvim -d file1 file2
This will open up both files and highlight the differences and fold blocks of code that are the same depending on your config.
If you already have Neovim running and you want to run a diff between two different sets of output or source files then you can use :windo diffthis
.
Just make sure that you have the files open in two different windows (or splits) and Neovim will show a diff of the two windows.
What is happening here is running the diffthis command in each window.
Here is a snippet of what diffthis does:
*:difft* *:diffthis*
:difft[his] Make the current window part of the diff windows. This sets
the options as for "nvim -d".
Removing lines with :g
There are lots of ways to remove lines from your buffer in Neovim.
If you want to do so using a regex pattern and remove all lines that match then you can use this handy shortcut:
:g/<pattern>/d
If you want to remove lines that do NOT match the pattern then you can use this version:
:g!/<pattern>/d
Here are a few other Neovim articles you might be interested in:
If you enjoy topics like this then you might also like my Youtube channel. Have a great day!