ham*_*066 10 vim remote-access process
我今天遇到了一个不寻常的问题,
我正在使用 vim,在 bash 中创建了一个新别名,并想尝试一下。
所以我 ctrl- z, exec bash
(我这样做是因为我不喜欢用 嵌套它bash
)。
而我的工作也没有了。我现在无法恢复vim。
我能想到的唯一选择是杀死 vim 并开始一个新会话。
vim
Run Code Online (Sandbox Code Playgroud)
ctrl——z
exec bash
fg
Run Code Online (Sandbox Code Playgroud)
编辑:这与使用 screen/tmux无关。
Tho*_*hor 14
考虑reptyr
:
NAME
reptyr - Reparent a running program to a new terminal
SYNOPSIS
reptyr PID
Run Code Online (Sandbox Code Playgroud)
使用pidof vim
或查找vim 的进程ID ps aux | grep vim
。
如果您尝试打开仍由 vim 打开的文件,也可以查看进程 ID。使用显示的 pid,您应该能够重新连接到之前的会话。
如果出现错误:
Unable to attach to pid 12345: Operation not permitted
Run Code Online (Sandbox Code Playgroud)
确保ptrace scope
设置为0
(而不是1
):
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
Run Code Online (Sandbox Code Playgroud)
运行后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".
Run Code Online (Sandbox Code Playgroud)