4 ms·
Here's a Vim trick I only figured out fairly recently. Everybody knows that % jumps between a bracket, brace or parenthesis and its matched pair, but what happe
by thristian 15y ago
Here's a Vim trick I only figured out fairly recently. Everybody knows that % jumps between a bracket, brace or parenthesis and its matched pair, but what happens if you hit % while the cursor isn't on such a character? Turns out, it searches forward until it finds such a character, then jumps to its matched pair.
So for example, let's say you had a nested function invocation that was getting long and unwieldy and you wanted to break it out onto its own line:
foo = makeFoo(
globalConfig.getParam(
"FooSize",
int,
default="37",
)
)
If you put the cursor on the 'g' at the beginning of 'globalConfig' and press "d%", it will cut the function name and all the parameters in one action.
- tudorizer 15y agoHat tip to you, sir.
- mnazim 15y agoIt can also be used with y and c(y%, c% etc.)
- agscala 15y agoThat is a neat trick. Even though it's one more character, the expected way to do this would be: "dt("
- tmhedberg 15y agoThat would delete just the function name (`globalConfig.getParam`), not the argument list as well. `d%` would grab the function name _and_ its argument list.
- mathias_10gen 15y agoci( is another nifty trick that will do the same but will work anywhere between the two ('s not just at the beginning of globalConfig. See ":help text-objects" for more details on one of the more powerful feature of vim.
- thesteamboat 15y agoYou can also do cib (for inside '()') and ciB (for inside '[]') and cis (for inside sentences).
- bcrescimanno 15y agoGah! I'd been wondering how to do that--thanks for the tip!
- avinashv 15y agoI very regularly do ci" or ci' to edit within strings.
- cdmwebs 15y agocit is another favorite. Try it inside HTML tags, for example.