Open doronbehar opened 8 years ago
Hey @Doron-Behar, thanks!
Regarding the issues you're seeing, I'm guessing they're related to the process listing, rather than anything to do with your user settings.
Can you try the first step outlined in the Troubleshooting section to help narrow down?
Interesting.
It also does not work with https://github.com/christoomey/vim-tmux-navigator/pull/117: the script detects that Vim is running, but the actual send-keys c-h
is not handled by Vim?!
You can try it from tmux' command mode (<c-b> :
by default): :send-keys c-h
does nothing, but :send-keys c-w c-h
works.
:send-keys :TmuxNavigateLeft c-m
also works (that's what is mapped to from <c-h>
).
And it's actually only a problem with Neovim (v0.1.3-384-g47d44e0), but not Vim (7.4.1689) for me.
@Doron-Behar Are you using Neovim or Vim? Which version?
The <c-h>
gets interpreted as <bs>
with sudo nvim
..
You can check this after <c-v>
in Neovim's insert/command-line mode: <c-v><c-h>
prints <BS>
for me.
The Neovim issue is https://github.com/neovim/neovim/issues/2048.
@Doron-Behar See https://github.com/neovim/neovim/issues/2048#issuecomment-212135388. Also with Vim, the terminfo might be relevant.
Per @blueyed's comment, this seems to be duplicate of #71, related to an issue with Neovim, and not this plugin directly. I'm going to close this now based on that, but please feel free to comment or reopen if I've missed something.
Sorry for not replying a long time, I use Vim - no Neovim
It might be a similar issue though: c-j does not get through to vim.
Please investigate using c-v, and also by executing the tmux-navigator commands manually.
Ok, Here is my Report: :send-keys c-[hjkl]
from within tmux
as well as :TmuxNavigate*
from within vim
brings me to the correct pane/window. It means vim handles this plugin better compared to neovim right?
Hey @Doron-Behar, sorry for the confusion. I'll reopen this now and hopefully we can sort it out.
I just installed neovim
and tested the same issue with sudo nvim file
. Surprisingly, in contrast of what you said about an opened issue with neovim
, I didn't experience the same problem like with vim.
-- Perhaps it's another good reason to use neovim
and not vim
.
In vim, vim-tmux-navigator looks for the active tmux socket in the TMUX
environment variable. When invoked using sudo, the environment is typically sanitized or reset (via env_reset
in /etc/sudoers
). Therefore, vim invoked via sudo doesn't know that it's in a tmux session, and CTRL+[hjkl] aren't passed onto tmux by vim.
To immediately work around this issue, the TMUX
environment variable should be preserved when starting a root shell or invoking vim as root using sudo. You can preserve the entire environment with:
sudo -E vim
or just the TMUX
environment variable with:
sudo TMUX="${TMUX}" vim
(assuming this is allowed by your machine's /etc/sudoers
configuration).
@smkent Good find.
I wonder why it works for @Doron-Behar with Neovim though.. do you have $TMUX
set in that case?!
I don't think there is much we can do about it, apart from adding something to the README, is there?
I don't think there is much we can do about it, apart from adding something to the README, is there?
sudo sets the SUDO_USER
and SUDO_UID
environment variables. The vim-tmux-navigator vim plugin could be modified to look for the default tmux socket path at /tmp/tmux-${SUDO_UID}/default
. Unfortunately this still isn't a reliable solution, because it assumes 1) the user's tmux socket is in the standard location (tmux allows a different socket path to be specified using -S
) and 2) that the current SUDO_UID
is the original user (invoking sudo within a shell started with sudo overwrites SUDO_USER
and SUDO_UID
).
I think the best solution would just be to mention the workarounds in the README. We could also recommend adding env_keep += "TMUX"
to /etc/sudoers
, but I don't know if that introduces security or compatibility issues.
I don't think there is much we can do about it, apart from adding something to the README, is there?
Still not in the README. Spent quite a while tracking down what seemed to me like an intermittent problem, including adding debug code to the plugin, before it hit me that it was only the sudo vim
windows malfunctioning, then ran across this issue.
Additionally, I would recommend another workaround to be mentioned in the README (which should be suitable for Neovim as well because of https://github.com/neovim/neovim/issues/1716) - Use a plugin such as https://github.com/tpope/vim-eunuch or https://github.com/lambdalisue/suda.vim which provide a :SudoWrite
and :SudoRead
like commands.
@doronbehar the issue being discussed breaks https://github.com/tpope/vim-eunuch that :SudoWrite
is no longer working under neovim. https://github.com/lambdalisue/suda.vim is a work-around, yet user needs to input password each time when saving a file.
I make no argument if this is a good fix for everyone, or if it should be recommended. I make a lot of /usr/local/bin/
"wrappers" for things, so I lean this way. This builds off one of the comments by @smkent
/usr/local/bin/sudo
#!/usr/bin/bash
if [[ -v TMUX ]]; then
/usr/bin/sudo TMUX="${TMUX}" "$@"
else
/usr/bin/sudo "$@"
fi
It obviously requires /usr/local/bin/
be in $PATH
, and before /usr/bin/
. Those with other shells would need to tweak as appropriate, or with older bash
would need to use:
if [[ -z ${TMUX+x} ]]; then
@randomizedthinking I've had this discussion on https://github.com/lambdalisue/suda.vim/pull/3 about the seemingly lack of password cache which was supposed to be fixed in https://github.com/neovim/neovim/pull/8389 which wasn't yet merged.
Great Extension, but I think this small issue is annoying but easy to be fixed.
Let's say I have 2
tmux
panes divided to up and bottom. Consider the following being done on the upper pane:vim -O hello world
I can switch betweenvim
's windows - everything works fine.sudo vim -O hello world
as myself, I can't switch with<C-l>
and<C-h>
betweenvim
's windowssudo su
before), and I runvim -O hello world
, I can switch between vim's windows<C-l>
and<C-h>
but I can't switch totmux
's pane at the bottom.sudo su
orsu root
, I can runzsh --login
andvim -O hello world
and then everything works fine like I'm myself and notroot
.su <myusername>
, I don't have all my environment variables and aliases defined like always but if I run afterwardsvim -O hello world
, I can switch totmux
's pane at the bottom with<C-j>
.