]> git.phdru.name Git - dotfiles.git/commitdiff
Feat: On exit from `vim` do `cd` to its last working directory
authorOleg Broytman <phd@phdru.name>
Fri, 28 Oct 2022 15:07:46 +0000 (18:07 +0300)
committerOleg Broytman <phd@phdru.name>
Fri, 28 Oct 2022 15:07:46 +0000 (18:07 +0300)
.shellrc
.vimrc

index 892921c6beb5cbcc383929c5a5f0ddbf41456f7f..3e238bd5546ca21863eae260caee660686c47598 100644 (file)
--- 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 19b63289e72cb20ea35bebd0771015fc71ac503c..49702499dac2c1078a8f7ec7776b7e819ed4ffe1 100644 (file)
--- 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