In the buffer
Before:
connect(host="db.internal.example.com", port=5432, retries=3)
^
After typing dt,:
connect(, port=5432, retries=3)
^
The first argument is gone, up to but not including the comma. The cursor sits on the comma, ready for you to type a replacement with i or to keep going.
When you would reach for it
You need to remove the first argument of a function call, and it is a string full of dots, quotes, and punctuation. Counting words for d5w means knowing how vim splits "db.internal.example.com" into words, which nobody knows offhand. You do know where the argument ends: at the comma. t lets you name the landmark instead of counting the distance, and any operator can use it.
Gotchas
tonly searches the current line. If the target character is on the next line, the motion fails, vim beeps, and the operator deletes nothing. Used/,with a search when the target might be further away.tis exclusive andfis inclusive.dt,leaves the comma;df,takes it. When you mean to remove a whole argument including its separator,df,(followed byxfor the space) is usually what you want.- If the target character is the very next character,
dt,has nothing to cover and does nothing. The cursor is already “till” the comma. - After
t,, pressing;in Vim jumps to before the next comma rather than staying put. In strict vi, or withcpocontaining;, it stays stuck. Use2t,orf,if you need the same result everywhere.
Variants
connect(host="db.internal.example.com", port=5432, retries=3)
^
connect(host="db.internal.example.com", port=5432, retries=5)
^
ct) then retries=5 and <Esc>: change everything up to the closing paren, leaving the paren in place.
connect(host="db.internal.example.com", port=5432, retries=3)
^
connect(, retries=3)
^
dT(: the backward version. Deletes from the cursor back to immediately after the opening paren. The character under the cursor stays, because backward motions are exclusive of the starting position.
connect(host="db.internal.example.com", port=5432, retries=3)
^
connect(, retries=3)
^
d2t,: a count picks the second comma, so two arguments go in one command.