@@ -108,8 +108,12 @@ _vim_pane_id() {
108
108
_tmux_fetch_or_store tmux_vim_pane " $@ "
109
109
}
110
110
111
- _vim_last_dir () {
112
- _tmux_fetch_or_store tmux_vim_last_dir " $@ "
111
+ _vim_cwd () {
112
+ local vim_pane_id=$( _vim_pane_id )
113
+ local vim_pid=$( tmux lsp -F ' #{pane_id}=#{pane_pid}' | \
114
+ grep ^$vim_pane_id = | cut -d= -f2 )
115
+
116
+ lsof -p $vim_pid -a -d cwd -Fn | grep ^n | cut -c 2-
113
117
}
114
118
115
119
# _vim_send_keys [keystrokes...]
@@ -308,7 +312,6 @@ _vim_start() {
308
312
# 0:1.1: [100x88] [history 0/10000, 0 bytes] %2
309
313
# ^^^^^ $tmux_vim_pane pane_id ^^
310
314
_vim_pane_id $( $tmux lsp -a | grep ^$tmux_vim_pane : | grep -o ' %[0-9]\+' )
311
- _vim_last_dir " $PWD "
312
315
313
316
# Swap the panes if necessary. tmux only does right/bottom
314
317
[[ $do_swap == 1 ]] && $tmux swap-pane -D
@@ -332,7 +335,8 @@ tmux_vim() {
332
335
# If we are now in a different directory than $TDIR, we want to make
333
336
# vim switch to this directory temporarily before opening the files.
334
337
# This obviates any relative path computations.
335
- [[ " $PWD " != " $( _vim_last_dir ) " ]] && _vim_op cd " $PWD "
338
+ local vim_cwd=$( _vim_cwd )
339
+ [[ " $PWD " != " $vim_cwd " ]] && _vim_op cd " $PWD "
336
340
337
341
# Rather than :edit each file in turn, use :badd for all but the last
338
342
# file, and then use :edit on that.
@@ -350,7 +354,7 @@ tmux_vim() {
350
354
351
355
_vim_op edit " $1 "
352
356
353
- [[ " $PWD " != " $( _vim_last_dir ) " ]] && _vim_op cd -
357
+ [[ " $PWD " != " $vim_cwd " ]] && _vim_op cd -
354
358
fi
355
359
356
360
$tmux select-pane -t $( _vim_pane_id )
0 commit comments