在多进程操作系统中,子进程无法更改父进程中的任何内容。但是父进程可以合作,因此子进程可以要求父进程为子进程做一些事情。在您的情况下,退出vim时应返回最后一个工作目录,并且外壳程序应cd返回该目录。我设法通过以下方式实施合作:
在~/.vimrc:
call mkdir(expand('~/tmp/vim'), 'p') " create a directory $HOME/tmp/vim
autocmd VimLeave * call writefile([getcwd()], expand('~/tmp/vim/cwd')) " on exit write the CWD to the file
Run Code Online (Sandbox Code Playgroud)
在~/.bashrc:
call mkdir(expand('~/tmp/vim'), 'p') " create a directory $HOME/tmp/vim
autocmd VimLeave * call writefile([getcwd()], expand('~/tmp/vim/cwd')) " on exit write the CWD to the file
Run Code Online (Sandbox Code Playgroud)