Skip to content
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

Not Working as Expected with Lazyvim #15

Closed
Josh-Piper opened this issue Jul 13, 2023 · 5 comments
Closed

Not Working as Expected with Lazyvim #15

Josh-Piper opened this issue Jul 13, 2023 · 5 comments

Comments

@Josh-Piper
Copy link

Josh-Piper commented Jul 13, 2023

https://www.reddit.com/r/neovim/comments/14yer8w/neovimtmux_navigation_plugin_with_lazyvim_not/

Hi,

I am trying to install the plugin https://github.com/alexghergh/nvim-tmux-navigation so I can easily switch between Tmux panes and Neovim panes. I am using the default lazyvim installation plus the additions I have mentioned https://www.lazyvim.org/installation

Currently, I am able to use ctrl+hjkl to move between neovim panes using the current setup in a normal session without tmux.

BUT

During a tmux session, I am only able to move between the tmux panes and not to/between the neovim sessions.

So this implementation that I have seems to not be working on the tmux side since the NvimTmux commands are executing as expected. I was hoping I could be pointed in the right direction towards fixing this tmux issue.


lua/plugins/tmux.lua

return {
  "alexghergh/nvim-tmux-navigation",
  event = "VeryLazy",
  config = function()
    local nvim_tmux_nav = require("nvim-tmux-navigation")
    nvim_tmux_nav.setup({
      disable_when_zoomed = true,
      -- defaults to false
      keybindings = {
        left = "<C-h>",
        down = "<C-j>",
        up = "<C-k>",
        right = "<C-l>",
        last_active = "<C-\\>",
        next = "<C-Space>",
      },
    })
  end,
}
lua/config/keymap.lua

vim.keymap.set("n", "<C-h>", "<Cmd>NvimTmuxNavigateLeft<CR>", { silent = true })
vim.keymap.set("n", "<C-j>", "<Cmd>NvimTmuxNavigateDown<CR>", { silent = true })
vim.keymap.set("n", "<C-k>", "<Cmd>NvimTmuxNavigateUp<CR>", { silent = true })
vim.keymap.set("n", "<C-l>", "<Cmd>NvimTmuxNavigateRight<CR>", { silent = true })
vim.keymap.set("n", "<C-\\>", "<Cmd>NvimTmuxNavigateLastActive<CR>", { silent = true })
vim.keymap.set("n", "<C-Space>", "<Cmd>NvimTmuxNavigateNavigateNext<CR>", { silent = true })
~/.tmux.conf

set -g default-terminal "screen-256color"

set -g prefix C-a
unbind C-b
bind-key C-a send-prefix

unbind %
bind | split-window -h 

unbind '"'
bind - split-window -v

unbind r
bind r source-file ~/.tmux.conf

bind -r j resize-pane -D 5
bind -r k resize-pane -U 5
bind -r l resize-pane -R 5
bind -r h resize-pane -L 5

bind -r m resize-pane -Z

set -g mouse on

set-window-option -g mode-keys vi

bind-key -T copy-mode-vi 'v' send -X begin-selection # start selecting text with "v"
bind-key -T copy-mode-vi 'y' send -X copy-selection # copy text with "y"

unbind -T copy-mode-vi MouseDragEnd1Pane # don't exit copy mode when dragging with mouse

# remove delay for exiting insert mode with ESC in Neovim
set -sg escape-time 10

# tpm plugin
set -g @plugin 'tmux-plugins/tpm'

# list of tmux plugins
# set -g @plugin 'christoomey/vim-tmux-navigator'
# THIS IS WHERE THE NEW CODE FOR NAVIGATION IS
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"

bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L'
bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D'
bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U'
bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R'

tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'

if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
    "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\'  'select-pane -l'"
if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
    "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\'  'select-pane -l'"

bind-key -n 'C-Space' if-shell "$is_vim" 'send-keys C-Space' 'select-pane -t:.+'

bind-key -T copy-mode-vi 'C-h' select-pane -L
bind-key -T copy-mode-vi 'C-j' select-pane -D
bind-key -T copy-mode-vi 'C-k' select-pane -U
bind-key -T copy-mode-vi 'C-l' select-pane -R
bind-key -T copy-mode-vi 'C-\' select-pane -l
bind-key -T copy-mode-vi 'C-Space' select-pane -t:.+


# END FANCY STUFF <---------

set -g @plugin 'jimeh/tmux-themepack'
set -g @plugin 'tmux-plugins/tmux-resurrect' # persist tmux sessions after computer restart
set -g @plugin 'tmux-plugins/tmux-continuum' # automatically saves sessions for you every 15 minutes

set -g @themepack 'powerline/default/cyan'

set -g @resurrect-capture-pane-contents 'on'
set -g @continuum-restore 'on'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
@Josh-Piper Josh-Piper changed the title Not Working as Expected with Lazy Not Working as Expected with Lazyvim Jul 13, 2023
@Josh-Piper
Copy link
Author

Could it be that I am using MacOS? Would that result in the grep and sed having an unexpected outcome for the tmux?

@alexghergh
Copy link
Owner

Hello, mind sharing what the problem was so I can potentially fix/improve the code? Was it the issue mentioned in your last comment?

@Josh-Piper
Copy link
Author

Like your readme mentioned, I went into the original author's repository and went through their debugging process, and noticed the vim process wasn't appearing when running : TmuxNavigatorProcessList.

It mentioned that Figterm was being used instead, so it turned out a workaround script was needed.

Original issue was related to using Fig.

christoomey/vim-tmux-navigator#339

@finomayato
Copy link

Probably worth including the Lua/lazy configuration for plugin keymaps in README.md. It would've saved me some time and likely will for others.

@alexghergh
Copy link
Owner

Included the above issue in the README file as a FAQ sub-point. Conversation might be relevant to other users.

Thanks for mentioning it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants