Prev topicNext topicHelp

Topic 14 of 29: vi

Sat, Apr 11, 1998 (02:41) | Paul Terry Walhus (terry)
vi is a unix text editor. It comes with nearly every UNIX system.

8 responses total.

 Topic 14 of 29 [unix]: vi
 Response 1 of 8: Stacey Vura (stacey) * Sat, Apr 11, 1998 (02:41) * 1 lines 
 
but it is NOT very user friendly!


 Topic 14 of 29 [unix]: vi
 Response 2 of 8: Dr. Uzkuzz K'Bugg-E'Bukk  (CotC) * Mon, Aug  3, 1998 (11:28) * 1 lines 
 
http://www.math.fu-berlin.de/~guckes/vi/


 Topic 14 of 29 [unix]: vi
 Response 3 of 8: Paul Terry Walhus (terry) * Wed, Jun 23, 1999 (12:28) * 12 lines 
 
How do you do globabl substitutions with vi?

I know to substitute one thing you use

s /old/new

And the man page says:

[range] s[ubstitute] [/pattern/replace/] [options] [count] [flags]
[range] & [options] [count] [flags]
[range] ~ [options] [count] [flags]
Make substitutions.


 Topic 14 of 29 [unix]: vi
 Response 4 of 8: Paul Terry Walhus (terry) * Wed, Jun 23, 1999 (13:07) * 32 lines 
 
3.0 - How do you do a search and replace?
Well, there are a few methods. The simplest is: :s/old/new/g
But, this only does it on the current line... So: :%s/old/new/g
In general: :[range]s/old/new/[cgi]
Where [range] is any line range, including line numbers, $ (end of
file), . (current location), % (current file), or just two numbers with
a dash between them. (Or even: .,+5 to mean the next five lines).
[cgi] is either c, g, i, or nothing. c tells vi to prompt you before
the changes, g to change all of the occurrences on a line. (type yes
to tell vi to change it.) i tells vi to be case insensitive on the
search. The g after the last slash tells it to replace more than just
the first occurrence on each line. Another method is:
:g/foobar/s/bar/baz/g This searches for foobar, and changes it to
foobaz. It will leave jailbars alone, which the other method will not.
Unfortunately, if jailbars appears on the same line as foobar, it will
change, too.
Of course you can also use regular expression search patterns, and a
few other commands in the replacement part of the text. If you use \(
and \) in the pattern to escape a sequence (and use \1, \2, etc., you
can do lots of nifty things. For example:
:g/foo/s/^\([^ ]*\) \([^ ]*\)/\2 \1/
will swap the first and second words on every line containing "foo".
Special sequences allowed are:
& everything which was matched by the search
\[1-9] The contents of the 1st-9th \(\) pair
\u The next character will be made uppercase
\U The characters until \e or \E will be made uppercase
\l The next character will be made lowercase
\L The characters until \e or \E will be made lowercase
\[eE] end the selection for making upper or lowercase




 Topic 14 of 29 [unix]: vi
 Response 5 of 8: Paul Terry Walhus (terry) * Wed, Nov 10, 1999 (10:54) * 5 lines 
 
That search and replace was so useful today!

/%s/wearfree/poolgoods/g




 Topic 14 of 29 [unix]: vi
 Response 6 of 8: Marcia  (MarciaH) * Wed, Nov 10, 1999 (20:58) * 1 lines 
 
Everything back in order yet? Never came in here before. Very Cool and extremely edgy!!!


 Topic 14 of 29 [unix]: vi
 Response 7 of 8: Marcia  (MarciaH) * Wed, Nov 10, 1999 (21:14) * 16 lines 
 
Some URLs I picked up in my efforts to learn vi

The Vi/Ex Editor
http://www.networkcomputing.com/unixworld/tutorial/009/009.html


Beginners guide to Unix, vi, and X_Windows
http://www-jics.cs.utk.edu/I2UNIX/unix_guide/unix_guide.html

Editing Files using vi
http://www.mhpcc.edu/training/vitecbids/UnixIntro/Editors.html#vi


Vi Text Editor
http://www.ms.washington.edu/help/editors/vi.html



 Topic 14 of 29 [unix]: vi
 Response 8 of 8: Paul Terry Walhus (terry) * Sat, Dec 29, 2001 (11:43) * 3 lines 
 
:%s/href="[^"]*"/\L&/

makes urls lowercase.

Prev topicNext topicHelp

unix conference Main Menu