Closed damnskippy closed 4 years ago
Thanks for filing the issue, @damnskippy. Adding a knob to prevent the mappings would be easy, as would setting up <Plug>
mappings, but I'd like to understand the use case a bit better too. Can you give me a concrete example or two of the kind of thing you'd like to set up?
In the meantime as a kind of hacky workaround, you do have the option of setting up an override in ~/.vim/after/plugin/loupe.vim
and overwriting the mappings defined here:
execute 'nnoremap <silent> # #' . s:center_string . ':call loupe#private#hlmatch()<CR>'
execute 'nnoremap <silent> * *' . s:center_string . ':call loupe#private#hlmatch()<CR>'
execute 'nnoremap <silent> N N' . s:center_string . ':call loupe#private#hlmatch()<CR>'
execute 'nnoremap <silent> g# g#' . s:center_string . ':call loupe#private#hlmatch()<CR>'
execute 'nnoremap <silent> g* g*' . s:center_string . ':call loupe#private#hlmatch()<CR>'
execute 'nnoremap <silent> n n' . s:center_string . ':call loupe#private#hlmatch()<CR>'
Obviously calling loupe#private#anything
is not "supported" and could break if I ever change the internal APIs in the future, but it may enable you to get what you want right now. I just want to learn more about your use cases before making any changes.
Yes, here's some more info on my use case. There are two other search related plugins I currently very much like and use: https://github.com/henrik/vim-indexed-search and https://github.com/haya14busa/incsearch.vim. I also have my own (or perhaps copied from somewhere) "center_string" function which keeps the cursor in the middle of the screen only "most of the time" since I find the redraw/realign, though useful, a bit disorienting.
I end up chaining these functions in the mappings; for instance,
map <silent> n <Plug>(incsearch-nohl-n)zv:call MyAlignScreen() <CR>:ShowSearchIndex<CR>:LoupeMatch<CR>
For now, I have commented out the exec nnoremap in plugin/loupe.vim and have added command LoupeMatch as below:
" execute 'nnoremap <silent> # #' . s:center_string . ':call loupe#private#hlmatch()<CR>'
" execute 'nnoremap <silent> * *' . s:center_string . ':call loupe#private#hlmatch()<CR>'
" execute 'nnoremap <silent> N N' . s:center_string . ':call loupe#private#hlmatch()<CR>'
" execute 'nnoremap <silent> g# g#' . s:center_string . ':call loupe#private#hlmatch()<CR>'
" execute 'nnoremap <silent> g* g*' . s:center_string . ':call loupe#private#hlmatch()<CR>'
" execute 'nnoremap <silent> n n' . s:center_string . ':call loupe#private#hlmatch()<CR>'
command LoupeMatch :call loupe#private#hlmatch()
Also commented out mappings to / & ? since they break/defeat the incsearch plugin functionality.
" nnoremap <expr> / loupe#private#prepare_highlight('/' . <SID>MagicString())
" nnoremap <expr> ? loupe#private#prepare_highlight('?' . <SID>MagicString())
" xnoremap <expr> / loupe#private#prepare_highlight('/' . <SID>MagicString())
" xnoremap <expr> ? loupe#private#prepare_highlight('?' . <SID>MagicString())
I wonder if the above should be done only if g:LoupeVeryMagic is not set to 0? Just a thought, could be wrong.
HTH.
Not related at all, but in case you're curious about MyAlignScreen, below is the code. Unfortunately I just don't recall whether I wrote this or stole it from somewhere.
function MyAlignScreen()
let s:top = line("w0")
let s:bot = line("w$")
let s:cur = line(".")
let s:screenWidth = s:bot - s:top
let s:hotWidth = (s:screenWidth * 30) / 100
if s:cur < (s:top + s:hotWidth) || s:cur > (s:bot - s:hotWidth)
silent exec 'normal zz'
endif
endfunction
I wonder if the above should be done only if
g:LoupeVeryMagic
is not set to 0?
If I do that, I think that will break search highlighting of the current match, so probably can't do that. There should be a way, however, to make this work without clashing with incsearch.
I was just looking at this plugin https://github.com/timakro/vim-searchant (which incidentally provides a subset of Loupe functionality), and in it, I see the following code in an attempt to solve one of the two mapping problems I listed above:
function! s:MapUpdate(name)
let recall = maparg(a:name, "n")
if !len(recall)
let recall = a:name
endif
execute "nnoremap <silent> ".a:name." ".recall.":call <SID>Update()<CR>"
endfunction
call s:MapUpdate("*")
call s:MapUpdate("#")
call s:MapUpdate("g*")
call s:MapUpdate("g#")
call s:MapUpdate("n")
call s:MapUpdate("N")
Pushed some changes to the next
branch to partially address this. Consider it tentative as I am not sure this is the best way to go about it. Will let it bake there for a while before merging back to master
.
I actually also stumbled across this and found that your solution does not quite work as expected (at least not with the latest neovim nightly-build). When I setup
nmap <Nop> <Plug>(LoupeN)
nmap <Nop> <Plug>(Loupen)
to disable both mappings, the second overwrites the first and, thus, only n
is not being mapped.
Ofcourse I can fix it by using a after/loupe.vim
file to rebind n
and N
to themselves, respecitvely, but the map preventions may need some work.
@mrossinek: I think you just need to pick some a unique LHS (left-hand-side) for each mapping that you want to suppress. For example, you could do:
map <Nop><F1> <Plug>(LoupeN)
nmap <Nop><F2> <Plug>(Loupen)
Ah I didn't think of simply concatenating <Nop>
with another key ^^ Thanks that resolves this.
Perhaps you could add a knob that will conditionalize mappings to n,N,,#,g, etc. And provide aCommand that can be used to append to an already existing mapping.
I (like others, I suspect) already have existing search related mappings but want to utilize Loupe functionality.
Just a suggestion - thanks for the plugin.