unblevable / quick-scope

Lightning fast left-right movement in Vim
MIT License
1.43k stars 54 forks source link

a:mapping.mode is 'no' and Restore() tries to nonoremap #87

Closed mckellygit closed 2 years ago

mckellygit commented 2 years ago

In both vim and nvim for me the first time I use quick-scope (f key) but then hit \<C-c> I get an error that nonoremap is not valid. I tracked it down to a:mapping.mode being "no" instead of "" or just "n". I am not sure why that is. To fix this I check for n and only add an n, as in -

function! quick_scope#mapping#Restore(mapping) abort
  if a:mapping.mode =~ "n"
    let mapfirst = 'n'
  else
    let mapfirst = ''
  endif
  execute mapfirst
        \ . (a:mapping.noremap ? 'noremap ' : 'map ')
  ...
bradford-smith94 commented 2 years ago

Interesting, in my quick testing I didn't get this to happen.

Can you tell me the output of running :map <c-c> in your setup?

mckellygit commented 2 years ago

Hi, for vim I have -

v  <C-C>         (&buftype ==# 'terminal') ? 'tyi' : (mode() =~ "\<C-V>") ? 'ty' : '<C-\><C-N>:call <SNR>4_YankAndRestoreWinPos("ty")<CR>'
no <C-C>       * <Cmd>AsyncStop!<CR><Cmd>sleep 500m<CR><Cmd>AsyncStop!<CR><Cmd>call feedkeys("\<C-C>", "Lnt")<CR>

It does show the "no" for a mapping mode, in both vim and nvim. After the f for quick-scope and then a \<C-c> the :map shows n and o maps separately, but they are identical (with my change above).

mckellygit commented 2 years ago

And I should have said first off, thank you for quick-scope!

bradford-smith94 commented 2 years ago

Interesting, did you set that mapping or did a plugin? (You can do :verbose map <c-c> if you aren't sure).

First off I'm wondering how a mode of no gets set, and secondly if it's an issue with how the mapping is created or just a new way of displaying the mode (if the latter then we do need to handle this similar to your original suggestion).

Knowing what vim/nvim version you're using may also be helpful. I have Vim 8.2 (patches through 4827) and Nvim 0.7.0, and I couldn't find any mention of a mapping showing up with no in either of their help pages. I'm guessing that no means normal (n) and operator-pending o but when I try that myself I see two lines in a :map output.

mckellygit commented 2 years ago

Hi, If I have:

noremap <C-c> :redraw!<CR>:echom "here"<CR>

I see this from the :map command:

no <C-C>       * :redraw!<CR>:echom "here"<CR>

But if I use nnoremap then map shows it just with an "n". So I can probably just change my mapping from noremap to nnoremap to get around this. But it seems "no" is an ok mode ? I am using: NVIM v0.8.0-dev or vim version 8.2.4969 but I don't think that matters too much ? Maybe it is something fairly new. thx

mckellygit commented 2 years ago

ok, I think its because I also have a vmap \<C-c> somewhere else, so the "nvo" from the noremap becomes just "no".

mckellygit commented 2 years ago

ok, if I explicitly do:

nnoremap <C-c> ...
onoremap <C-c> ... (the same as above)

then I get the separate "n" and "o" mappings - so that is a solid work-around I think.

mckellygit commented 2 years ago

Hi, Should I submit a PR ? Or just use a separate nnoremap and onoremap and close this issue ? thx

bradford-smith94 commented 2 years ago

Hey, sorry I've been a little busy for the past week. I think I should have time later today to push an update for this.

mckellygit commented 2 years ago

ok, thx. No problem at all, just glad to help :-)