From: Oleg Broytman Date: Fri, 28 Oct 2022 15:07:46 +0000 (+0300) Subject: Feat: On exit from `vim` do `cd` to its last working directory X-Git-Url: https://git.phdru.name/?p=dotfiles.git;a=commitdiff_plain;h=9c24f5210ec5ebca94688aa195a1ee6a07d7d0e5 Feat: On exit from `vim` do `cd` to its last working directory --- diff --git a/.shellrc b/.shellrc index 892921c..3e238bd 100644 --- a/.shellrc +++ b/.shellrc @@ -165,6 +165,14 @@ if which tmux >/dev/null 2>&1; then fi +vim() { + command vim "$@" + rc=$? + cd "`cat \"$HOME/tmp/vim/cwd\"`" && rm "$HOME/tmp/vim/cwd" && + return $rc +} + + if [ "$SHLVL" -eq 1 ] && which startx >/dev/null 2>&1; then X() { startx >> .Xserver.log 2>&1; cyr; rm -f .Xauthority; } fi diff --git a/.vimrc b/.vimrc index 19b6328..4970249 100644 --- a/.vimrc +++ b/.vimrc @@ -856,5 +856,7 @@ if v:version >= 800 call timer_start(500, 'SetLazyRedraw') endif +autocmd VimLeave * call writefile([getcwd()], expand('~/tmp/vim/cwd')) + " This has to go to the very end of ~/.vimrc to allow reading the .vimrc set secure " safer working with script files in the current directory