What constitutes a 'word' in vim?
Let's say we have the following in vim atm:
int main () {
printf("hello");
return 0;
}
In vim, w moves a word to the right, but what exactly constitutes a 'word'?
For example, if I have the cursor on p of printf
, pressing w takes u to (
and pressing another w skips the "
and puts the cursor on the h
of hello
. Why was the "
skipped ?
Pressing another w now takes you to the other "
before the )
and pressing another w
takes you to the next line. Why where the )
and ;
skipped?
And now the cursor is on the r
of return
. Pressing a w takes the cursor on 0
and pressing another w now takes the cursor on the ;
. So in this case, the ;
was not skipped unlike in the previous line. Why is this?
I hope I made my question clear enough but I'm just trying to understand how this all wor开发者_运维知识库ks.
From :help word
:
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.
If your use capital W instead:
A WORD consists of a sequence of non-blank characters, separated with white space. An empty line is also considered to be a WORD.
In your example, w
treats any sequence of non-keyword letters as a word too.
EDIT: The setting for virtualedit
will influence this too: You must have it unset, because line-final punctuation is being skipped by w
(add some whitespace to the end of the line to see the difference). If you set virtualedit=onemore
the cursor will be able to stop one space beyond the end of the line, and line final punctuation won't ever be skipped.
From within vim, type
:help word-motions
You will get all the explanation you seek.
精彩评论