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?
You could just do a quick :saveas! file1 and :saveas! file2 in the respective buffers to set things right, but of course you have autoread enabled, so correcting the file in one buffer will cause the other copy in the second buffer to be immediately lost!1
The solution is a quick :0f away: it’s a shortcut for :filename "" that clears the association between the buffer and the underlying file, leaving the contents in the buffer unchanged but severing the link with the underlying inode, meaning when after you do :0f in one buffer, you can swap back to the other and save it to the correct path without risking the other buffer’s contents from being lost, as its been dissociated from the underlying file. Then you can go back to the now-unnamed buffer and save it to correct path too, and all will be well.
Yes, of course you can undo the
autoreadand then:saveasagain, but do you really want to be taking that risk with your hours of work? ↩
![:0file :0f[ile][!] Remove the name of the current buffer. The optional ! avoids truncating the message, as with :file. :buffers :files :ls List all the currently known file names. See windows.txt :files :buffers :ls.](https://neosmart.net/blog/wp-content/uploads/2026/01/vim-help-0f.webp)