From 9c24f5210ec5ebca94688aa195a1ee6a07d7d0e5 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Fri, 28 Oct 2022 18:07:46 +0300 Subject: [PATCH] Feat: On exit from `vim` do `cd` to its last working directory --- .shellrc | 8 ++++++++ .vimrc | 2 ++ 2 files changed, 10 insertions(+) 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 -- 2.39.5