spring.net — live bbs — text/plain
The SpringUnix › topic 14

vi

topic 14 · 8 responses
~terry Sat, Apr 11, 1998 (03:41) seed
vi is a unix text editor. It comes with nearly every UNIX system.
~stacey Sat, Apr 11, 1998 (03:41) #1
but it is NOT very user friendly!
~CotC Mon, Aug 3, 1998 (12:28) #2
http://www.math.fu-berlin.de/~guckes/vi/
~terry Wed, Jun 23, 1999 (13:28) #3
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.
~terry Wed, Jun 23, 1999 (14:07) #4
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
~terry Wed, Nov 10, 1999 (11:54) #5
That search and replace was so useful today! /%s/wearfree/poolgoods/g
~MarciaH Wed, Nov 10, 1999 (21:58) #6
Everything back in order yet? Never came in here before. Very Cool and extremely edgy!!!
~MarciaH Wed, Nov 10, 1999 (22:14) #7
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
~terry Sat, Dec 29, 2001 (12:43) #8
:%s/href="[^"]*"/\L&/ makes urls lowercase.
log in or sign up to reply to this thread.