Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!snorkelwacker!apple!usc!samsung!uunet!microsoft!steveha From: steveha@microsoft.UUCP (Steve Hastings) Newsgroups: comp.editors Subject: Typing long commands in vi Message-ID: <56433@microsoft.UUCP> Date: 9 Aug 90 17:57:07 GMT Reply-To: steveha@microsoft.UUCP (Steve Hastings) Organization: Microsoft International Products Group Lines: 50 For "power-users" of vi or ex, here is a useful tip for typing long commands. Some long, powerful vi commands can be hard to get right in one try. For example, yesterday I wanted to convert lines of the form #define foo 99 to [[foo]]=99 and the command I used was :.,$s/^#define[ \t]\([^ \t]*\)[ \t]*\(.*\)/[[\1]]=\2/ (Where the "\t" appear above, I really hit the Tab key; vi doesn't support \t escapes in character sets.) Now, I used to get really frustrated trying to get such commands right. (These days, I get it right in two tries or less, most of the time, but it took a lot of practice!) vi has two features you can use to make this easier. The first is the :source filename command (:so filename is the abbreviation) that reads in a file. Edit a scratch file, enter the command you wish to execute, and source the file. If you didn't get it right, undo the command, switch back to the other file, and edit the command and try again. (Note that you can use :so # to source the file if you just switched back from it.) This technique is good for ex commands like g// or s///. The other way uses named buffers and the @ command. The @ command executes a command stored inside a named buffer. So open a new line right in your source text, type the command then and there, and use the yank command to put it in a named buffer. Once it is in there, execute the command as many times as you want with @. If you made a typing error or want to change the command, edit the line and yank it again. If you deleted the original line, paste that buffer back in, edit it, and yank it again. This works well with vi commands, or ex commands preceded by a colon. (Note that if you use the command :@ you are using the ex @ command instead of the vi @ command, and it will expect ex commands inside the buffer instead of vi commands.) By the way, I know that the long command I showed above for munging #define lines works. I used the @ command and named buffers to test it right from the text of this message! -- Steve "I don't speak for Microsoft" Hastings ===^=== ::::: uunet!microsoft!steveha steveha@microsoft.uucp ` \\==|