Much too often my Linux box gets plugged off with lots of open vim sessions. To continue my work I have to open all files and decide whether to continue with the saved file or with the swap file. I use

for file in $(find ~/git -name *.swp); do
  gvim "$(echo $file | sed 's/.swp$//;s_/\._/_')"

which does what I want (yes, I prefer separate instances of gvim over one instance with multiple buffers, and yes, theoretically this could fail for certain path names I don't have in real life), but is a nasty way to script it.

I'd rather do something like

find ~/git -name *.swp -exec gvim -r {} \;

but this doesn't leave me the decision whether the the saved or the recovery version is the one to continue with.

Can you think of some other more straight-forward way to reach my goal?

  • What is gvim? – 123 Nov 3 '17 at 14:27
  • A "graphical" vim instance, running on your X11 desktop, instead of in a terminal emulator. – Thomas N Nov 3 '17 at 14:31
  • Tangentially related to your question: you might find this plugin useful. – Satō Katsura Nov 3 '17 at 14:49

You've got one gvim command with no options where you manipulate the filename, and one gvim -r where you're passing the swap file.

If you like what the for loop does, try this (which is a bash-only version):

find ~/git -name *.swp -exec bash -c 'f=${1%.swp}; f=${f/\/./\/}; gvim "%f"' x {} \;

Passing the "x" to bash sets $0 to "x", so the find {} placeholder becomes $1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.