Vim: word vs WORD

  • 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

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


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.


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'

Tags:

Vim