tmux-resurrect
tmux-resurrect copied to clipboard
Neovim instances do not get resurrected with tmux 3.2
Neovim instances do not get restored with tmux 3.2 while vim instances do. Here is a demo that shows this:

Tested on: OS: Manjaro Linux x86_64 Kernel: 5.10.53-1-MANJARO Shell: zsh 5.8 Terminal: alacritty 0.8.0 (a1b13e68)
I confirm this issue also on Arch Linux. neovim v0.5.0 + kitty terminal.
Same here wsl2 + Ubuntu 20.04 + neovim v0.5.0 + windows terminal
I am losing my nvim only on restart. Works great if I close terminal and re-resurrect. On Debian 11, neovim, xfce terminal
May be related to my issue #421. It may be due to folders being deleted in /tmp
I experienced this when using the neovim AppImage.
The issue is that when using the appimage, the save_command ps strategy resolves the nvim command as something like:
/tmp/.mount_nvimBLrhe6/usr/bin/nvim -S
But in order, to succesfully restore the neovim session, it expects the command to just be
nvim -s
@camgraff Thanks! I'll have to take a look!
I have faced the same issue for quite some time and just found out the solution that work for me.
I have my neovim installed through asdf-vm, in which the binary is a shim file that executing the actual version-managed binary in the shim directory it managed.
If I ran which nvim, it will produced /Users/username/.asdf/shims/nvim hence it would not get restored as @camgraff explained above.
To fix the issue, I simply set set -g @resurrect-processes '~nvim' to restore the command with nvim in the full command. Refers to the link below for the full explanation on how it works.
EDIT:
If there are arguments expected to be save, just use set -g @resurrect-processes '"~nvim->nvim *"' to have resurrect also kept the arguments. This should help in case of @SerhatTeker where there are multiple instances of the same process with a different arguments.
@spywhere's suggestion works for me to launch vim, but state is not relaunched automatically (using obsession.vim).
Just using
set -g @resurrect-strategy-vim 'session'
set -g @resurrect-strategy-nvim 'session'
just gives me an empty shell.
I'm using NixOS, so paths are also a bit weird for me.
As @camgraff mentioned that the problem is totally related to /tmp/.mount_nvimXXXXXX/usr/bin/nvim -S.
However I couldn't use @spywhere solution —set -g @resurrect-processes '~nvim', since I'm spinning nvim instances with both -S and -u init.lua like below.
# ~/.local/share/tmux/resurrect/sessions/last
pane session 0 1 :* 0 :/home/user/dir 1 nvim :/tmp/.mount_nvimYGd2jH/usr/bin/nvim -u /home/user/.local/share/lunarvim/lvim/init.lua
pane session 1 1 :* 0 :/home/user/dir 1 nvim :/tmp/.mount_nvimgLpUP0/usr/bin/nvim -S
As a solution, I've added a post-save-hook using sed to clean /tmp/... parts:
resurrect_dir="$XDG_DATA_HOME/tmux/resurrect/sessions"
set -g @resurrect-dir $resurrect_dir
set -g @resurrect-hook-post-save-all 'sed -i "s/\/tmp.*nvim/nvim/" $resurrect_dir/last'
The result will be like:
# ~/.local/share/tmux/resurrect/sessions/last
pane session 0 1 :* 0 :/home/user/dir 1 nvim :nvim -u /home/user/.local/share/lunarvim/lvim/init.lua
pane session 1 1 :* 0 :/home/user/dir 1 nvim :nvim -S
P.S: Also related to https://github.com/LunarVim/LunarVim/issues/1987
I make a workaround that solved it, but it requires Go.
// nvim.go
// A simple wrapper over nvim.appimage.
package main
import (
"os"
"os/exec"
"syscall"
)
func main() {
cmd := exec.Command("nvim.appimage", os.Args[1:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
waitStatus := exitError.Sys().(syscall.WaitStatus)
os.Exit(waitStatus.ExitStatus())
} else {
os.Exit(1)
}
}
}
To install. nvim.appimage must be in your path.
go build nvim.go
cp nvim ~/.local/bin/nvim
I've made the same as @SerhatTeker (but i'm using nvchad instead of lunar vim). This is my related conf in tmux.config:
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @resurrect-hook-post-save-all 'sed -i "s/\/tmp.*nvim/nvim/" /home/samuel/.local/share/tmux/resurrect/last'
I've checked that /home/samuel/.local/share/tmux/resurrect/ is my path to file sessions of tmux-resurrect.
This is the content of last file:
➜ resurrect cat last
pane 0 1 1 :* 1 Lenova :/home/samuel 1 nvim :nvim
window 0 1 :nvim 1 :* bbfd,122x25,0,0,0 :
state 0
If I kill the tmux session (it's the same if you open tmux after restarting), and open it again, the content of neovim sessions don't get restored, only I get a empty sheel.
As you can see, the /tmp/.mount_nvimXXXXXX/usr/bin/nvim path is changed to only nvim. But in @SerhatTeker 's last file there is a -S tag which is not present in mine. Any help?
OS: Ubuntu 22.04 Tmux version: 3.2a
Any chance someone has the know-how to upstream a fix? I love this plugin, but not having neovim restore is a real bummer.