Nvim Session 08: Text Objects Complete

Text objects are semantic chunks of text. Master them all: words, sentences, paragraphs, delimiters, tags, and plugin extensions.

Pre-Session State

  • Know iw and aw basics

  • Used i" and a"

  • Know ALL built-in text objects

  • Understand inner vs around

The Text Object Grammar

{operator}{a|i}{object}
  • a = "around" (includes delimiters/whitespace)

  • i = "inner" (inside only)

Lesson 1: Word Objects

Exercise 1.1: iw vs aw

The quick brown fox
     |
diw      " Delete inner word → "The  brown fox" (word gone, spaces remain)
daw      " Delete around word → "The brown fox" (word + trailing space)

Rule: aw includes trailing whitespace (or leading if at end).

Exercise 1.2: WORD objects

hello-world.example.com
      |
diW      " Delete entire "hello-world.example.com"
ciW      " Change entire WORD

Exercise 1.3: Word selection for replacement

oldVariable = value
    |
ciw      " Change inner word
newVariable<Esc>

Lesson 2: Sentence and Paragraph

Exercise 2.1: Sentence objects

Sentences end with ., !, ? followed by whitespace.

First sentence. Second sentence! Third one?
                |
dis      " Delete inner sentence → "First sentence.  Third one?"
das      " Delete around sentence → "First sentence. Third one?"

Exercise 2.2: Paragraph objects

Paragraphs are separated by blank lines.

First paragraph
continues here.

Second paragraph
also continues.
dip      " Delete inner paragraph (content only)
dap      " Delete around paragraph (includes trailing blank line)
yap      " Yank paragraph
gqip     " Reformat paragraph

Exercise 2.3: Move paragraphs

dap      " Cut paragraph
}        " Move to next paragraph
P        " Paste above

Lesson 3: Quote Objects

Exercise 3.1: Double quotes

config = "old-value"
          |
di"      " Delete inside → config = ""
ci"      " Change inside → config = "|"
da"      " Delete around → config = (no quotes)
yi"      " Yank inside → register has "old-value"

Exercise 3.2: Single quotes and backticks

name = 'value'
code = `command`
di'      " Inside single quotes
da'      " Around single quotes
di`      " Inside backticks
da`      " Around backticks

Exercise 3.3: Quote objects find forward

Cursor doesn’t need to be IN the quotes:

| config = "value"
ci"      " Works! Finds first quotes on line

Lesson 4: Bracket Objects

Exercise 4.1: Parentheses

function(arg1, arg2, arg3)
              |
di)      " Delete inside → function()
da)      " Delete around → function
ci)      " Change inside → function(|)

Equivalents: di(, dib (b = block)

Exercise 4.2: Square brackets

array[index]
      |
di]      " Delete inside → array[]
da[      " Delete around → array

Exercise 4.3: Curly braces

{
  content
  here
}
diB      " Delete inside braces (multiline!)
daB      " Delete around including braces
ciB      " Change inside

Equivalents: di{, di}

Exercise 4.4: Angle brackets

<element attr="value">
         |
di>      " Delete inside angles
da<      " Delete around angles

Lesson 5: Tag Objects

Exercise 5.1: HTML/XML tags

<div class="container">Content here</div>
                        |
dit      " Delete inside tag → <div class="container"></div>
dat      " Delete entire tag element
cit      " Change inside tag → <div class="container">|</div>
vit      " Visual inside tag

Exercise 5.2: Nested tags

<outer><inner>Text</inner></outer>
               |
dit      " Affects <inner>|</inner>
2dit     " Affects <outer>|</outer>

Exercise 5.3: Self-closing tags

<img src="photo.jpg" alt="Photo" />
              |
dit      " Selects attributes

Lesson 6: All Text Objects Reference

Exercise 6.1: Complete reference table

Object Inner (i) Around (a)

Word

iw

aw

WORD

iW

aW

Sentence

is

as

Paragraph

ip

ap

`" ` quotes

i"

a"

’ ` quotes

i'

a'

` backticks

i`

a`

( ) parens

i) ib

a) ab

[ ] brackets

i]

a]

{ } braces

i} iB

a} aB

< > angles

i>

a<

Tags

it

at

Exercise 6.2: Practice each one

Create a practice file:

word "quoted" (parens) [brackets] {braces}
<tag>content</tag>

Sentence one. Sentence two.

Paragraph one.

Paragraph two.

Try every text object on appropriate content.

Lesson 7: Operators with Text Objects

Exercise 7.1: Common operations

" Delete
diw daw di" da( dip

" Change
ciw caw ci" ca( cip

" Yank
yiw yaw yi" ya( yip

" Visual
viw vaw vi" va( vip

" Indent
>ip <ip =ip

" Case
gUiw guaw g~i"

Exercise 7.2: Multiple operators

Operator + text object is consistent:

" Same pattern applies everywhere
d{object}    " Delete
c{object}    " Change
y{object}    " Yank
v{object}    " Visual
>{object}    " Indent
<{object}    " Outdent
={object}    " Auto-indent
gU{object}   " Uppercase
gu{object}   " Lowercase
g~{object}   " Toggle case
gq{object}   " Format
gw{object}   " Format (keep cursor)

Lesson 8: Plugin Text Objects

Exercise 8.1: Common plugin objects

With mini.ai or nvim-treesitter-textobjects:

" Function (f)
daf      " Delete around function
cif      " Change inside function

" Argument (a)
dia      " Delete inside argument
daa      " Delete argument + comma

" Class (c)
dac      " Delete around class

" Comment (/)
di/      " Delete inside comment

" Indent (i)
dii      " Delete at current indent level
dai      " Delete including less-indented lines

Exercise 8.2: Targets.vim patterns

" Next/Last modifiers
cin"     " Change inside NEXT quotes
cil"     " Change inside LAST quotes
dan(     " Delete around NEXT parens
dal{     " Delete around LAST braces

" Argument separator
dia      " Delete inside argument
d2ia     " Delete next 2 arguments

Exercise 8.3: Your domus-nvim objects

Check what’s configured in your config:

:lua print(vim.inspect(require('mini.ai').config))

Lesson 9: Practical Patterns

Exercise 9.1: Config file editing

YAML:

hostname: "old-value.domain.com"
ci"      " Change inside quotes
new-value.domain.com<Esc>

JSON:

{"key": "old-value", "other": "data"}
f"ci"    " Find quote, change inside
new-value<Esc>

Exercise 9.2: Code refactoring

Function arguments:

function(oldArg1, oldArg2, oldArg3)
di)      " Clear all args → function()
ci)      " Change all args
f,ciw    " Change specific arg

Exercise 9.3: Documentation editing

Markdown:

This is `inline code` in text.
ci`      " Change inside backticks

Exercise 9.4: Log analysis

[ERROR] 2026-03-18 Something failed: reason
di[      " Delete inside brackets
ci]      " Change inside brackets

Inner vs Around Decision

Use Inner (i) Use Around (a)

Keep delimiters

Remove delimiters

Change content only

Delete entire element

ci" change quoted value

da" remove quotes entirely

cip rewrite paragraph

dap remove paragraph + spacing

Text Object Mnemonics

Object Remember As

w

word

W

WORD (whitespace-delimited)

s

sentence

p

paragraph

", ', `

The delimiter itself

), b

Block/parentheses

]

Bracket

}, B

Brace/Big block

>

Greater-than/angle

t

Tag

Exercises to Complete

  1. [ ] Practice all quote objects: di", ci', da`

  2. [ ] Practice all bracket objects: di), ci], daB

  3. [ ] Use dit and dat on HTML

  4. [ ] Chain operations: yiw then ciw then Ctrl-r 0

  5. [ ] Try paragraph operations on a markdown file

Next Session

Session 09: Command-line Mode - Ex commands, ranges, global.

Session Log

Timestamp Notes

Start

<Record when you started>

End

<Record when you finished>

Discoveries

<What surprised you?>