How do I change the contents inside curly braces?
Answer
ci{
Explanation
The ci{ command deletes everything inside the nearest pair of curly braces {} and places you in insert mode to type a replacement. It works no matter where your cursor is inside the braces.
How it works
ctriggers the change operator (delete + enter insert mode)i{is the "inner braces" text object — it selects everything between{and}, excluding the braces themselves
Example
Given the text with the cursor anywhere inside the braces:
if (true) {
console.log("hello");
console.log("world");
}
Pressing ci{ deletes the two console.log lines and enters insert mode between the braces, leaving:
if (true) {
}
You can then type the new body of the block.
Tips
- Use
ci}— it does exactly the same thing asci{ - Use
ca{to change the braces themselves along with their contents - Use
di{to delete inside braces without entering insert mode - Use
vi{to visually select the contents inside braces first - Works with other bracket types too:
ci(for parentheses,ci[for square brackets - Nesting is handled automatically — Vim finds the nearest enclosing pair