English 中文(简体)
删除正文中正文部分的正文部分。
原标题:Remove block of text in vim with regex

I have a file with:

mr l 0x19600000 0x00004341
mr l 0x19600004 0x00004820
mr l 0x19600008 0x00003130
mr l 0x1960000c 0x00003920

我想逐行的最后一行。 因此,在我上述例子中,我想删除。

0x00004341
0x00004820
...

等等。

档案由大约4 000个牢房组成,因此,我猜测一个小区是这样做的途径。 迄今为止,我一直在徒劳地试图这样做。

因此,问题是如何做到这一点的?

问题回答

您可在第1条<代码>0x00004341之前将曲线移至空间,然后将Ctrl移至直观型,G,以至缓冲结束, E /kbd>删除。

或者,你可以操作:

%s/^(.* )[^ ]+$/1/g

这里简单一条:

:%s/ [^ ]+$//g

这里有一些解释:

  %      for the whole document
  s      substitute
  /      begin substitution pattern
         a space
  [^ ]   anything but a space
  +     one or more of the previous pattern (must escape + with )
  $      end of line
  /      end substitution pattern/begin replacement pattern
  /      end  replacement pattern (i.e. replace with empty string)
  g      perform multiple times per line (does nothing here)

如果你想要删除最后一部分:

:%s/[^ ]*$

如果你想要拆除最后一部分及其主要空间:

:%s/ *[^ ]*$

概括所有线,你可以采取宏观行动:

qq
0
3f <-- space
D
q

之后:

:%norm @q

还开展工作:

:%s/\%>15c.//g

第15栏中删除。





相关问题
Autoupdate VIM Plugins?

Is it possible to update vim plugins automatically?

how to unindent in vim without leaving edit mode?

I m writing a lot of python code recently, and i used the tab-to-space mode in vim. I was just wondering how would i unindent in vim without leaving edit mode for example after i finished if...: block....

Scrolling inside Vim in Mac s Terminal

I ve been googling around trying to figure out if it s possible to use my mouse wheel to scroll while inside Vim in Mac s Terminal, with no luck. It seems as if only X11 or iTerm support this. Before ...

Vim - Deleting XML Comments

How do I delete comments in XML? If the opening and the closing comment tags are on the same line, I use :g/^<!--.*-->$/d to delete the comment. How to delete the comments that are spread ...

Limiting a match in vim to certain filetypes?

I have the following in my .vimrc to highlight lines longer than 80 chars: highlight OverLength ctermbg=red ctermfg=white guibg=#592929 match OverLength /\%81v.*/ This works quite well. However, the ...

Profiling Vim startup time

I’ve got a lot of plugins enabled when using Vim – I have collected plugins over the years. I’m a bit fed up with how long Vim takes to start now, so I’d like to profile its startup and see which of ...

热门标签