Click to See Complete Forum and Search --> : for all you Vi people out there.
UkrainianTire
10-25-2001, 12:29 PM
Hey,
Teaching myself how to use vi... slow going but steady. First question (of many soon to follow i'm sure). Is there a replace command in Vi? In particular one that can do multiple simultaneous searches.
Thanks
X_console
10-25-2001, 12:34 PM
Check out this tutorial: http://it.yorku.ca/moonfrog/tutorials/vi_course.html
To replace all instances of a word unix with linux in a document:
:%s/unix/linux/g
UkrainianTire
10-25-2001, 12:45 PM
my only further question is what the /g means at the end of the syntax? Specifying the whole document? I noticed the tutorial had the same thing.
X_console
10-25-2001, 12:48 PM
The g means global, so yes, the entire document. If you only want to change the word "unix" to "linux" within the range of lines 25 to 60, but not anywhere else:
:25,60s/unix/linux
bdg1983
10-25-2001, 04:49 PM
Also from the commandline, type
vimtutor
AdaHacker
10-25-2001, 08:27 PM
Originally posted by X_console:
<STRONG>The g means global, so yes, the entire document.</STRONG>
Not to nit-pick, but no, not quite. The 'g' means global as in everyplace in the line, not the file. The % specifies the entire file.
Example:
s/a/b = changes the first 'a' in the current line to a 'b'.
s/a/b/g = changes all occurences of 'a' in the current line to 'b'.
% s/a/b = changes the first occurrence of 'a' in every line of the file. So if you had a line with just the word "attack", it would become "bttack".
So, basically, you need the g in order to change every occurence on the line or lines you specify. Give it a try and see how it works.
[ 25 October 2001: Message edited by: AdaHacker ]
slacker_x
10-25-2001, 08:44 PM
Originally posted by X_console:
<STRONG>Check out this tutorial: http://it.yorku.ca/moonfrog/tutorials/vi_course.html
To replace all instances of a word unix with linux in a document:
:%s/unix/linux/g</STRONG>
How similar is vi to vim? Should I read through this tutorial, or is there a better one to look at if I am using vim?
X_console
10-25-2001, 09:32 PM
AdaHacker: Not at all, thanks for the correction.
slacker_x: You'll probably find that vi is a symlink to either vim or elvis on Linux. The general usage is similar, although elvis and vim have some additional added features like syntax highlighting and such.
In short, if you can learn how to get around one type of vi, you can use any type of vi, whether it be elvis, vim, vi in BSD, vi in Solaris, etc.