Vim Tips Wiki
Register
(Change to TipImported template + severe manual clean)
(Change <tt> to <code>, perhaps also minor tweak.)
(2 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
|previous=914
 
|previous=914
 
|next=916
 
|next=916
|created=April 18, 2005
+
|created=2005
 
|complexity=basic
 
|complexity=basic
 
|author=Ethan Mallove
 
|author=Ethan Mallove
 
|version=6.0
 
|version=6.0
 
|rating=12/7
 
|rating=12/7
  +
|category1=
  +
|category2=
 
}}
 
}}
I re-fell in love with <tt>:g/</tt> when I discovered <tt>norm f{char}</tt>. In the following sample text, say you want to delete the two words between the name and the IP address, and "has address" isn't spelled the consistently throughout (preventing us from using <tt>:s/has address//</tt>). You can do this:
+
I re-fell in love with <code>:g/</code> when I discovered <code>norm f{char}</code>. In the following sample text, say you want to delete the two words between the name and the IP address, and "has address" isn't spelled the consistently throughout (preventing us from using <code>:s/has address//</code>). You can do this:
   
 
<pre>
 
<pre>
Line 19: Line 21:
   
 
<pre>
 
<pre>
yahoo.com hav address 216.109.112.135
+
yahoo.com has address 216.109.112.135
yahoo.com has addrwss 66.94.234.13
+
yahoo.com is address 66.94.234.13
google.com hqs address 216.239.37.99
+
google.com is IP 216.239.37.99
google.com has zddress 216.239.57.99
+
google.com has IP 216.239.57.99
google.com has addrers 216.239.39.99
+
google.com has address 216.239.39.99
msn.com has addresr 207.68.172.246
+
msn.com has address 207.68.172.246
vhost.sourceforge.net has addsess 66.35.250.210
+
vhost.sourceforge.net is address 66.35.250.210
 
</pre>
 
</pre>
   

Revision as of 05:56, 13 July 2012

Tip 915 Printable Monobook Previous Next

created 2005 · complexity basic · author Ethan Mallove · version 6.0


I re-fell in love with :g/ when I discovered norm f{char}. In the following sample text, say you want to delete the two words between the name and the IP address, and "has address" isn't spelled the consistently throughout (preventing us from using :s/has address//). You can do this:

:g/\d\+\.\d\+\.\d\+\.\d\+/norm f w2dw

The above command changes this:

yahoo.com has address 216.109.112.135
yahoo.com is address 66.94.234.13
google.com is IP 216.239.37.99
google.com has IP 216.239.57.99
google.com has address 216.239.39.99
msn.com has address 207.68.172.246
vhost.sourceforge.net is address 66.35.250.210

to this:

yahoo.com 216.109.112.135
yahoo.com 66.94.234.13
google.com 216.239.37.99
google.com 216.239.57.99
google.com 216.239.39.99
msn.com 207.68.172.246
vhost.sourceforge.net 66.35.250.210

References

Comments

Or you could use :s

:%s/\s\zs\w\+\s\+\w\+//

Actually, this would work ':%g//norm f w2df ', assuming that the columns are separated by spaces instead of tabs.