Vim's `ci(` Motion
Vim’s ci(
motion is a powerful tool for quickly changing the content of parentheses. It allows you to delete the text within the parentheses and enter insert mode, ready to type the new content. This command works not only for round parentheses ()
but also for curly braces {}
, square brackets []
, and angle brackets <>
. It’s a significant time saver compared to manually deleting and navigating.
Here’s a breakdown of how ci(
works:
c
: This stands for “change.” It signals that you want to change the text within the specified region.i
: This signifies “inside.” It specifies that you want to operate within the delimiters.(
: This indicates the delimiter itself. Using{
would target curly braces,[
would target square brackets, and so on.
How to Use It
- Navigate to the parentheses: Move your cursor anywhere on the opening or closing parenthesis.
- Type
ci(
: The text inside the parentheses will be deleted, and you’ll enter insert mode. - Type the new content: Enter the text you want to replace the original content with.
- Press
Esc
: This will exit insert mode and save your changes.
Examples
Let’s say you have the following line of JavaScript code:
let message = greet("world");
You want to change “world” to “user”. Follow these steps:
- Move your cursor to either parenthesis of
("world")
. - Type
ci(
. The line will change to:let message = greet("");
with the cursor positioned inside the empty parentheses. - Type
user
. - Press
Esc
. The final line will be:let message = greet("user");
Example in Go:
Imagine you have this Go code:
fmt.Println(reflect.TypeOf("hello"))
You want to change the type from “hello” (string) to reflect.TypeOf(10) (int).
- Move your cursor to either parenthesis of
("hello")
. - Type
ci(
. The line will change tofmt.Println(reflect.TypeOf())
. - Type
10
. - Press
Esc
. The final line will be:fmt.Println(reflect.TypeOf(10))
Beyond Parentheses
As mentioned earlier, this works with other delimiters as well. For instance, ci{
will change the content inside curly braces, ci[
, inside square brackets, and ci<
, inside angle brackets. This flexibility makes ci(
incredibly useful for a wide range of editing tasks in various programming languages and file formats.