lucc/nvimpager

Bug: Cannot remap j and k keys.

Closed this issue · 2 comments

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:

  • type man man to access the nvimpager
  • type :map j <c-d> and then :map k <c-u> to remap j and k
  • press j and k and notice there is no difference in normal mode
  • press V to go into visual mode
  • press j and k and notice the remaps work on visual mode

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

Other things I tried that were unsuccessful:

  • using :nmap, :noremap, and :nnoremap instead of :map
  • putting the remap commands in .config/nvimpager/init.vim with nothing else in the file
  • going into the file /usr/share/nvimpager/runtime/lua/nvimpager.lua and commenting out the lines map('n', 'k', '<C-Y>') and map('n', 'j', '<C-E>')

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

  • go into the file /usr/share/nvimpager/runtime/lua/nvimpager.lua
  • replace the line map('n', 'k', '<C-Y>') with map('n', 'k', '<c-u>')
  • replace the line map('n', 'j', '<C-E>') with map('n', 'j', '<c->')
lucc commented

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.

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