[comp.editors] Register Commands in Vi

benson@dcdwest.UUCP (Peter Benson) (09/20/89)

I have noted with respect the complex and powerful macros
people have generated for vi, e.g., centering lines.  I have
been trying to create a special one myself to no avail.  What
I am trying to do is create a macro that will act similar to
the tags function.  In this case, however, I would like to
position the cursor at the front of a file name, as in the "s"
in system in

.so system

and have the command

:n system

be executed.  I envision that this will be accomplished by
storing ":n " in a register, adding the file name to the
register and then executing the command in the register.  I
have tried numerous ways with no success.  Can someone think
of a solution?

PS
I use :<line,line>!ff -c to center stuff and it works quite
well.  ff is a useful program.
-- 
Peter Benson                    | ITT Defense Communications Division
(619)578-3080                   | 10060 Carroll Canyon Road
ucbvax!ucsd!dcdwest!benson      | San Diego, CA 92131
dcdwest!benson@UCSD.EDU         |

maart@cs.vu.nl (Maarten Litmaath) (09/21/89)

benson@dcdwest.UUCP (Peter Benson) writes:
\... I would like to
\position the cursor at the front of a file name, as in the "s"
\in system in
\
\.so system
\
\and have the command
\
\:n system
\
\be executed. [...]

map v ma:!:^V^M :t.^V^Mkc`a:e!^V^[ea ^V^[D^V^V"zdd@z

Explanation:

	ma		= mark the current position with `a'
	:!:^V^M		= this shell escape will force the buffer to be
	       ^	  written if it has been modified AND the option
	       space	  `autowrite' is set; all further modifications
			  due to the map are irrelevant and will be
			  discarded (see `e!' below)
			  the `:' command does nothing in sh and csh
			  the ^M (return) needs to be escaped with ^V, else
			  the map would be terminated
	:t.^V^M		= this "ex" command will put a copy of the current
			  line right below it (`yyp' seems to cause trouble)
	k		= upward one line (back to the original line)
	c`a:e!^V^[	= change till the mark `a'
			  just like ^M the escape ^[ needs to be escaped
	e		= go to the end of the next word (our filename)
	a ^V^[		= append a space, to make sure there's something to
			  delete (see `D')
	D		= delete the rest of the line
	^V^V"zdd	= delete the current line into register `z'
			  the `"' must be escaped upon the first READING of
			  the map, since it is the "ex" comment character
			  (NOTE: not necessary in some vi versions)
	@z		= execute the contents of register `z':

				:e!file^J
-- 
   creat(2) shouldn't have been create(2): |Maarten Litmaath @ VU Amsterdam:
      it shouldn't have existed at all.    |maart@cs.vu.nl, mcvax!botter!maart

steinbac@hpl-opus.HP.COM (Gunter Steinbach) (09/21/89)

This line in your .exrc should work:

map \ lb"xdEPo0:n! "xp"xdd@x
				^^execute buffer x
			    ^^^^remove the new line into buffer x
			 ^^^add the stored word to the new line
             ^^^^^^^^^^^^make new line with ":n! ", no indentation
      ^^^^^^^put the word under the cursor into buffer x

Usage: put the cursor anywhere on the file name, hit \.  You better have
previous changes saved, or they'll be lost.  Add :w
of the macro for automatic writing.

Good luck!

	 Guenter Steinbach	 |	 hplabs!gunter_steinbach
				 |	 gunter_steinbach@hplabs.hp.com

steinbac@hpl-opus.HP.COM (Gunter Steinbach) (09/21/89)

'Nother try, this time with control characters expanded - sorry!!!

This line in your .exrc should work:

map \ lb"xdEPo0^V^D:n! ^["xp"xdd@x
				^^execute buffer x
			    ^^^^remove the new line into buffer x
			 ^^^add the stored word to the new line
             ^^^^^^^^^^^^make new line with ":n! ", no indentation
      ^^^^^^^put the word under the cursor into buffer x

Usage: put the cursor anywhere on the file name, hit \.  You better have
previous changes saved, or they'll be lost.  Add :w
of the macro for automatic writing.

Good luck!

	 Guenter Steinbach	 |	 hplabs!gunter_steinbach
				 |	 gunter_steinbach@hplabs.hp.com

maart@cs.vu.nl (Maarten Litmaath) (09/23/89)

steinbac@hpl-opus.HP.COM (Gunter Steinbach) writes:
\This line in your .exrc should work:
\
\map \ lb"xdEPo0^V^D:n! ^["xp"xdd@x

Have you actually TRIED this macro?
Of course it SHOULD work, but SunOS 4.0.1 vi doesn't like it...
See my other posting for a macro that works at least on aforementioned system.
-- 
   creat(2) shouldn't have been create(2): |Maarten Litmaath @ VU Amsterdam:
      it shouldn't have existed at all.    |maart@cs.vu.nl, mcvax!botter!maart