恢复vim会话我不小心断开了

我今天遇到了一个不寻常的问题,

我正在使用vim,在bash中创建了一个新的别名,并想尝试一下。

所以我ctrl- zexec bash (我这样做是因为我不喜欢用bash嵌套它)。

我的工作已经结束了。 我现在无法恢复vim。

我能想到的唯一选择是杀死vim并开始一个新的会话。

 vim 

ctrlz

 exec bash fg 

编辑 :这与使用screen / tmux 无关

考虑reptyr

 NAME reptyr - Reparent a running program to a new terminal SYNOPSIS reptyr PID 

使用pidof vimps aux | grep vim查找vim的进程ID ps aux | grep vim

如果您尝试打开仍由vim打开的文件,也可以查看进程ID。 使用显示的pid,您应该能够重新连接到之前的会话。

如果您收到错误:

 Unable to attach to pid 12345: Operation not permitted 

确保ptrace scope设置为0 (而不是1 ):

 echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope 

运行reptyr ,您可能必须按Enter键或其他键才能刷新终端(控制台)窗口。

vim -r {file}是你想要的,“r”代表“恢复模式”。 见man vim

 Recovery mode. The swap file is used to recover a crashed editing session. The swap file is a file with the same filename as the text file with ".swp" appended. See ":help recovery". 

您将需要使用“屏幕”或“tmux”实用程序之类的东西来保持终端会话在后台运行。