How to assign text in curly braces to a variable in vim

Is there a way to get the data in braces, before a specific latex command (\ body) and assign this content (long text) to a variable.

eg:

\ text {just the text in front of the body} \ body {contains many paragraphs, etc. etc. etc., and that paragraphs also contain a lot of latex commands, for example \ textbf {my name} and \ textit {text}, etc., but I want all the content with in brackets} \ text {just text after the body}

I need

\ body {contains many paragraphs, etc. etc. etc., and that the paragraph also contains many latex commands, such as \ textbf {my name} and \ textit {text}, etc., but I want all the contents to be in brackets} in the variable

I need a search and a replacement. that's why

I made a macro to cross out the text in braces with% (for searching in braces).

Is there an easy way to do this?

early

+5
source share
1 answer

You can assign everything inside { to register a using

 "ayi{ 

Breakdown

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

It is suitable for matching braces

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

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

It is worth noting that the regular expression is not powerful enough to make the corresponding curly braces. (I think there are extensions that can make it powerful enough, but I'm not sure if vim supports any of them)

+6
source

Source: https://habr.com/ru/post/1243453/


All Articles