Reputation: 55620
Often times I want to change the text inside a parenthesis. If my cursor is at the beginning of the line:
𝙸String result = callMethod("someString");
I need to first move it inside the parenthesis
String result = callMethod("𝙸someString");
before I can type ci(
to replace the text:
String result = callMethod(𝙸);
However, I've noticed that when changing the text inside quotes, I don't need to move the cursor first.
𝙸String result = callMethod("someString");
And then type ci"
, and the cursor will jump forward to the first set of quotes on the line, clearing its contents:
String result = callMethod("𝙸");
Is it possible to enjoy this same functionality with parenthesis?
Upvotes: 3
Views: 170
Reputation: 1681
Here's another option. Add the following code to your .vimrc file
onoremap in( :<c-u>execute "normal! /(\rvi("<cr>
onoremap il( :<c-u>execute "normal! ?)\rvi("<cr>
onoremap in{ :<c-u>execute "normal! /{\rvi("<cr>
onoremap il{ :<c-u>execute "normal! ?}\rvi("<cr>
Then you can just type cin(
to replace the text inside the next pair of parentheses. You could also do cil(
to replace inside the most recent pair of parentheses (n
for "next" and l
for "last"). As you see I've also got this set to work with braces, and one could also do square brackets, quotes, etc. Since this is an operator map I can also type din(
if I just want to delete the text without replacing it, or any other operation that acts on a range of text.
I first learned this mapping in this tutorial: http://learnvimscriptthehardway.stevelosh.com/, which I highly recommend.
Upvotes: 4
Reputation: 4202
Double quotes and single quotes work by default the way you're describing.
Try the plugin https://github.com/wellle/targets.vim to make it work with parenthesis etc. This plugin adds some more text objects too.
Upvotes: 4