Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!ucla-cs!lanai.cs.ucla.edu!gast From: gast@lanai.cs.ucla.edu (David Gast) Newsgroups: comp.editors Subject: Re: vi mapping difficulty Message-ID: <1991Mar13.084943.934@cs.ucla.edu> Date: 13 Mar 91 08:49:43 GMT References: <1991Mar08.205940.11108@vpnet.chi.il.us> Sender: usenet@cs.ucla.edu (Mr. News Himself) Organization: UCLA Computer Science Department Lines: 50 Nntp-Posting-Host: lanai.cs.ucla.edu In article <1991Mar08.205940.11108@vpnet.chi.il.us> dattier@vpnet.chi.il.us (David W. Tamkin) writes: >I'm having a problem with a key mapping in vi. If anyone can help, I'd >surely appreciate it. >I want to clear out any lines that don't have text on them. The purpose is >to separate paragraphs in quoted text. So I have this in my .exrc: map ^X :v/[0-9A-Za-z]/s/.*//^M I use EXINIT instead of .exrc. One line from that EXINIT say: map #4 mz:%s/[ ][ ]*$//^M`z where there is a tab and a space between every [ and ] pair. The mz and `z are to return me the same place in the file. This macro is not exactly the same as yours. First, it deletes trailing white space; secondly, it defines text to be any printable character while yours defines text to be only alphanumeric text. You can easily make the change if you really desire your semantics. In particular, I use mine to make d} work (paragraphs are not recognized where a line contains tabs and/or blanks) and to get rid of trailing white space; however, in re-reading your posting, I think you want to make a paragraph break whenever rn (or some other news server) has inserted a > (or related character) at the beginning of a blank line so that a line that only contains characters like "<>=" is made empty. Is that what you mean by quoted text? Thus, you could use as the left hand side of the s command: ^[^a-zA-Z0-9][^a-zA-Z0-9]*$ where all the ^s are literal. Please note, however, while, I think, the the change immediately above describes what you wrote, it may not be what you want. For example, any lines that contain only a { or } (from a C program perhaps) will also be deleted. You *may* want to change only those lines beginning with > or only those lines containing >*. My macro is superior in terms of speed (only an issue for large files) because s is much faster than v/g. If you don't believe it, try two identical command on /usr/dict/words and notice the difference in time. That is, you should only use v or g when you want to do something that s alone cannot do like delete the line or change a different line. >If I've just read the file into the buffer and made no changes yet, it works. >Otherwise, one or two occurrences of the pattern get replaced and the >operation stops with "Can't undo in global" -- so who asked for an undo? I have never had this happen with my macro and I don't see why you are having difficulties. I did not try to investigate either. David