vimtricks.wiki Concise Vim tricks, one at a time.

What is the difference between the inner word (iw) and inner WORD (iW) text objects in Vim?

Answer

iW vs iw

Explanation

Vim has two flavors of the "inner word" text object that are easy to confuse: iw (lowercase) and iW (uppercase). Knowing when to use each saves time when working with compound identifiers, URLs, file paths, and hyphenated names.

How it works

  • iw — selects the current word, defined as a sequence of letters, digits, and underscores (\w characters). It stops at punctuation like ., -, /, :.
  • iW — selects the current WORD, defined as any sequence of non-whitespace characters. It treats ., -, /, :, and other symbols as part of the WORD.

The same distinction applies to aw / aW ("a word"/"a WORD", which include surrounding whitespace).

Example

Given the cursor positioned anywhere on foo.bar:

const url = 'https://example.com/path/file.js';
  • ciw with cursor on example changes only example
  • ciW with cursor on example.com changes the entire example.com

With cursor on file.js:

const url = 'https://example.com/path/';
  • diw deletes just file, leaving .js behind
  • diW deletes file.js entirely

Tips

  • Use ciW to replace an entire URL, path, or hyphenated CSS class name in one keystroke
  • viW quickly selects a snake_case, kebab-case, or path/name for further operations
  • Combine with y to yank: yiW copies the full non-whitespace token (e.g., [email protected])
  • The same uppercase/lowercase distinction applies to motion commands: w vs W, b vs B, e vs E

Next

How do I embed per-file Vim settings directly in a source file using modelines?