How do I visually select a double-quoted string including the quotes themselves?
Answer
va"
Explanation
Vim's text objects let you select structured regions of text with two-keystroke shortcuts. va" selects around double quotes — the quoted string plus both surrounding " characters — making it easy to yank, delete, or replace an entire string literal in one motion.
How it works
venters Visual modea"is the around double-quote text object — it selects the contents and the delimiting"characters- Use
i"instead to select only the inner content (without the quotes) - The same pattern works for other delimiters:
va'(single quotes),va\`` (backticks),va(,va[,va{` - Works from anywhere on the current line — Vim searches forward for the next quoted string if the cursor is not already inside one
Example
With the cursor anywhere on this line:
const greeting = "Hello, world!";
Press va" and Vim selects "Hello, world!" (with quotes). Press di" to delete only Hello, world! (leaving the empty quotes "").
Tips
- Text object motions work in Normal mode too:
da"deletes around quotes,ca"changes around quotes,ya"yanks around quotes — no need to enter Visual mode first - For nested or multi-line strings, use
:set selection=inclusiveand combine with%or tag-based text objects ci"is one of the most frequent editing operations in code: it clears a string's value while leaving the surrounding quotes in place