-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
is_vim
does not detect vim running in a subshell
#295
Comments
Hey John 👋. Well, this is certainly a fun one. I'll be honest that I don't have a great grasp of the
Hopefully something in there will help you get back to working. |
Hi, Chris! Sadly, no, both of those don't work. Through a bit more digging, I found |
Hi, I'm also running into this issue. It seems like I thought one possible solution would be something like https://stackoverflow.com/a/52544126 which constructs a process tree from a command like what John mentioned above This approach could be used to get all child processes running in Wondering if this sounds like a reasonable way to avoid false positives in the full ps list? |
Following up on this - a temporary fix for anyone having this issue is to do the following:
#!/usr/bin/env bash
# Usage: is_vim.sh <tty>
# tty: Specify tty to check for vim process.
tty=$1
# Construct process tree.
children=();
while read -r pid ppid; do
[[ -n $pid && pid -ne ppid ]] && children[ppid]+=" $pid"
done <<< "$(ps -e -o pid= -o ppid=)"
# Get all descendant pids of processes in $tty with BFS
idx=0
IFS=$'\n' read -r -d '' -a pids < <(ps -o pid= -t $tty && printf '\0')
while (( ${#pids[@]} > idx )); do
pid=${pids[idx++]}; pids+=( ${children[pid]-} )
done
# Check whether any child pids are vim
ps -o state= -o comm= -p "${pids[@]}" | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'
exit $?
@christoomey I'm happy package this in a PR, but wasn't sure if it was preferable to include the bash script as a separate file or to wrestle with multi-line string escaping inside the tmux file itself. |
UPDATE I found some time to wrestle with tmux's string escaping -- here is a more concise solution that is a drop in for the
It does the same thing as the shell script above - a quick explanation line by line:
For those using this workaround, I'm hoping this approach is more easily adaptable to future updates to the
|
@christoomey - would you be open to merging this upstream? A lot of our users at Fig would like this to be fixed! |
Hi @brendanfalk - apologies for the radio silence here. I've been mulling it over and am hesitant to make a change of this magnitude to the core functionality. That said, since this change lives in the |
@christoomey thanks for getting back! Totally understand the concerns about pushing changes that could affect all users. Would you be open to having a chat with me + Sean about the implementation? We've triple checked it and really do think it is just as performant and stable as before, but gives the additional functionality we need to get Fig working. What happens is people who have vim-tmux-navigator download Fig and it just doesn't work... And most of the time they don't realise it's a conflict between our tools, rather, just assume Fig doesn't work at all. So even if we were in the your troubleshooting documentation, unfortunately I just don't think users would even think to look there. Open to discussing some other methods like setting an environment variable that makes the change. Or we'd be happy to write a bunch of tests! |
I can't get this to work in tmux 3.2a on Ubuntu 22.04. I'm not sure how to debug it? I think I also ran into an intermittent bug with the old is_vim.sh (I was getting errors from ps about malformed PIDs in the list, and they seemed to have whitespace in them?). For now, I've got a modified version of this inline script working as is_vim.sh: #!/usr/bin/env bash
# Usage: is_vim.sh <tty>
# tty: Specify tty to check for vim process.
tty=$1
# Construct process tree.
children=();
pids=( $(ps -o pid= -t $tty) )
while read -r pid ppid
do
[[ -n pid && pid -ne ppid ]] && children[ppid]+=" $pid"
done <<< "$(ps -Ao pid=,ppid=)"
# Get all descendant pids of processes in $tty with BFS
idx=0
while (( ${#pids[@]} > idx ))
do
pid=${pids[idx++]}
pids+=( ${children[pid]-} )
done
# Check whether any child pids are vim
ps -o state=,comm= -p "${pids[@]}" | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'
exit $? |
Here's another approach based on #201
function! s:set_is_vim()
call s:TmuxCommand("set-option -p @is_vim yes")
endfunction
function! s:unset_is_vim()
call s:TmuxCommand("set-option -p -u @is_vim")
endfunction
augroup tmux_navigator_is_vim
au!
autocmd VimEnter * call s:set_is_vim()
autocmd VimLeave * call s:unset_is_vim()
if exists('##VimSuspend')
autocmd VimSuspend * call s:unset_is_vim()
autocmd VimResume * call s:set_is_vim()
endif
augroup END
bind -n C-h if-shell -F "#{@is_vim}" "send-keys C-h" "select-pane -L"
bind -n C-j if-shell -F "#{@is_vim}" "send-keys C-j" "select-pane -D"
bind -n C-k if-shell -F "#{@is_vim}" "send-keys C-k" "select-pane -U"
bind -n C-l if-shell -F "#{@is_vim}" "send-keys C-l" "select-pane -R"
bind -n C-\\ if-shell -F "#{@is_vim}" "send-keys C-\\" "select-pane -l" The key advantages are:
|
I think this is potentially racy if you move from one tmux split to another and have vim open in both? |
@brendanator thanks for your approach - works well for me. For the bindings, the For context, Here's a related issue and a proposed solution / workaroud on the tmux repo for the unquoted key binding: tmux/tmux#1827 (comment) Here are the quoted key bindings I'm using, which are working nicely: bind -n 'C-h' if-shell -F "#{@is_vim}" "send-keys C-h" "select-pane -L"
bind -n 'C-j' if-shell -F "#{@is_vim}" "send-keys C-j" "select-pane -D"
bind -n 'C-k' if-shell -F "#{@is_vim}" "send-keys C-k" "select-pane -U"
bind -n 'C-l' if-shell -F "#{@is_vim}" "send-keys C-l" "select-pane -R"
bind -n 'C-\' if-shell -F "#{@is_vim}" "send-keys 'C-\\'" "select-pane -l" |
See christoomey#295 (comment) for details.
If there is someone out there who also needs to have support for fzf the only change you need to do is on the regex. Just add an extra
|
This reverts commit 7ffe1f2. I'm removing Fig because it caused issues with vim-tmux-runner [1] [2] [3]. The founders of Fig are trying to work with Chris Toomey to find a solution though [3], so I could get it working if I really wanted to I bet. For now, I'm just going to remove Fig; vim and tmux navigation is more important. The thing that attracted me to Fig was the command line autocomplete, but I'm not sure that's worth the cost. Fig does a lot more than I actually want it to, and it seems to be a fairly complex tool. Dealing with it doesn't seem worth the value it would create for me. I'll pass. [1]: christoomey/vim-tmux-navigator#339 [2]: christoomey/vim-tmux-navigator#317 [3]: christoomey/vim-tmux-navigator#295
This reverts commit f306816. I'm removing Fig because it caused issues with vim-tmux-runner [1] [2] [3]. The founders of Fig are trying to work with Chris Toomey to find a solution though [3], so I could get it working if I really wanted to I bet. For now, I'm just going to remove Fig; vim and tmux navigation is more important. The thing that attracted me to Fig was the command line autocomplete, but I'm not sure that's worth the cost. Fig does a lot more than I actually want it to, and it seems to be a fairly complex tool. Dealing with it doesn't seem worth the value it would create for me. I'll pass. [1]: christoomey/vim-tmux-navigator#339 [2]: christoomey/vim-tmux-navigator#317 [3]: christoomey/vim-tmux-navigator#295
Hey, thanks a bunch for the solution! I just implemented it and it largely fix vim split navigation. The only issue I'm seeing is that if I split nvim horizontally, I can move down a split but not back up. |
- remove: Fig integration - was conflicting with vim-tmux-navigation - ref: withfig/fig#460 - possible solution here: christoomey/vim-tmux-navigator#295 (comment) - will come back to this later... - set: a default editor - add: some aliases
- remove: Fig integration - was conflicting with vim-tmux-navigation - ref: withfig/fig#460 - possible solution here: christoomey/vim-tmux-navigator#295 (comment) - will come back to this later... - set: a default editor - add: some aliases
I have a project where I am working in Python. I'm using
pipenv
to manage the environment, which has a feature where if you runpipenv shell
it starts a subshell with everything set up right for the environment. This starts a new TTY.However, that means that
ps ... -t "#{pane_tty}"
returns the "wrong" process list. It returnsBut just
ps
alone returns (and you can seevim
running inside/dev/ttys002
)The end result is that the
is_vim
clause in the pane-switching bindings doesn't return true, so it doesn't send the keys to vim, even though it's the program in the foreground.I'm not really sure how to fix this, since apparently OSX's
ps
can't show the lineage of processes to know thatvim
is, in fact, running as an (eventual) sub-process in/dev/ttys001
.The text was updated successfully, but these errors were encountered: