tmux-resurrect icon indicating copy to clipboard operation
tmux-resurrect copied to clipboard

Neovim instances do not get resurrected with tmux 3.2

Open mroavi opened this issue 3 years ago • 12 comments

Neovim instances do not get restored with tmux 3.2 while vim instances do. Here is a demo that shows this:

Peek 2021-08-06 16-35_tmux-resurrect-bug-with0tmux3 2

Tested on: OS: Manjaro Linux x86_64 Kernel: 5.10.53-1-MANJARO Shell: zsh 5.8 Terminal: alacritty 0.8.0 (a1b13e68)

mroavi avatar Aug 06 '21 14:08 mroavi

I confirm this issue also on Arch Linux. neovim v0.5.0 + kitty terminal.

cartesius82 avatar Aug 23 '21 19:08 cartesius82

Same here wsl2 + Ubuntu 20.04 + neovim v0.5.0 + windows terminal

Odas0R avatar Sep 10 '21 02:09 Odas0R

I am losing my nvim only on restart. Works great if I close terminal and re-resurrect. On Debian 11, neovim, xfce terminal

norogoth avatar Dec 02 '21 17:12 norogoth

May be related to my issue #421. It may be due to folders being deleted in /tmp

norogoth avatar Dec 03 '21 15:12 norogoth

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 avatar Mar 25 '22 21:03 camgraff

@camgraff Thanks! I'll have to take a look!

norogoth avatar Mar 26 '22 14:03 norogoth

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.

Restoring Programs

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 avatar Apr 21 '22 19:04 spywhere

@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.

skogsbrus avatar Jun 19 '22 17:06 skogsbrus

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

SerhatTeker avatar Aug 23 '22 15:08 SerhatTeker

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

mikeslattery avatar Sep 25 '23 16:09 mikeslattery

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

SamuelCano03 avatar Jan 09 '24 19:01 SamuelCano03

Any chance someone has the know-how to upstream a fix? I love this plugin, but not having neovim restore is a real bummer.

AThilenius avatar Feb 20 '24 02:02 AThilenius