Collection of useful vim tips and vim features I've learned over the years
If you are working inside of a JSON file, you can autoformat it by using Python's built-in json module.
Running this command:
:%!python3 -m json.tool --sort-keys
will automatically format and alphabetize the JSON file in your current buffer. I have this line in my vim config to easy run this:
command! JSON %!python3 -m json.tool --sort-keys
Vim comes with a built-in program called vimdiff
which can be used inside vim
with the :diffthis
command.
I use it like this: I have two json files that are slightly different, but I want
to find out where. I open each file in a split buffer, then in I type
:windo diffthis
and voila! I have a diff inside my editor showing where the two
file diverge. The :windo
command
runs diffthis
on all open buffers in the current window.
Example: