文字对文字

我正在学习 Vim,无法理解 wordWORD之间的区别。

我从 Vim 手册中得到了以下信息。

一个单词由一系列字母、数字和下划线组成,或者一个 其他非空白字符序列,用空格分隔 (空格、制表符) 选项。空行也被认为是一个单词。

WORD 由一系列非空白字符组成,用 一个空行也被认为是一个 WORD。

我觉得 wordWORD是一回事。它们都是用空格分隔的非空字符序列。一个空行可以被认为是 wordWORD

问题:
他们之间有什么区别?
为什么/什么时候会有人使用 WORD而不是 word

我已经做了谷歌和 SO 搜索,但他们的搜索引擎解释 WORD只是 word,所以它就像我正在搜索 Vim word vs word,当然不会找到任何有用的东西。

16486 次浏览

If I do viw ("select inner word") while my cursor is on app in the following line, it selects app:

app/views/layouts/admin.blade.php

If I do viW (WORD) while my cursor is at the same place, it selects the whole sequence of characters. A WORD includes characters that words, which are like English words, do not, such as asterisks, slashes, parentheses, brackets, etc.

  • A WORD is always delimited by whitespace.
  • A word is delimited by non-keyword characters, which are configurable. Whitespace characters aren't keywords, and usually other characters (like ()[],-) aren't, neither. Therefore, a word usually is smaller than a WORD; the word-navigation is more fine-grained.

Example

This "stuff" is not-so difficult!
wwww  wwwww  ww www ww wwwwwwwww    " (key)words, delimiters are non-keywords: "-! and whitespace
WWWW WWWWWWW WW WWWWWW WWWWWWWWWW   " WORDS, delimiters are whitespace only

According to Vim documentation ( :h 03.1 )

  • A word ends at a non-word character, such as a ".", "-" or ")".

  • A WORD ends strictly with a white-space. This may not be a word in normal sense, hence the uppercase.

eg.

           ge      b          w                             e
<-     <-         --->                          --->
This is-a line, with special/separated/words (and some more). ~
<----- <-----         -------------------->         ----->
gE      B                   W                       E

If your cursor is at m (of more above)

  • a word would mean 'more' (i.e delimited by ')' non-word character)

  • whereas a WORD would mean 'more).' (i.e. delimited by white-space only)

similarly, If your cursor is at p (of special)

  • a word would mean 'special'
  • whereas a WORD would mean 'special/separated/words'

Another way to say it. If ur coding, and want to move thru the line stopping at delimiters and things line that "() . [] , :" use w.

if you want to bypass those and just jump to words lets say like a novel or short story has, use W.

For coding the small w is probably the one used most often. Depends where you are in the code.

To supplement the previous answers... I visualise it like this; WORD is bigger than word, it encompasses more... enter image description here

That's a grammar problem while understanding the definition of "word".

I get stuck at first in Chinese version of this definition (could be miss-translation).


The definition is definitely correct, but it should be read like that:

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, <EOL>).

Whitespace characters were only needed when delimiting two same types of 'word'


More examples in brackets as follow:

(example^&$%^Example) three "word" :(example), (^&$%^) and (Example)

(^&^&^^ &&^&^) two "word" : (^&^&^^) and (&&^&^)

(we're in stackoverflow) five "word" :(we), ('), (re), (in) and (stackoverflow)