RedditPP Mascot

RedditPP

r/vim • … • u/CodyChan

How to view vim's .swap file without using vim?

There is one problem annoying me for a long time, and I googled a while and failed, so I came here.

Most of time I'm an Emacs user, but when I need to modify one file or two or system configuration files or especially, files from remote machine, I usually use vim.

But for some reason, I lost the screen of vim or that vim process doesn't exist anymore, a .swap file exists in that directory, when I use vim to edit it again, vim will warn me that there is .swap file and ask to deal with it. The thing is, there is no diff command to show the differences (currently unable to install any vim plugins).

In Emacs, it will create a plain text file such as filename~ and I can check the content using other tools like less or vim, and I can also use diff tool to show the difference between filename and filename~, and then I can recover it from filename~ or just delete it. This is very useful.

I use builtin vim in multiple machines without lots of configuration in .vimrc, so it is not recommended to install any vim plugins.

Two solutions are welcome:

1. check the content or diff the two files in terminal without vim 2. just add several lines in .vimrc so I can change the .swap to plain text such as filename~

— 0