rhysd / committia.vim

A Vim plugin for more pleasant editing on commit messages
MIT License
731 stars 30 forks source link

Window navigation using mappings #35

Closed tinyheero closed 7 years ago

tinyheero commented 7 years ago

I currently have the following in my ~/.config/nvim/init.vim:

nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l

For easier window navigation. For what some reason these mappings do not work in the committia plugin. I have to use full keystrokes (e.g. <C-w>h) to move between the edit, diff and status windows. Is there a reason why these mappings don't work in committia?

rhysd commented 7 years ago

Could you try below each commands while committia windows are shown?

:nmap <C-h>
:nmap <C-j>
:nmap <C-k>
:nmap <C-l>

What was shown in messages area for each commands?

tinyheero commented 7 years ago

I got this:

n  <C-H>       * :TmuxNavigateLeft<CR>
n  <NL>        * :TmuxNavigateDown<CR>
n  <C-K>       * :TmuxNavigateUp<CR>
n  <C-L>       * :TmuxNavigateRight<CR>

I have the plugin Plug 'christoomey/vim-tmux-navigator' that allows for navigation between tmux and vim panes. This might be the reason why it's failing...

rhysd commented 7 years ago

Yeah, I think disabling the plugin temporarily would solve this problem. I don't know what actually the plugin does. But I think overwriting mappings only in committia windows as following may solve this problem.

" In .vimrc
function! s:setup_win_move(info)
    nnoremap <buffer><C-h> <C-w>h
    nnoremap <buffer><C-j> <C-w>j
    nnoremap <buffer><C-k> <C-w>k
    nnoremap <buffer><C-l> <C-w>l
endfunction

let g:committia_hooks = {}
let g:committia_hooks.edit_open = function('s:setup_win_move')
let g:committia_hooks.diff_open = function('s:setup_win_move')
let g:committia_hooks.status_open = function('s:setup_win_move')
tinyheero commented 7 years ago

Unfortunately, this didn't work. The issue only surfaces when I am inside a tmux session. I think the issue is in my ~/.tmux.conf I have the following settings:

# Smart pane switching with awareness of vim splits
# recommended by vim-tmux-navigator
is_vim='echo "#{pane_current_command}" | grep -iqE "(^|\/)g?(view|n?vim?)(diff)?$"'
bind -n C-h if-shell "$is_vim" "send-keys C-h" "select-pane -L"
bind -n C-j if-shell "$is_vim" "send-keys C-j" "select-pane -D"
bind -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -U"
bind -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R"
bind -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"

When I remove this, the quick window navigation works inside committia while inside a tmux session. The downside is that I can't use the mappings to navigate tmux panes...

rhysd commented 7 years ago

I see. From .vimrc, there is no way to modify tmux config safely. The tmux config captures input sequence from you before Vim receives. Then I think you need to find other mappings like <Space>h, <Space>j, ...

tinyheero commented 7 years ago

Thanks.

kthibodeaux commented 5 months ago

i know this has issue was closed 7 years ago, but i got here by googling, and none of the suggested solutions seemed right to me

here is how i address the issue https://github.com/kthibodeaux/.dotfiles/commit/0f9f36c21683228d6457242836fe40fe043bf1a8