I often forget to sudo vim. I make significant changes to the file just to find out that I don’t have permissions to save the file.

Well, now that I’ve memorized this little gem it doesn’t matter:

:w! sudo tee %

The % is a shortcut for the filename. You are really just piping the output through tee to the file - effectively overwriting the contents.

Ta-dah!