bfops
bfops

Reputation: 5678

Jump between words with varying separators in vim

I have a few different keys to jump between words, depending on what separators I want to include:

" Use _ as a word separator when moving between words with q and t
noremap q :set iskeyword-=_<CR>b:set iskeyword+=_<CR>
noremap t :set iskeyword-=_<CR>w:set iskeyword+=_<CR>

This, however, doesn't work with multi-key commands like dq, dt, cq, or ct. Can I create a version of these keys which will work with multi-key commands like this?

Bear in mind I don't want to lose the functionality of jumping between words normally (e.g. with w, e, b), I just want to add keys with different functionality.

Thanks!

Upvotes: 2

Views: 197

Answers (1)

Birei
Birei

Reputation: 36262

Use the Operator Pending Mapping:

:onoremap t :<c-u>normal t<cr>
:onoremap q :<c-u>normal q<cr>

Remember to declare them after your normal mapping, because they are based in those ones.

Upvotes: 1

Related Questions