Given this line of code in C:
printf('%3.0f\t%6.1f\n', fahr, ((5.0/9.0) * (fahr-32)));
Is there a way to delete or yank from the first bold parenthesis to its matching parenthesis? I thought about df), but that only will get you to just after the 9.0.
Is there a similar way to get vim to grab everything between matching braces, regardless of newlines?
Various Motions: %
The
%command jumps to the match of the item under the cursor. Position the cursor on the opening (or closing) paren and usey%for yanking ord%for deleting everything from the cursor to the matching paren.This works because
%is a ‘motion command’, so it can be used anywhere vim expects such a command. From:help y:By default, ‘item’ includes brackets, braces, parens, C-style comments and various precompiler statements (
#ifdef, etc.).There is a plugin for ‘extended % matching’ that you can find on the Vim homepage.
You can read the documentation on
%and related motion commands by entering:help various-motionsin command mode.object-select
There is another set of motion commands that you can use in Visual mode to select various text objects.
To solve your specific problem you would do the following:
Let’s say your cursor is positioned at
^. Enter the following sequence to select the part you are looking for:First
venters Visual mode, then you specify that you want to go2levels of parens up. Finally thea)selects ‘a block’. After that you can usedorxto delete, etc.If you don’t want to include the outer parens, you can use ‘inner block’ instead:
See
:help object-selectfor the complete list of related commands.