vim-sneak
vim-sneak copied to clipboard
Support regex input
With regex input supported, for example, these jumps would be possible:
" Alternative searching, flexibility improved
nnoremap g/ :call sneak#wrap('', 99, 0, 2, 1)<CR>\v
" Jump around word boundaries, accuracy improved
nnoremap \\w :call sneak#wrap('', 4, 0, 2, 1)<CR>\v<
Thank you! What are some example inputs that you use? I can use those examples to add some tests.
I suppose the the pattern parsing is correct. But there are probably problems when inputting patterns in vmap
, omap
or in streak mode. Additional integration would be done.
My initial intention for adding pattern input is that, by defining specific mappings, we can jump to common text objects, which is currently all I need. I define a simple wrapper function and some mappings which seems work well.
function! Sneak(pre, post, reverse)
let n = getchar()
if n == 27 | return | endif
let c = nr2char(n)
call sneak#to('', a:pre.c.a:post, 1, 1, 0, a:reverse, 2, 0)
endfunction
nnoremap <silent> 8w :call Sneak('\v<', '', 0)<CR>
nnoremap <silent> 8b :call Sneak('\v<', '', 1)<CR>
nnoremap <silent> 8e :call Sneak('\v', '>', 0)<CR>
nnoremap <silent> 8ge :call Sneak('\v', '>', 1)<CR>
nnoremap <silent> 9w :call Sneak('\v\_s\zs', '', 0)<CR>
nnoremap <silent> 9b :call Sneak('\v\_s\zs', '', 1)<CR>
nnoremap <silent> 9e :call Sneak('\v', '\ze\_s', 0)<CR>
nnoremap <silent> 9ge :call Sneak('\v', '\ze\_s', 1)<CR>
@bohrshaw Instead of a new option, what do you think about just assigning a special key like <C-v>
or something, to invoke "regex mode"?
@justinmk the current option would be just ignored as the actual trigger for "regex mode" is to prefix input with text matching \\[vVmM]
(solely \\[vVmM]
is still literal). By predefining special text positions or boundaries in extra mappings, sneaking can be more precise. But I think inputting pattens in real time would be counter-productive and superfluous, which then may be invoked by a key.
@justinmk I just refreshed the PR and the option for turning on "regex mode" is removed, as both modes should be freely accessible and an option doesn't make sense. Refreshed thoughts on my implementation are detailed in the commit message.
@bohrshaw Thanks. I would like to invoke regex mode with CTRL+X. With your PR users can't search for the literal \v
. I started an implementation on this branch: https://github.com/justinmk/vim-sneak/tree/regex
But didn't finish it. Since you mentioned it, I will try to finish it this week.
@justinmk Glad you're working on this. But my implementation does allow users search for the literal \v
, as it doesn't match the pattern \\[vVmM].
.
The PR has always been a quick and dirty(coupling of literal and non-literal) work anyway. Again glad you have some time working on this.