How to (safely) swap the contents of two files opened in (neo)vim buffers

Raise your hand if you’ve been here before: you have file1 open in a vim or neovim buffer and you want to “fork” its contents over to file2, but you need to reference file1 while you do so. So you do the obvious: you open a split buffer with :sp or :vsp, run a quick :saveas file2 then hack away at the file to make the changes you want followed by :w (or whatever shortcut you have mapped to the same) and call it a day… only to realize that you were in the wrong split and that you’ve accidentally switched file1 and file2 around?

Continue reading