justinmk / vim-sneak

The missing motion for Vim :athletic_shoe:
http://www.vim.org/scripts/script.php?script_id=4809
MIT License
3.24k stars 88 forks source link

Basic Sneak and Labeled Sneak with different key bindings #275

Closed baldore closed 3 years ago

baldore commented 3 years ago

Hello!

Is it possible to have both functionalities at the same time? I would like to be able to use s and S to sneak normally, but have another keybinding to use the labeled one. Is that possible?

ggandor commented 3 years ago

Yes, you can use the sneak#wrap function, with that you can customize the behavior (:h sneak#wrap).

Set g:sneak#label = 0, and define these mappings for "labeled sneak" (change x/X in the example to the desired keys). The first three arguments after op correspond to the normal s/S behavior, and the last argument is set to 2, that enforces label-mode for the particular command, regardless of the global setting.

nnoremap <silent> x :<C-U>call sneak#wrap('', 2, 0, 2, 2)<CR>
nnoremap <silent> X :<C-U>call sneak#wrap('', 2, 1, 2, 2)<CR>
xnoremap <silent> x :<C-U>call sneak#wrap(visualmode(), 2, 0, 2, 2)<CR>
xnoremap <silent> X :<C-U>call sneak#wrap(visualmode(), 2, 1, 2, 2)<CR>
onoremap <silent> x :<C-U>call sneak#wrap(v:operator, 2, 0, 2, 2)<CR>
onoremap <silent> X :<C-U>call sneak#wrap(v:operator, 2, 1, 2, 2)<CR>

Or equivalently, set g:sneak#label = 1, and change the last argument to 0 in the function calls above (that enforces "no-label-mode" for the particular command).

baldore commented 3 years ago

It works great! Thanks a lot.