0

Is it possible to link the cwd of vim to the cwd of the shell running it, or change the cwd of the parent shell within vim?

I run neovim+tmux with the tmux-resurrect plugin, and it would be nice if I could restore the neovim session associated with the cwd of all the saved tmux session panes/windows upon executing the resurrect restore command. However, the cwd of the shell running neovim is separate from the cwd of the neovim instance. I would like to create an autocommand that triggers on the event DirChanged to accomplish this, but I'm not sure how or if it's even possible to do that.

Thanks!

2
  • In general child processes can't affect parent processes like that (change working directory or environment variables, etc.) - not without the cooperation of the parent process anyway. So, e.g., you could have neovim write the current directory to some file and configure the shell to change to to whichever directory is listed in that file. Commented Mar 15, 2023 at 3:28
  • On a Linux box, you can usually query the proc pseudo-filesystem (commonly mounted at /proc) about process-related information. For example, you can try to change cwd to the parent process's cwd in Vim as follows: (1) :let b:ppid = split(readfile('/proc/self/stat', '', 1)[0])[3], (2) :exec 'lcd /proc/'. b:ppid .'/cwd'. See the manual page of proc(5). Commented Mar 15, 2023 at 19:37

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.