How do I change text from the cursor up to a specific character?
Answer
ct{char}
Explanation
The ct{char} command deletes everything from the cursor up to (but not including) the specified character and drops you into insert mode. It combines the change operator c with the t ("till") motion for precise, surgical edits within a line.
How it works
cis the change operator (delete and enter insert mode)t{char}is the "till" motion — it moves the cursor to just before the next occurrence of{char}on the current line- Together,
ct{char}deletes from the cursor to just before{char}and enters insert mode
Example
Given the text with the cursor on H:
Hello, World!
Pressing ct, deletes Hello (everything before the comma) and enters insert mode:
|, World!
Type Goodbye and press <Esc>:
Goodbye, World!
Tips
- Use
cf{char}to change through the character (including it), versusct{char}which stops just before it - Use
cT{char}andcF{char}to change backwards to a character dt{char}anddf{char}are the delete equivalents — they delete without entering insert mode- Combine with
;to extend: if the first match of{char}isn't the one you want, usec2t{char}to change up to the second occurrence - This is extremely useful for editing function arguments: with the cursor at the start of a parameter,
ct,changes just that one argument - Pair with
.to repeat the same change-to-character operation elsewhere in the file