Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign text with in braces into variable in vim

Is there any way to get data with in braces, before a certain latex command (\body) and assign that content (long text) to a variable.

eg:

\text{just a text before body} \body{contains lot of paragraphs etc etc etc, and that paragraphs also contains lot of latex command like \textbf{my name} and \textit{text} etc. but i want all the content with in the brace} \text{just a text after body}

i need

\body{contains lot of paragraphs etc etc etc, and that paragraphs also contains lot of latex command like \textbf{my name} and \textit{text} etc. but i want all the content with in the brace} in a variable

I want some search and replace in it. thats why

i did a macro to yank text with in braces by the help of % (to search with in braces).

is there any easy way to do this?

thanks in advance

like image 938
Zam Avatar asked Feb 20 '16 10:02

Zam


1 Answers

You can assign everything inside the { to register a using

"ayi{

Breakdown is

"a - select register a
y  - yank 
i{ - everything inside {}

It does the right thing for matching braces

If you later need to access the contents of a you can do this in multiple different ways depending on the context - I think the ways are

"ap    : paste register a in normal mode
<C-r>a : paste register a into command line
@a     : access register in script

It's worth noting that regex is not powerful enough to do matching braces. (I think there are extensions that can make it powerful enough, but I'm not sure if vim supports any of those),

like image 160
Michael Anderson Avatar answered Sep 23 '22 04:09

Michael Anderson