octopusgrabbus
octopusgrabbus

Reputation: 10695

Do vim or gVim commands exist to copy text between parentheses?

In the following code snippet, if I go to the first open parenthesis ( of the line beginning with (spit

(defn missing-accts 
    "Prints accounts found in one report but not the other."

    [report-header mapped-data out-file]
    (spit out-file (str "\n\n    " 
          (count mapped-data) 
          "   " report-header 
          "\n\n") :append true)
          .
          .
          .

vim highlights the first ( and closing ) parentheses.

Is there and, if there is, what is the vim command that would yank the entire spit command?

Thanks.

Upvotes: 4

Views: 511

Answers (3)

Brian Agnew
Brian Agnew

Reputation: 272417

The sequence

va(

will highlight from the opening to closing brackets inclusively, and a y will then yank that. Note unlike the % command, you don't have to be positioned on the bracket - you just need to be inside the clause.

Note that

vi(

would highlight everything inside the brackets, but not the brackets.

You can do this for braces too ({ instead of () and XML tags (t - presumably for tag)

Upvotes: 9

thb
thb

Reputation: 14464

Vim does have such a command, and fortunately it is very simple. Just type y%.

The reason this works is that % is what Vim calls a movement command. It moves from one delimiter to the matching delimiter -- in your case from the opening parenthesis to the closing one. The y command yanks a single line into Vim's buffer if invoked as yy, but the second y is not required. Instead, one can issue a movement like %, whereupon Vim will yank the text moved over. Thus, y%.

Upvotes: 7

nav_jan
nav_jan

Reputation: 2553

use % with y. press "y" once then "%" ,your cursor should be on "(" when you type the command.

Upvotes: 2

Related Questions