Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uwm.edu!spool.mu.edu!olivea!oliveb!felix!asylvain@felix.UUCP From: asylvain@felix.UUCP (Alvin "the Chipmunk" Sylvain) Newsgroups: comp.editors Subject: Re: VI: Positioning the cursor ("|") from within a macro doesn't work. Summary: It sure don't! Keywords: vi cursor Message-ID: <164676@felix.UUCP> Date: 15 Jun 91 01:46:17 GMT References: <1501@cacilj.UUCP> Sender: daemon@felix.UUCP Reply-To: asylvain@felix.UUCP (Alvin "the Chipmunk" Sylvain) Distribution: usa Organization: Foundation for the Increased Wealth of Chipmunks Send in your pledges now! (Visa/Mastercard accepted) Lines: 61 Written in article <1501@cacilj.UUCP> by jurgen@cacilj.UUCP (Jurgen Heymann): > I am trying to position the cursor on a specific column using a :map macro. > When I enter the command string interactively everything works fine. When I > define it as a :map macro however, the position command is not executed and > the macro execution stops there at the "|". I also tried "\|" but that didn't > help either. What can I do? > I know I could just say "077l" to go to column 77 but that only works when > there are no tabs in that line. I ran into that problem too, trying to do a similar application and ran into the same reason to use "|". I was able to find out at least why it won't work. We have _some_ documentation down here, if you know who to bug. It turns out that the ":" brings you to "ex" mode, which you probably aready knew. What you probably did not know is that the "|" character is a command separator for "ex". This means, from the "ex" colon, you could enter, say: :.,.+3d|s/fred/charlie/|s/bill/ted/|wq which will delete four lines, including the current, then on the line that becomes current, change "fred" to "charlie", "bill" to "ted", then write the file out and quit. Your best example of a use for this is outside the editor. You may have an EXINIT environment variable defined: EXINIT="set ai|set sw=8|set nomagic" export EXINIT # for /bin/sh users, other shells slightly different This performs all three "set" commands at "vi" or "ex" initialization. "ex" refuses to allow you to "quote" it's command separator, or at least our version does. I have found absolutely no way to get around that. There is a slower solution to your application. You could pipe the line into "expand" to convert the tabs to spaces, then "077l" will work just fine. Then, if you want to, you can repipe the line into "unexpand" to get the tabs back. I haven't tried it, but that might be one of very few solutions to your problem. Something like this: :map K !!expand^M077l{whatever else you want to do}!!unexpand^M The reason this is slow is because it must spawn a subshell for both "expand" and "unexpand". You can speed it up somewhat if you can live with the tabs permanently removed, saving one subshell. Alternately, just remember to run "unexpand" on the entire file when you're thru. Give it a try. I can't think of anything better. -- Alvin ===== asylvain@felix.UUCP ===== hplabs!felix!asylvain ===== "hplabs!felix!asylvain"@uunet.uu.net (I always try to respond to mail, if possible. If you don't hear back from me, try changing "hplabs" to "ccicpg," "spsd," or "lawnet.") DISCLAIMER: It's all in fun, folks, no flames intended. Any similarity between my opinion and that of my employer is purely coincidental and sufficient reason to change my opinion, although I'll still be right.