0

Recently my system become unstable because of a mysterious memory leak. As a result I have the Xorg process frequently killed with Out of memory entry in the /var/log/syslog.

To save my vim session in case of crashes I run it within screen.

Unfortunately, after Xorg is killed I am unable to recovery the vim session. The reattached shell is totally messed. So far every time I was trying to exit vim by issuing :qa command at blind. Then with every press of Enter I get prompt in the same line.

I suspect the vim is not running (have to validate it after next crash) since:

  1. despite I issued the :qa command, new vim session warns me about presence of the swap file,
  2. I can see the :qa command in my .bash_history file.

Recovery after close of terminal emulator window works fine.

What (but fixing the memory leak) may I do to preserve my vim session?

Versions: vim - 7.4.52, screen - 4.01.00devel, Ubuntu - 14.04.5

[EDIT] vim is definitively not running after crash - today I found a message ICE default IO error handler doing an exit(), pid = 12810, errno = 11 in the resumed screen window.

abukaj
  • 485
  • See if my post on [vi.se] helps. – muru Feb 14 '17 at 10:45
  • @muru do you mean to bypass the screen when typing into vim's stdin? I will give it a try after next crash - if the vim is still up. – abukaj Feb 14 '17 at 10:50
  • Yes. If Vim is up, then the error message about the swap file will say (still running) next to the Process ID. If not, you can safely go on to recover from swap and then delete it. – muru Feb 14 '17 at 10:52
  • @muru it is the latter case and it works - I would like to accept your answer if you mind to write it. – abukaj Feb 16 '17 at 10:18

1 Answers1

1

If Vim complains about a swap file when opening a file, there are two cases: either it's from another currently running Vim process, or it's from a crashed Vim process.

If it's from a running process, the message will look like so:

E325: ATTENTION
Found a swap file by the name ".foo.swp"
          owned by: muru   dated: Thu Feb 16 15:59:59 2017
         file name: ~muru/foo
          modified: no
         user name: muru   host name: localhost
        process ID: 870 (still running)
While opening file "foo"

Note how it says (still running) next to the process ID. An error due to a crashed Vim's swap file won't have that (except, if by coincidence, another currently running process got that same PID). If it's from a crashed Vim, you can choose to recover from the swap file, and later delete it.

If it's from a currently running Vim process, you can kill it (the swap file will let you recover) or choose to gracefully exit if you don't want a swap file lying around. For the latter option, if you don't have screen or some such way to interact with the Vim process, you can use Python to send key codes to it, as described in another post by me.

muru
  • 207,970