Delete command using appropriate curly braces

I am using (mac) vim with tex-suite and would like to have one regex command (or any other way) to do the following:

Edit

\ textcolor {green} {some random text}

in

some random text

This should be done for all occurrences of \textcolor{green}{} in my tex file ...

Any idea?

EDIT: I need it to recognize the corresponding curly braces. Here is an example:

 \textcolor{green}{ with $v_\text{F}\sim10^6$ms$^{-1}$ the massless Dirac fermions velocity in pristine graphene}. 
+4
source share
2 answers

In my experience, such things most often occur during editing, and you may have a search already \textcolor{green}{ .

In this scenario :global usually my weapon of choice:

 :g//norm d%diBvaBp 

diBvaBp: diB (remove the internal block), vaB (select block), p (put) sub>

If you have surround.vim installed (recommended!), You can remove a pair of curly braces by simply doing dsB (delete around {})

 :g//norm d%dsB 

Of course you can combine it as

 :g/\\textcolor{green}{/norm d%dsB 

I just noted a potential problem when the target patterns do not start at the beginning of the line. The easiest way to get around this is

 :g//norm nNd%diBvaBp 

A more attractive way (possibly less efficient) would be to use a macro:

 /\\textcolor{green}{ gg qqd%diBvaBpnq 

Following something like 100@q to repeat the macro

+5
source
  :%s,\\textcolor{green}{\([^}]\+\)},\1,g 

Updated according to your updated question:

 :%s,\\textcolor{green},\r-HUUHAA-&,g :g/\\textcolor{green}/normal 0f\df}lvi{xhP$xx :%s/\n-HUUHAA-// 

A brief description of how this works:

  • Put all the lines \ textcolor {green} on your own line, with a special marker -HUUHAA -
  • Use the vi {visual selection to select everything between {}, paste it outside, and remove the empty {}.
  • Delete remaining items, including a marker.
+1
source

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


All Articles