halle1@houxz.UUCP (J.HALLE) (03/20/84)
Is there any way to switch to a file, do some editing, then come back to the original file? I know that :n file2 file1 will work, but that can get inconvenient when long paths must be typed in.
stanwyck@ihuxr.UUCP (Don Stanwyck) (03/20/84)
The way I switch to another file, edit, then return, is: :w :!vi file2 <edit commands> :wq <cr> It works just fine. (The first write is optional, but without it you are risking losing work if the system crashes or you lose yourself somewhere.) -- ________ ( ) Don Stanwyck @( o o )@ 312-979-3062 ( || ) Cornet-367-3062 ( \__/ ) ihnp4!ihuxr!stanwyck (______) Bell Labs @ Naperville, IL
chris@umcp-cs.UUCP (03/21/84)
You can also use :w :e otherfile ... :w :e # The pound sign expands to the "alternate" filename. There is only one alternate filename; it's the name of the file you were last editing (i.e. ":n" makes the current filename become the alternate filename). Percent sign (%) expands to the current filename. Both of these work for ":!" also. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci UUCP: {seismo,allegra,brl-bmd}!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris.umcp-cs@CSNet-Relay
davy@ecn-ee.UUCP (03/21/84)
#R:houxz:-71000:ecn-ee:17100004:000:990 ecn-ee!davy Mar 21 08:38:00 1984 There's an easier way: % vi file1 ..... ..... :w -- write out file1 :e file2 -- edit file2 ..... ..... :w -- write out file2 :e # -- go back to file1 There are advantages to this. First, you don't have to fork a shell to edit the second file. Secondly, by using ":e", all your named buffers stay the same across the edit. Thus, you can edit file1, go into file2, yank some stuff into a named buffer (e.g., "a10Y), go back to file1 by saying ":e #", and then put the text you just yanked (e.g. "ap). Some things to note: 1. Your unnamed buffers (last delete, etc.) are NOT saved between the two files. 2. If, from file2, you do another ":e", then ":e #" will take you back to file2. If you want to get back to file1, you'll have to ":e file1" again. This is because ":e #" always says "take me back to the previous file". 3. The HOME key used to be a synonym for ":e #", but this seems to have gone away in 4.2BSD. --Dave Curry pur-ee!davy
mark@elsie.UUCP (03/21/84)
I thought this was general knowledge, but from the responses so far, I guess not: You can toggle between two files in vi using the "CTRL SHIFT ~" sequence. You will need to have autowrite set (set aw) if the file has been changed. On some terminals, notably the vt100, a simple "CTRL ~" will work, but this is, apparently, a hardware bug. What the "CTRL SHIFT ~" sequence does is change you back to the previous file you were editing. Hence it can be used to toggle between files. ..!elsie!mark -- Mark J. Miller NIH/NCI/DCE/LEC UUCP: decvax!harpo!seismo!rlgvax!cvl!elsie!mark Phone: (301) 496-5688
tierney@fortune.UUCP (03/22/84)
#R:houxz:-71000:fortune:26900032:000:558 fortune!tierney Mar 21 17:43:00 1984 ***** fortune:net.unix / houxz!halle1 / 6:28 am Mar 20, 1984 Is there any way to switch to a file, do some editing, then come back to the original file? I know that :n file2 file1 will work, but that can get inconvenient when long paths must be typed in. ---------- Why, of course there is! try: (edit, edit, edit, etc. file 1) :w #save file 1 changes :e file2 #edit file2 :e# #edit the alternate file (file 1) :e XXX edits XXX :e# edits the alternate file and you can switch back and forth. Wonderful. charlie tierney
chris@umcp-cs.UUCP (03/22/84)
Actully, it's control-^ which can toggle between two files. It's a built-in macro (the same way ~ is a built-in macro) which expands to ":e #<RETURN>". This will work if you either have autowrite set or if you haven't modified the current file. [The reason you have to use control-~ on VT100s is DEC didn't put control-^ on the key with ^ (they did something similar with control-@, it's control-space-bar). Fortunately all the other control keys are where they are supposed to be.] Isn't it amazing what you can find when you read the source? -- In-Real-Life: Chris Torek, Univ of MD Comp Sci UUCP: {seismo,allegra,brl-bmd}!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris.umcp-cs@CSNet-Relay
richard@islenet.UUCP (03/23/84)
> Is there any way to switch to a file, do some editing, then come > back to the original file? I know that :n file2 file1 will work, > but that can get inconvenient when long paths must be typed in. How 'bout a simple fork? :!vi file2 -- Richard Foulk (vortex!islenet!richard)
srini@ut-sally.UUCP (Srinivasan Sundararajan) (03/29/84)
Actually, it's CTRL SHFT ^ , to toggle between files, at least on the mime2a's we use here.
hester@Uci-750a.ARPA (03/31/84)
From: "Jim Hester" <hester@Uci-750a.ARPA> Forking via ':!vi' file is nice, but if you can stop the process with ^Z and start another it's a lot faster (doesn't need a new shell). However, along the lines of the question, vi keeps track of the last file edited, and the location in the file. At any time (current file unmodified, of course) you can type ':e #' and go edit the previous file some more.
dan@rna.UUCP (Dan Ts'o) (11/07/84)
Hi, Excuse this stupid VI question... but, How in VI, visual mode to you specify a count which indicates the whole buffer ? At the moment, I either have to find out how lines there are (by ^G) and then type that in explicitly, or go into EX mode and type 1,$ How do you, for example, pipe the entire buffer into another program in visual mode ?, or delete the entire buffer without :1,$d<CR> Thanks. Dan ...cmcl2!rna!dan
chris@umcp-cs.UUCP (Chris Torek) (11/07/84)
Captial G is a line-oriented command which says ``go to end of file'', thus, to delete to end of file, type dG. (Actually, G takes a preceding count and turns it into a line number; it just defaults to EOF.) -- (This mind accidently left blank.) In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (301) 454-7690 UUCP: {seismo,allegra,brl-bmd}!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@maryland
"James M. Galvin" <galvin%udel-dewey.delaware@UDEL-RELAY.ARPA> (11/10/84)
One final note about VI. You comment that :1,d$ has the advantage of not transmitting the new screen, like 1G. If you type G by itself, you will print the last page, which VI actually only prints half a screen. You can then delete the buffer by typing d1G. Saves printing a whole screen, which is nice at slower baud rates.
notes@rna.UUCP (11/22/84)
Hi, Many thanks to the netters who mailed me their solution to me question. (i.e. you can stop now...) It still seems a little clumsy that you have to jump to the beginning of the buffer (with a 1G) before deleting the entire buffer with a dG. The :1,d$ approach has the slight advantage that you don't have to transmit the new screen after the 1G. TECO had H which meant the entire buffer. But you can't ask for everything... Cheers, Dan