vim - Deleting specific patterns without deleting the whole lines -
say want remove comment blocks in source code without deleting whole lines on. it's possible achieve using
:%s/\/\*.*\*\// command. wondering, there specific delete command this, or replacing matched pattern best approach? difference wouldn't much, i'm curious.
replacing nothing idiomatic 'delete pattern' operation.
:%s/pattern//g if want blank lines contain pattern, in example, obvious solution add wildcard matches around pattern.
:%s/.*pattern.*// an alternative use :global normal mode or ex command. these 2 achieve same thing:
:g/pattern/normal! s :g/pattern/delete|put! _ by way, while don't recommend using abbreviated command names in scripts or in code other people might see, think it's fine use them interactively. tend abbreviate such commands :g/pattern/norm! s , :g/pattern/d|pu!_.
Comments
Post a Comment