lucc / nvimpager

Use nvim as a pager to view manpages, diffs, etc with nvim's syntax highlighting
Other
396 stars 20 forks source link

Bug: Cannot remap j and k keys. #65

Closed Luis-Licea closed 2 years ago

Luis-Licea commented 2 years ago

I am trying to remap the j, k keys so that instead of moving one line down or up, I can go one page down or up. However, it looks like the j, k keys cannot be remapped to anything. My other remaps work normally.

To reproduce the error:

The remap commands for j and k do not work in normal mode, only in visual mode.

Other things I tried that were unsuccessful:

I found one solution, but I do not like it because it changes the source code:

lucc commented 2 years ago

I can reproduce this.

When I start nvimpager and list the mapping (map j) I get:

n  j           *@<C-E>
n  j           * <C-E>

and after your map j <c-d> it shows

n  j           *@<C-E>
   j             <C-D>

According to :help map-listing the @ marks a buffer lokal mapping and that takes precedence over your global mapping. You could unmap <buffer> j first or you could map <buffer> j <c-d> to overwrite it.

I will check if nvimpager really needs to define two mappings here.

Luis-Licea commented 2 years ago

Thanks. I got the mappings I wanted. The mappings did not work without the <buffer> specifier as you mentioned above. I also had to map the keys after the configurations were loaded. The events VimEnter and SourcePost only worked for the first buffer, but CursorMoved works no matter how many buffers I open.

" Fast up movement.
au CursorMoved * nnoremap <buffer> j <c-d>
" Fast down movement.
au CursorMoved * nnoremap <buffer> k <c-u>
" Open manual entry.
nnoremap <cr> K
" Slow down movement.
nnoremap J j
" Slow up movement.
nnoremap K k

At first I tried without the <buffer>specifier, and with the VimEnter and SourcePostevents, but