|
|
This item text has been erased.
28 responses total.
This response has been erased.
Nice writeup. One correction concerning something you say at the end -- "man vi" does *not* give information on vi commands.
This response has been erased.
wow -that's a chock-full chunk!
Where do we have this listed? I have a printout and still use it. It's good enough to keep. New users might like to see it.
This response has been erased.
This response has been erased.
*z*cat? What does zcat do?
It reads a compressed file.
Thanks. ,
(Various standard & semi-standard Unix compression utilities use file extensions of .Z and .z (and now .gz) by default. Hence zcat, zmore, etc., etc.)
Could someone please supply the vi syntax for doing a replace? Specifically, I want to replace each occurrence of ">" at the beginning of a line with the null string.
This will do it for your whole file: :%s/^>//g
This will do it everywhere in lines 5-10: :5,10s/^>//g
If I say that ":" gets you into last-line mode, that "s" is the command
("substitute"), that "/" is a separator, that "^" matches beginning of
string (in this case of line), and that "g" is for "global" and says
to do them all, I expect that you can figure out how to extend this
to other replacements, right? 8-{)]
And if I say that I'm not sure what the alternatives to "g" are (my
experience being that including & omitting it seem to work the
same), I'm sure that someone will explain.
You can also add to the end a "c" (with or without the "g"), and you
will be prompted for confirmation for each replacement.
The "g" causes replacement of all occurrences on a line of the replacement pattern; omit the "g" and it will replace only the first occurrence on each line. Since Kevin wants to replace only the occurrences of ">" at beginnings of lines, he probably doesn't want to include the "g".
This response has been erased.
Thanks, John. Whatever I'd read, way back when, suggested (to my mind, anyway) that omitting the "g" would lead to replacement of only the first occurrence - which plainly didn't seem to happen. Either the "in each line" was omitted, or I missed it. (I think all the examples on that point involved an address range of a single line. <sigh>) That should be very useful, now that you've explained how it *does* work. I also would like to know how to use marks in address-range things.
Marks come from ed. In ed, you can mark a line by saying "kX", (where X
is a letter a-z) and you can then use marks in line ranges in place of
numbers.
So, if you wanted to capitalize all occurences of "the" from lines 3-6,
you could say:
3ka
6kb
'a,'bs/the/THE/g
You can use marks just the same way in command mode in vi (which is of
course just "ex"). So, ":3ka"<return> will indeed mark line 3. But you
can also mark lines directly in visual command mode, with m - "ma" will
mark a mark on the current line, just like ":ka"<return>. You can go to
a mark with 'X in visual mode - so "'a" will go to mark a. "''"p is
kind of handy - it will go back to the last place you came from - so you
can search for a string, then jump back to where you were.
I most commonly use marks for moving and shifting text blocks. In
visual mode, I can mark the start with "ma", go to the end of what I
want to shift, and say ">'a" to shift from the current line to the line
marked a. Or, if I want to move stuff, I can mark where I want to move
stuff to with "mc", then the start & end with "ma" & "mb", and then say
":'a,'bm'c"<return>
Regarding g & c. Ed doesn't support c. Both ex & ed support p there.
p will print out the last line that was changed - which saves
typing p on a separate line. ex has a "set autoprint" which defaults
on & acts as if a 'p' were always supplied. Without g, ex will
indeed only change one occurrence per line, so if the file reads:
aruba
mta
robh
and you say 1,$s;a;b;
you will get:
bruba
mtb
robh
This response has been erased.
Almost as convenient as dragging a mouse! :)
How can we list by line numbers in vi? Also, since we don't have a man page for vi, is there somewhere to ftp one for grex, or download something similar to a manual page.
This response has been erased.
:se nu
(Which is short for "set numbers". But yes, that's the way.)
There's a vi ftp archive where one can download tons of documentation. I don't have the address handy but will try to remember to look it up and post it here.
A couple of places to look for vi-related information are: http://www.cs.vu.nl/~tmgil/vi.html (The VI Lover's Home Page) and ftp://alf.uib.no:/pub/vi/ (if you ftp directly there, just cd to the vi directory--no 'pub') Apparently, ftp.uwp.edu or ftp.uu.net are supposed to have vi information but I either had a difficult time connecting or the site is being remodeled so I couldn't find what I was looking for. (uwp allows web access at http://archive.uwp.edu, although I did not see any vi documentation there when I looked). The VI Lover's page, btw, has links to a lot of vi information and would probably be my first Web choice (although you might also try Yahoo! under Computers/Software/Editors/vi). Okay, I got through to ftp.uwp.edu (/pub/vi) and it looks like alf.uib.no, which is to say, there is a fair amount of information there as well as programs for various types of computers. (Actually, it seems uwp is a mirror of alf.uib.no, so they are the same). I grabbed a few files while I was there; you probably will, too, if you are interested in vi.
To get line number listing of a document in vi , add following lines to your .cshrc file : setenv EXINIT 'se nu smd' But I am not sure how to get this line numbered listing while printing this file to printer.If anybody knows , then please let me know.
I don't think that's particularly a vi question, but variations on "cat -n file | lpr" or "egrep -n '^' file | lp" could work. Of course, ':set smd' doesn't have anything to do with line numbers. It's possible to type ':set nu' at any time to turn line numbering on, and ':set nonu' to turn it off again. I prefer to run with it it off nearly all of the time, as the numbers get in the way, and in some versions of vi, can cause display pecularities.
Thanks mdw, I am happy to know this. It was only recently that experimented with set nu etc, and learned most of vi features, when in my local server our administrator refused to install pico.
Response not possible - You must register and login before posting.
|
|
- Backtalk version 1.3.30 - Copyright 1996-2006, Jan Wolter and Steve Weiss