Vim以最快的方式选择文本行块直到特定字符

时间:2015-12-08 20:23:26

标签: vim macros

我有一个包含wikicode(tikiwiki)的页面,其中包含类似的HTML:

{DIV(class="Act PersonInterested")}
{HTML()}
  multiple 
  lines 
  of 
  html (svg) 
  code
{HTML}
{DIV}

{DIV(class="Act CHActivePFOnly")}
{HTML()}
  multiple 
  lines 
  of 
  html (svg) 
  code
{HTML}
{DIV}

我希望vim删除{HTML()} {HTML} wiki标记之间的文本。 dt{无效...

我找到的最方便的选项是录制一个宏,就像那个:

qa   -> Records macro in register a
v/{  -> Visual selects text until next '{' symbol
q    -> Stops recording
@a   -> Applies macro from the current line

然后我移动到下一行并用' @ a'重新应用宏。等等,直到我完成清空所有标签。

我的问题是,必须有某种更快的方法,我忽略了......就像一个g:一个甚至更简单。我很高兴能够了解它,而且,我在这里找不到很多答案或者对这个具体问题不知所措。

谢谢!

4 个答案:

答案 0 :(得分:0)

你可以用:

:g/{HTML(/norm jV/HTML^Mkd

或:

^M

如果您对视觉模式更有信心。

Ctrl + V ,然后按 Enter 获取 while (x < 4){ //x = 0 System.out.print("a"); if(x < 1){ System.out.print(" "); } System.out.print("n"); if(x < 1){ System.out.print("oise");//Allowed two lines in this block x = x - 1; } if(x==1){ System.out.print("noys"); } if(x>1){ System.out.print(" oyster"); } System.out.println(""); x = x + 2; }

答案 1 :(得分:0)

我明白这个问题吗?

%s/{HTML()}\zs\_.\{-}\ze{HTML}//g

以上命令是否适用于您?

答案 2 :(得分:0)

你也可以只记录更复杂的宏,然后重复它。

qa           -> Records macro in register a  
/{html()<cr> -> Find next   
j            -> Go down one line   
d/{html}<cr> -> delete to closing html tag  
q            -> Stops recording  
100@a        -> Applies macro 100 times or less if there is no matches  

答案 3 :(得分:0)

以下就足够了

g/{HTML/,/{HTML/ d_

这假设,与其他答案一样,您的真实代码之间没有{HTML...。如果这样做,唯一可靠的方法是使用解析器。

<强>击穿

g              : start a global command
/              : separator
{HTML          : search for {HTML
/              : separator
,/{HTML/       : set a range from the previous search result up until the next {HTML tag
d_             : delete to the empty register. As I have my clipboard synchronized with deletes, without the `_`, each delete goes to my windows clipboard slowing things down a lot in large files.
相关问题