Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In vim, how do I make a custom word boundary motion?

As I understand, w recognizes word boundaries by splitting text into 3 groups:

1) characters that are specified in the iskeyword setting (alphabetic, digits, and underscore)

2) other non-printable characters (symbols)

3) whitespace characters

Each time you press w it goes to the next group 1 or group 2. I'd like to customize it so it only goes to the next group 1, jumping over "symbol words".

What almost works is this:

nnoremap w /\k\+<CR>

which uses the iskeyword character class \k. But it is ugly because it simulates me performing a search, which changes my highlighting, clutters my search history, and who knows what else. Is there way to make this work "cleanly" like the w command normally is?

like image 678
Ein Avatar asked Mar 02 '12 21:03

Ein


1 Answers

I think you are looking for operator pending mode, a.k.a xmap, smap and family.

I have done some examples of these in other answers on SO:

The most relevant example might be

  • vim: select inside dots

You will also find some techniques that are similar and might be useful for you

like image 119
sehe Avatar answered Oct 04 '22 22:10

sehe