Don't change alternate file in Vim

It seems that in Vim :read <file> command (used for inserting other file’s contents below the cursor in current buffer) changes alternate file to the inserted one (you can jump between current and alternate file with C-^ or C-6, which is super handy). It’s not obvious and in my opinion it breaks the rule of least astonishment, because I totally didn’t ask Vim to do anything outside of a current buffer (and buffer list shown by :ls isn’t even changed and might not contain that file at all). This behaviour complicated my workflow for quickly adding new notes from templates.

Fortunately (TIL) there’s easy fix – or rather workaround – for this. We can prefix any Vim command with :keepalt and this command won’t change alternate file in any way. So :r <file> becomes :keepalt r <file>. Super handy and good to know, especially for making custom functions, plugins etc.