anw@nott-cs.UUCP (05/18/88)
In article <7549@boring.cwi.nl> dik@cwi.nl (Dik T. Winter) writes: >In article <727@sjoerd.cs.vu.nl> sjoerd@cs.vu.nl (Sjoerd Mullender) writes: > > [direct substitute v. global version] > > But on the whole the forms are similar enough so that you can use either. >All very true, but there is another difference: performance. Try a 8192 >line file were all lines contain the text pattern only; time the two >commands. On a VAX 780 the :%s form will do it in about 6 seconds; the >:g form needs more than 3 minutes. There is obviously scope for an interesting benchmark here. I *did* try it -- PDP 11/44 running a much-hacked V7, file == 8192*"qwertyuiop", and substituting "/qwertyuiop/fred/" -- and it took 18 seconds for the s form and just over 16 minutes for the g form. (Ed, not vi, which we don't have on this machine.) Reasons for the *relatively* poor performance are solicited! >The reason: > [for :g] the searching is a n squared process, each and > every time the file will be searched from the first line to find > the next marked line. the reason is obvious: all kinds of > commands may follow that disrupt the order of the file. Yes, but there is a relatively easy hack: keep track of the next-possibly-marked-line; the search can then run from this line, stopping on reaching the last line. Usually, the n-p-m-line is the line after the previous marked line (or initially line 1), but it will be updated in a reasonably obvious way by deletions, insertions or moves. The search will then be linear in most cases, including g/pattern/d g/pattern/s//fred/ g/pattern/.,+5m-5 g/^/m0 # "reverse" a file and be quadratic only in cases such as g/pattern/$m0 (in these last two cases, the run-time behaviour will be respectively quadratic and cubic in vanilla ed/vi, 'cos the move takes longer as the "range" gets longer). -- Andy Walker, Maths Dept, Nott'm Univ, UK. anw@maths.nott.ac.uk
hansm@cwi.nl (Hans Mulder) (05/24/88)
In article <549@bnlux0.bnl.gov> como@bnlux0.bnl.gov (Andrew Como) writes: > >What is the command to go to the end of the file. G > " " " " " " " " beginning of the file. 1G In general, type nG to go to line n. >Is there a mechanism to re-define keys. Type :map! ^V then hit the key, type a space, and then the definition. End it with an <esc>. (the ^V represents a control-V) >Is there a mechanism to bind a command to a key Type :map ^V then hit the key, type a space, and then the definition. End it with an <esc>. The difference between :map! type bindings and :map type bindings is that the former are used in insert mode, and the latter in command mode. In both cases it is possible to switch mode within such a definition. Keep in mind that vi does not automagically switch back. The definition is just a sequence of keystrokes which would be legal in that mode, except that some "special" characters like backspace and escape must be quoted with a ^V. To obtain a literal ^V, you need to type four of them. You can list the current :map! or :map bindings by typing :map! and :map respectively. If you want to keep such bindings across vi sessions, put the :map! commands in a file named .exrc in your home directory. -- Hans Mulder hansm@cwi.nl mcvax!hansm
gilbert@cs.glasgow.ac.uk (Gilbert Cockton) (05/26/88)
In article <37200005@uiucdcsm> wsmith@uiucdcsm.cs.uiuc.edu writes: >Is there a single letter command that re-executes the same [fFtT] command? ; -- Gilbert Cockton, Department of Computing Science, The University, Glasgow gilbert@uk.ac.glasgow.cs <europe>!ukc!glasgow!gilbert The proper object of the study of humanity is humans, not machines
fowser@vax1.acs.udel.EDU (Scott Fowser) (06/17/88)
I am trying to map the key K so that it puts the buffer "p and deletes a single character. I use the following command: :map K "pPx When K is pressed, the command works fine the first time, but the buffer, "p is deleted and can't be used again. Does anyone know what I am doing wrong? Is there a way to do the mapped command 50 times in a row? 50K will not repeat the command 50 times.
como@max.bnl.gov (Andrew T. Como) (10/12/89)
I have a question about "vi"...If you are editing a file and want to look at another file (just for reference) is there a way? I have tried ":r filename" and it appends the filename to the original file. Also how can I keep switching from file1 to file2 without "setting autowrite". como@bnl.gov BITNET: como@bnl.BITNET UUCP: ....philabs!sbcs!bnl!como
larry@macom1.UUCP (Larry Taborek) (10/16/89)
From article <1494@bnlux0.bnl.gov>, by como@max.bnl.gov (Andrew T. Como): > > I have a question about "vi"...If you are editing > a file and want to look at another file (just for reference) > is there a way? > > I have tried ":r filename" and it appends the filename to > the original file. Try ":!{cat,more,pg,head,tail} filename" It will list the file on your screen and then let you continue to edit your file. > > Also how can I keep switching from file1 to file2 without > "setting autowrite". > You can edit multiple files in a single vi session just by starting it with multiple file names as arguments like. vi filename1 filename2 filename3... Then you can switch to the next with the :n command, but you MUST write the file you are editing before moving on to the next or you will loose your editing changes. Hope this helps... -- Larry Taborek ..!uunet!grebyn!macom1!larry Centel Federal Systems larry@macom1.UUCP 11400 Commerce Park Drive Reston, VA 22091-1506 My views do not reflect those of Centel 703-758-7000
itkin@mrspoc.Transact.COM (Steven M. List) (10/18/89)
como@max.bnl.gov (Andrew T. Como) writes: > I have a question about "vi"...If you are editing >a file and want to look at another file (just for reference) >is there a way? Yup - you can "edit" an alternate file with ":e filename". > Also how can I keep switching from file1 to file2 without >"setting autowrite". This is what's known as "editing an alternate file". The last file you edited in this VI session is known as "#". Thus, if you are editing file1 and file2: vi file1 file2 :n :e # :e # will first bring up file1, switch to file2, then switch back to file1. Each time you type ":e #" it switches to the last file you were editing. I define a macro in my .exrc for this: map ^A :e #^M since I do it so often. Since ^A is right by the little finger of my left hand, it's awfully easy to use. -- +----------------------------------------------------------------------------+ : Steven List @ Transact Software, Inc. :^>~ : : Chairman, Unify User Group of Northern California : : {apple,coherent,limbo,mips,pyramid,ubvax}!itkin@guinan.Transact.COM :
peter@ficc.uu.net (Peter da Silva) (10/18/89)
como@max.bnl.gov (Andrew T. Como) writes: > Also how can I keep switching from file1 to file2 without >"setting autowrite". Not conveniently. If you mean "how do I keep switching without writing the file", you can't. I would recommend a macro: :map g ':w|e ' -- Peter da Silva, *NIX support guy @ Ferranti International Controls Corporation. Biz: peter@ficc.uu.net, +1 713 274 5180. Fun: peter@sugar.hackercorp.com. `-_-' "You can tell when a USENET discussion is getting old when one of the 'U` participants drags out Hitler and the Nazis" -- Richard Sexton
maart@cs.vu.nl (Maarten Litmaath) (10/20/89)
itkin@mrspoc.Transact.COM (Steven M. List) writes:
\ map ^A :e #^M
How about using `^^'? (That is ctrl-^, which often equals `HOME'.)
(Of course you might find `^A' still easier.)
--
A symbolic link is a POINTER to a file, | Maarten Litmaath @ VU Amsterdam:
a hard link is the file system's GOTO. | maart@cs.vu.nl, mcsun!botter!maart
allbery@NCoast.ORG (Brandon S. Allbery) (10/20/89)
As quoted from <1989Oct17.203042.14712@mrspoc.Transact.COM> by itkin@mrspoc.Transact.COM (Steven M. List): +--------------- | como@max.bnl.gov (Andrew T. Como) writes: | > Also how can I keep switching from file1 to file2 without | >"setting autowrite". | | I define a macro in my .exrc for this: | | map ^A :e #^M +--------------- Those who don't understand vi are condemned to reinvent it.... Try ^^ (often CTRL-6 or CTRL-SHIFT-6). (This will fail on a terminal or terminal emulator using a Televideo-style emulation, including Wyse 50s, since ^^ is the HOME key and vi maps it to the H command.) ++Brandon -- Brandon S. Allbery, moderator of comp.sources.misc allbery@NCoast.ORG uunet!hal.cwru.edu!ncoast!allbery ncoast!allbery@hal.cwru.edu bsa@telotech.uucp 161-7070 (MCI), ALLBERY (Delphi), B.ALLBERY (GEnie), comp-sources-misc@backbone [comp.sources.misc-related mail should go ONLY to comp-sources-misc@<backbone>] *Third party vote-collection service: send mail to allbery@uunet.uu.net (ONLY)*
pld@hpfcso.HP.COM (Paul Dineen) (11/23/89)
Another vi question: What does vi mean when it flashes "No lines in the buffer" each time I enter the editor?
maart@cs.vu.nl (Maarten Litmaath) (11/24/89)
In article <8940002@hpfcso.HP.COM> pld@hpfcso.HP.COM (Paul Dineen) writes:
\... What does vi mean when it flashes
\
\ "No lines in the buffer"
\
\ each time I enter the editor?
A bug in your .exrc, probably an empty line: such a line equals a linefeed
command -> go to the next line, which doesn't exist in a new file.
--
[...] like a roving gang. "Ah, here's a NEW almost-empty group to post train
schedules and core dumps in!" (Joe Buck) | maart@cs.vu.nl, mcsun!botter!maart
mende@athos.rutgers.edu (Bob Mende Pie) (08/29/90)
I want to set up a map statment in vi to allow a program to be run with all of the files that vi is to be edited as arguments. For example, if I were to invoke vi with "vi foo bar baz", I want to say :!command foo bar baz. I know that I can get the current file with %, but I want somthing closer to what :args prints (without the [] around the current file). Is there any way to do this. /Bob... -- {...}!rutgers!mende mende@cs.rutgers.edu mende@zodiac.bitnet
was@hp-lsd.COS.HP.COM (Bill Stubblebine) (09/01/90)
mende@athos.rutgers.edu (Bob Mende Pie): > I want to set up a map statement in vi to allow a program to be run with > all of the files that vi is [editing] as arguments. I know of no vi internal command that will do what you ask. (That is not to say, of course, that there isn't one. :-) ) As an alternative, why not invoke vi via a shell script that makes the file names visible in the shell environment: export files="file1 file2 file3" (or export files=$*, to generalize) vi "+map L :!ls $files^M" $files (substitute your favorite shell command or mapped key in the 'map' directive) Obligatory control character caution: Assuming you are editing the above shell script with vi (seems logical, given the basenote), the ^M (carriage return) code in the map command is entered as cntl-V cntl-M. Putting the ^M in the map directive relieves the operator of the terrible burden of hitting 'return' after hitting the mapped character. Then, whilst in vi, typing 'L' will execute the shell escape with the desired file names. This works for me. This method has one limitation: changes to the argument list made within vi, e.g., ":n file4 file5 file6", won't update the shell environment. If you need to invoke vi with flags, the shell script may need to create separate lists (under different environment variable names) to hold flags and file names passed to the script above on the command line. Creating these separate lists shouldn't be too hard to do (see getopt(1)). Bill Stubblebine Hewlett-Packard Logic Systems Div. 8245 N. Union Blvd. Colorado Springs, CO 80920 was@hp-lsd.hp.com (Internet) (719) 590-5568
como@max.bnl.gov (Andrew T. Como) (09/11/90)
Is there a way to change a word case....(ie...from lower to upper) Andrew Como INTERNET: como@bnl.gov BITNET: como@bnlux0.BITNET UUCP: ...philabs!sbcs!bnl!como or bnlux0!como@uunet.uu.net
lee@sq.sq.com (Liam R. E. Quin) (09/11/90)
como@max.bnl.gov (Andrew T. Como) writes: >Is there a way to change a word case....(ie...from lower to upper) Some versions of vi let you say ~w to do this. You can also make a macro using \U and \L, except that \L is broken in SunOS vi. Here is a version using \U to make an uppercase word. :map! ^B ^V^V ^V^[bywPbi:s/!\(^V^[els\)/\U\1/!^V^[F:"zd3f/@z^V^M (You have to turn ^B into control-B, etc. first) If you put this in your .exrc, you can delete the first ^V if you want. This macro is inelegant in that it uses replace, and also uses f and F, so it affects the , and ; commands. You can't quite undo it (you get a spurious ! left over), and it clobbers the & command too. But it is easier than typing... Another way would be to use !w, but that doesn't work :-( :-( Lee -- Liam R. E. Quin, lee@sq.com, SoftQuad Inc., Toronto, +1 (416) 963-8337 /text/humour/quote: No such file or directory
dalessio@motcid.UUCP (Mario D'Alessio) (09/12/90)
como@max.bnl.gov (Andrew T. Como) writes: >Is there a way to change a word case....(ie...from lower to upper) > Andrew Como INTERNET: como@bnl.gov > BITNET: como@bnlux0.BITNET > UUCP: ...philabs!sbcs!bnl!como > or bnlux0!como@uunet.uu.net Use the tilde (~) key to change case. In some vi's, you can specify the number of chars to change with the command x~ (where x is a number: eg. 4~ changes the case of 4 characters). ****************************************************************************** * ************************************************************************** * * * * * * * Mario D'Alessio Motorola, Inc. * * * * dalessio@motcid.UUCP Cellular Infrastructure Division * * * * * * * ************************************************************************** * ******************************************************************************
les@chinet.chi.il.us (Leslie Mikesell) (09/12/90)
In article <2112@bnlux0.bnl.gov> como@max.bnl.gov (Andrew T. Como) writes: >Is there a way to change a word case....(ie...from lower to upper) Not exactly, there's n~ where n is the (optional) number of letters to switch case, or there's the ex mode \U in a regex replacement that makes the following substitution in uppercase: :s/.*/\U&/ will uppercase the whole line Maybe someone has a nifty macro to do a word at a time. Les Mikesell les@chinet.chi.il.us
wyle@inf.ethz.ch (Mitchell Wyle) (09/12/90)
In <2112@bnlux0.bnl.gov> como@max.bnl.gov (Andrew T. Como) asked: >Is there a way to change a word case....(ie...from lower to upper) I answered his query with an incorrect response. He flamed me for trying to help him. My response to his flame (below) contains a correct solution to his problem. It has different tradeoffs from other posted replies. It does not assume the tilde function; it does not clobber &. It does create a temporary line after the current paragraph, which the cause your cursor to jump around. Here is my solution and my reply to Mr. Como's flame. I don't usually flame people trying to give me help, but I guess my kind should be banned -oops- band from the matrix... 8-O >The question was "how to change a word case" your answer >rtfm? (read the fine manual) > ^^^^ >:%s/[a-z]/\u/g > >is unitelligible and ineffective. Thanks for showing me your The last line was a vi command for changing the case of all letters; to apply it only to a word, one can (according to the manual) use a sequence of vi keystrokes such as: madw}p0:s/./\u&/g^V^Mdw`ahp where the ^V is a control V and ^M is a control M You can then map this keystroke sequence to a more convenient one as in map ;cw madw}p0:s/./\u&/g^V^Mdw`ahp and put that line in your EXINIT or ~/.exrc The macro marks the current position (at the begining of the word whose case you want to change) with marker a. deletes the word into the delete buffer, puts it a paragraph lower, changes its case, and puts the upper-case word back. If you are running on a slow terminal, you can watch each step. I expect there are more elegant solutions; this one works for me, though. >intelligence. Its people like you that should be band from the >network because of your attitude I don't normally reply to flames, especially from people whom I was trying to help. Thanks for posing an interesting vi problem, though. I might add it's solution to my vi book. Thanks also for the flame; it goes into my collection. Yours is mild compared to some of them in German. German is a better language for flaming. -Mitch
whkr@ciba-geigy.ch (Hans Kraft) (09/13/90)
The proposal map ;cw madw}p0:s/./\u&/g^V^Mdw`ahp could have problems on the beginning of a line or in one line files. Next try: map ^K^U madwo^[p0:s/./\u&/g^Mdw`aPjdd`a ? Hans Kraft (Giovanni Forza)
lwv27@CAS.BITNET (09/27/90)
I am using the showmode option on my vi (from SunOS 4.1). I have found a pecularity that I wondered if was typical. If I am in command mode and type an i, I get a 'mode line' msg that I am in insert mode. BUT, if I have a map which puts me into insert mode, I do NOT get the mode line msg. That seems to me to defeat the purpose of showmode - sometimes I end up in insert mode and vi doesn't tell me. Is there something that can be done in a map so that showmode will recognize the transition? Also, I know that some of you folks out there are so talented that you write things like turning machines in vi macros :-), so I am wondering if anyone has written a utility which could read a .exrc type file and describe, in english, what vi actions the maps translate into? For instance, if this utility encountered a: map V Gz- it might output: command mode V go to end of current file, position current line at bottom of scree Seems like it should not be TOO hard, and would make trying to remember rather cryptic mappings like: map ^[[225z 0mzi-^[}:'z,.s/-/^B/g^M`zxO.pl 1^M.ll 6i^M.na^M.nh^M.tr ^B^M.eo^M.c2 a little easier to figure out later... -- Larry W. Virden Business: UUCP: osu-cis!chemabs!lwv27 INET: lwv27%cas.BITNET@CUNYVM.CUNY.Edu Personal: 674 Falls Place, Reynoldsburg,OH 43068-1614 Proline: lvirden@pro-tcc.cts.com America Online: lvirden CIS: [75046,606]
edp367s@monu6.cc.monash.edu.au (Rik Harris) (10/01/90)
lwv27@CAS.BITNET writes: >I am using the showmode option on my vi (from SunOS 4.1). I have found >a pecularity that I wondered if was typical. If I am in command mode and >type an i, I get a 'mode line' msg that I am in insert mode. BUT, if I >have a map which puts me into insert mode, I do NOT get the mode line msg. >That seems to me to defeat the purpose of showmode - sometimes I end up in >insert mode and vi doesn't tell me. You probably won't like this, but my suggestion is to use 'vi' enough so that you don't need showmode. There are very few people I know, who are 'vi regulars/experts', still use showmode...it slows down screen updates :-) Once you've used vi enough, most of the time you are typing ahead of the screen anyway :-) >Also, I know that some of you folks out there are so talented that you >write things like turning machines in vi macros :-), so I am wondering >if anyone has written a utility which could read a .exrc type file and >describe, in english, what vi actions the maps translate into? I suppose so, but I don't think anyone would bother. >Seems like it should not be TOO hard, and would make trying to remember > rather cryptic mappings like: >map ^[[225z 0mzi-^[}:'z,.s/-/^B/g^M`zxO.pl 1^M.ll 6i^M.na^M.nh^M.tr ^B^M.eo^M.c2 > a little easier to figure out later... ever heard of comments. The version I have accepts " (double quotes) as a begin comment, and everything else on the line is ignored. rik. ps. to reddy@lion.austin.ibm.com... I can't seem to send mail to you...just wanted to say thanks for the fix for "no tail recursion" it works fine! -- Rik Harris - edp367s@monu6.cc.monash.edu.au | Build a system that Faculty of Computing and Information Technology, | even a fool can use, Monash University, Caulfield Campus, Australia | and only a fool will (say that with your mouth full!) | want to use it.
Dan_Bloch@TRANSARC.COM (12/11/90)
Since all the expert experts are coming out of the woodwork, I thought I'd bring out my only currently outstanding vi question. Does anyone know what the "sourceany" option does? It doesn't exist on all versions of vi, but I've seen it on 3.7 and SVR3.1, running under Ultrix and SunOS 4.0 and 4.1. The default is "nosourceany." I've never seen it documented anywhere. Anyone? Dan
news@massey.ac.nz (USENET News System) (04/17/91)
Get VI to recognize a pattern of two 4 lettered uppercase words and insert a comma in them for eg XHLP XCEL APPL XCEL STAK WILD STAK WILD STAK WILD and make them XHLP,XCEL APPL,XCEL STAK,WILD STAK,WILD STAK,WILD In the above case it is easy, but I want a command which will do it for a pattern like this anywhere in the file. Thanx Raminder PS Is there a good book for VI. The man page is quite useless.
ekw@world.std.com (Elliott C Winslow) (04/17/91)
In article <1991Apr16.234809.23553@massey.ac.nz> R.Singh@massey.ac.nz (R. Singh) writes: >Get VI to recognize a pattern of two 4 lettered uppercase words and insert >a comma in them >for eg >XHLP XCEL >APPL XCEL >STAK WILD >STAK WILD >STAK WILD >and make them >XHLP,XCEL >APPL,XCEL >STAK,WILD >STAK,WILD >STAK,WILD That does it once per line; you want multiple, stick the ubiquitous '/g' at the end (no quotes). BTW, this has been a great newsgroup for learning the tricks to vi. Thanks to all. --Elliott
peter@ficc.ferranti.com (peter da silva) (04/18/91)
In article <1991Apr16.234809.23553@massey.ac.nz>, news@massey.ac.nz (USENET News System) writes: > Get VI to recognize a pattern of two 4 lettered uppercase words and insert > a comma in them :s/\<\([A-Z][A-Z][A-Z][A-Z]\) \([A-Z][A-Z][A-Z][A-Z]\)\>/\1,\2/ Add range, global suffix, etc... -- Peter da Silva. `-_-' peter@ferranti.com +1 713 274 5180. 'U` "Have you hugged your wolf today?"
lewis@tramp.Colorado.EDU (LEWIS WILLIAM M JR) (04/18/91)
In article <1991Apr16.234809.23553@massey.ac.nz> R.Singh@massey.ac.nz (R. Singh) writes: >Get VI to recognize a pattern of two 4 lettered uppercase words and insert >a comma in them > >for eg > >XHLP XCEL >APPL XCEL > >and make them > >XHLP,XCEL >APPL,XCEL > Examples abbreviated. Instead of vi, use any AT&T version of 'ed' later than V7: g/[A-Z]\{4\} [A-Z]\{4\}/s/ /,/g If you don't know about \{n,m\} closures, see McGilton and Morgan "Introducing the Unix System" and if the version of 'ed' that came with your UNIX system doesn't support closures, get the real thing.
paul@aqua.ccit.arizona.edu (Paul Sanchez) (04/18/91)
how about :%s/\([A-Z][A-Z][A-Z][A-Z]\) \([A-Z][A-Z][A-Z][A-Z]\)/\1,\2/g by the way, you didn't specify what the separator was to be. this solution assumes blank, but if you want something else (or a set of things), put an appropriate subtitution for the blank above. e.g. - "." will match anything. [ ,:;] will match any of space, comma, colon, semicolon.
les@chinet.chi.il.us (Leslie Mikesell) (04/18/91)
In article <1991Apr16.234809.23553@massey.ac.nz> R.Singh@massey.ac.nz (R. Singh) writes: >Get VI to recognize a pattern of two 4 lettered uppercase words and insert >a comma in them > >XHLP XCEL =>XHLP,XCEL >In the above case it is easy, but I want a command which will do it for a >pattern like this anywhere in the file. :%s/\<\([A-Z][A-Z][A-Z][A-Z]\) \([A-Z][A-Z][A-Z][A-Z]\)\>/\1,\2/ This assumes that there is always a single space between the words which you want to change into a comma. If not, you would need to replace the space above with something to match whatever might be there. If you do a lot of this, you might want to put the ex commands in a file and :source them. Les Mikesell les@chinet.chi.il.us
newlin@hpfcdc.HP.COM (Doug Newlin) (04/20/91)
The best book on vi there is: The Ultimate Guide the VI and EX Editors From Hewlett-Packard and The Benjamin/Cummings Publishing Co. ISBN 0-8053-4460-8 Order from The Benjamin/Cummings Publishing Co. 390 Bridge Parkway Redwood City, CA 94065
wyle@inf.ethz.ch (Mitchell Wyle) (04/22/91)
In <9800001@hpfcdc.HP.COM> newlin@hpfcdc.HP.COM (Doug Newlin) tells us: >The best book on vi there is: > The Ultimate Guide the VI and EX Editors and although it is better than the other two I've read, it is still quite poor at o bringing beginners up to speed o explaining macros, tags, or advanced topics adequately Unless someone else beats me to the punch, I intend to write a better book about vi.