Is there any difference between dw and daw in Vim?
Categories:
Vim's dw
vs daw
: Understanding Word Deletion in Vim

Explore the subtle yet significant differences between dw
and daw
in Vim for deleting words, and learn how to choose the right command for precise text manipulation.
Vim is renowned for its powerful and efficient text editing capabilities, largely thanks to its modal editing and extensive command set. Among the most frequently used commands are those for deleting text. While d
(delete) combined with a motion is fundamental, the distinction between dw
and daw
often confuses new and even some experienced Vim users. This article will clarify the differences, illustrate their usage, and help you master word deletion in Vim.
The Basics: d
and Motions
In Vim, the d
command is an operator that requires a motion to specify what to delete. For example, dl
deletes the character under the cursor, d$
deletes from the cursor to the end of the line, and dG
deletes from the cursor to the end of the file. When it comes to words, Vim offers several motions, but w
(word) and aw
(a word) are the most common and often misunderstood.
flowchart TD A[Start with 'd' operator] --> B{Choose a motion} B --> C1[Motion: 'w' (word)] B --> C2[Motion: 'aw' (a word)] C1 --> D1["Deletes from cursor to start of next word (excluding trailing space)"] C2 --> D2["Deletes the entire word under/after cursor (including surrounding space)"] D1 --> E[Result: `dw`] D2 --> F[Result: `daw`]
Decision flow for dw
vs daw
Understanding dw
(delete word)
The dw
command deletes from the current cursor position up to the beginning of the next word. It considers the space after the current word as part of the next word's boundary, but it does not delete the space before the word if the cursor is at the beginning of a word. If the cursor is in the middle of a word, dw
deletes from the cursor to the end of that word, plus any trailing whitespace until the start of the next word.
This is a test sentence.
^ (cursor here)
After `dw`:
This is a test sentence.
^ (cursor here, ' is' deleted)
Another example:
This is a test sentence.
^ (cursor here)
After `dw`:
This is a sentence.
^ (cursor here, ' test' deleted)
Examples of dw
behavior
dw
as 'delete word from here to the start of the next word'. It's useful when you want to delete part of a word or a word and the space immediately following it.Understanding daw
(delete a word)
The daw
command is more encompassing. It deletes the entire word under or after the cursor, along with any single space that separates it from the next or previous word. This means daw
is 'text object' based, specifically operating on the aw
(a word) text object. It's designed to delete a complete word and its surrounding whitespace, leaving clean boundaries between remaining words.
This is a test sentence.
^ (cursor here)
After `daw`:
This a test sentence.
^ (cursor here, ' is' deleted, including the space before 'a')
Another example:
This is a test sentence.
^ (cursor here)
After `daw`:
This is a sentence.
^ (cursor here, ' test' deleted, including the space before 'sentence')
Examples of daw
behavior
aw
text object includes the word and exactly one space on either side. If there are multiple spaces, daw
will only delete one, leaving the others. This makes daw
ideal for maintaining proper spacing between words.Key Differences and When to Use Each
The primary difference lies in how they handle whitespace and the cursor's starting position relative to the word. dw
is a motion-based command, deleting from the cursor's current position. daw
is a text-object-based command, deleting the entire 'a word' text object regardless of the cursor's exact position within that word.
dw
: Use when you want to delete from the cursor's current position to the beginning of the next word, often including the trailing space. It's more precise for partial word deletions or when you want to control exactly how much whitespace is removed.daw
: Use when you want to delete a complete word and its surrounding whitespace, leaving the text neatly formatted. It's excellent for removing whole words without worrying about leaving extra spaces or needing to delete spaces separately.

Visual comparison of dw
vs daw
behavior
Consider the following sentence: one two three
(with multiple spaces).
If your cursor is on t
of two
:
dw
will deletetwo
and one space, resulting inone three
.daw
will deletetwo
and one space, resulting inone three
.
However, if your cursor is on o
of one
:
dw
will deleteone
and the first space, resulting intwo three
.daw
will deleteone
and the first space, resulting intwo three
.
The behavior can seem similar with multiple spaces, but daw
's strength is in consistently deleting a word and a single surrounding space, making it more predictable for maintaining text structure.
dw
and daw
treat words differently based on Vim's definition of a word (alphanumeric characters and underscore). For example, word.
, dw
might delete word
, leaving .
, while daw
might delete word.
entirely depending on context and Vim's iskeyword
setting.