Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!brl-adm!brl-smoke!smoke!gregg%a.cs.okstate.edu@RELAY.CS.NET From: gregg%a.cs.okstate.edu@RELAY.CS.NET (Gregg Wonderly) Newsgroups: net.unix-wizards Subject: re: VI(1) vs. the world Message-ID: <4327@brl-smoke.ARPA> Date: Thu, 2-Oct-86 22:58:02 EDT Article-I.D.: brl-smok.4327 Posted: Thu Oct 2 22:58:02 1986 Date-Received: Sat, 4-Oct-86 10:43:00 EDT Sender: news@brl-smoke.ARPA Lines: 130 #define CASE3 3 #define CASE2 2 #define CASE1 1 With all this fuss about editors, I couldn't resist to get in on the discussion. Most of the complaints seem to center around whether or not VI(1) is mnemonic. I for one believe that this is not that important for those who use an editor frequently. Someone else commented to this effect. Putting that aside, I use VI(1) ONLY for its functionality. It gives me so many functions that I do not find in other editor's. Not to mention the fact that I can use my micro from home to edit files while dialed up. Granted, most other UN*X based editors take advantage of term[cap/info]. The other really BIG plus is Regular Expression searches, and substitutions. Most people might say "I'd never use that", but I guarantee that I have a real hard time on other systems which don't have RE's. Below is my classic example of the power of VI(1). I had to do this once apon a time when I took over a project that had been coded by some rather new C programmers. The problem was the switch statement. I needed very much to have #define macros for the case values in the switch. The printf's in each switch were already there, and had strings in them that were satisfactory for the macro names. The map statement below creates a keyboard macro which is invoked by typing the "q" key while in "command" mode. If you have never used a keyboard map in VI(1), then you might try this to see what happens. Before typing "q" the first time, you should enter the command: /case[ ]*[0-9]*: This will initiate a search to locate the first case in the switch below. You can figure out what the following map does pretty easily. It goes like this. 1) Move to the text after the text "case". -> W 2) Delete to the ':' character (exclusive of ':'). -> dt: 3) Mark the current position as A. -> ma 4) Go to the top of the file. -> 1G 5) Open a line and insert the text "#define". -> O#define^V 6) Put the case value with the #define. -> p 7) Move back to the position marked as A. -> 'a 8) Move down to the printf(). -> j 9) Move to the " character. -> f" 10) Move to the actual text. -> l 11) Delete the text. -> dt\ 12) Put it back. -> P 13) Move back up to the previous line. -> k 14) Move to the beginning of the line. -> 0 15) Move to the ':' character. -> f: 16) Put the macro name text in as CASE value. -> P 17) Move back to the current #define. -> 1G 18) Move past the #define. -> W 19) Put the Macro name in. -> P 20) Append 2 tabs after the name. -> a^V 21) Move back to the place marked as A -> 'a 22) Find the next case statement to change. -> n This is the magical map ----------------------- <...> denotes a single key to press as in the TAB key, or the ESCAPE key, and ^V is the CONTROL-V key, which is used to quote control characters that might otherwise be interpreted. Here, needs quoting or else VI will assume you want to end the map definition. Also note that you must type a ':' from command mode to get into 'EX' command mode where maps are entered. :map q Wdt:ma1GO#define^Vp'ajf"ldt\Pk0f:P1GWPa^V'an And by the way, undo even works on something like this. ------------------------------------------------------------------------------ switch (i) { case 1: printf ("CASE1\n"); func1(p,1,1,1,1,); break; case 2: printf ("CASE2\n"); func1(p,2,1,2,1,); break; case 3: printf ("CASE3\n"); func1(p,1,1,1,1,); break; case 4: printf ("CASE4\n"); func1(p,1,1,1,1,); break; case 5: printf ("CASE5\n"); func1(p,1,1,1,1,); break; case 6: printf ("CASE6\n"); func1(p,1,1,1,1,); break; case 7: printf ("CASE7\n"); func1(p,1,1,1,1,); break; case 8: printf ("CASE8\n"); func1(p,1,1,1,1,); break; case 9: printf ("CASE9\n"); func1(p,1,1,1,1,); break; case 10: printf ("CASE10\n"); func1(p,1,1,1,1,); break; } -------------------------------------------------------------------------- Gregg Wonderly Department of Computing and Information Sciences Oklahoma State University UUCP: {cbosgd, ea, ihnp4, isucs1, mcvax, uokvax}!okstate!gregg ARPA: gregg%okstate.csnet@CSNET-RELAY.ARPA or ARPA: gregg@A.CS.OKSTATE.EDU