Skip to content

Enhance terminal mode navigation in vim-tmux-navigator #430

@francescoVaglienti

Description

@francescoVaglienti

Problem

When using terminal mode (:term) in Vim with vim-tmux-navigator, the Ctrl+h/j/k/l navigation keys don't work properly. This breaks the seamless navigation experience between Vim splits, terminal splits, and tmux panes.

Solution

Add terminal mode mappings that properly handle navigation while preserving terminal state:

tnoremap <C-h> <C-w>:<C-U>TmuxNavigateLeft<cr>
tnoremap <C-j> <C-w>:<C-U>TmuxNavigateDown<cr>
tnoremap <C-k> <C-w>:<C-U>TmuxNavigateUp<cr>
tnoremap <C-l> <C-w>:<C-U>TmuxNavigateRight<cr>

This retains the expected functionality

Benefits

Maintains consistent navigation behavior across all modes
Preserves terminal state when navigating between panes
Works properly with nested Vim instances that contain terminal splits
Seamlessly integrates with existing tmux navigation

Testing Done

Verified navigation works between:

Vim splits → terminal splits
Terminal splits → Vim splits
Terminal splits → tmux panes
Nested Vim instances with terminal splits

Confirmed terminal state is preserved after navigation

Note on pull 172

#172 is now almost a decade old and this issue still comes up for default users. Rather than having people figure out how to create this functionality, it is much better to have it and just have it turned off by default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions