0

As the title says. Is it possible?

Steps to reproduce:

Type in sample(text) and put the cursor on the first character then press w.

Expected behavior:

Cursor moves to beginning of next word - text

enter image description here

Current (and default) behavior:

The cursor moves to the first brace.

enter image description here


The Same thing occurs when there is for example aaa * bbb - cursor moves to * first.

I tried manipulating iskeyword but without success.

Is there a way to tell Vim to ignore those operator and braces characters?

1

Is it possible?

Anything is possible with some scripting:

nnoremap <silent> <leader>w :call search('\<\w', 'W')<cr>
nnoremap <silent> <leader>e :call search('\w\>', 'W')<cr>
nnoremap <silent> <leader>b :call search('\<\w', 'bW')<cr>
nnoremap <silent> <leader>gE :call search('\w\>', 'bW')<cr>

It's not possible to change this behavior with iskeyword, however. Here's what :h word says:

A word consists of a sequence of letters, digits and underscores, or a sequence of other non-blank characters, separated with white space (spaces, tabs, ). This can be changed with the 'iskeyword' option. An empty line is also considered to be a word.

That is, a word motion is an alternating keyword or non-keyword sequence, that may be separated by whitespace. A word motion should not be confused with a word pattern (\w which only includes 0-9A-Za-z_).

This illustrates where the cursor jumps when you press w:

sample(text) { body }
^     ^^   ^ ^ ^    ^

Setting iskeyword+=( would give you these cursor jump positions:

sample(text) { body }
^          ^ ^ ^    ^

This is because sample(text is now considered a keyword.

This can be made clearer by using iskeyword=x to simplify your notion of a word motion:

xxxx xxxx xxabcxx def hijxxxlmn
^    ^    ^ ^  ^  ^   ^  ^  ^
0

I understand the frustration, though there are other ways around it which might be better to use since you could find yourself using vim on a server or other environment that doesn't have your customized command changes (and accompanying muscle memory).

In your specific example, you could do f t to jump directly to the start of text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.