# This is a list of exercises to perform # # for the purpose of using several features # # of the vim editor. # # Refer to http://www.css.tayloru.edu/~moquist/shs_is/vi_ref.html for help. # These practice excercises will require a file on which to excercise. I recommend that you use this file, by downloading and saving it, and then opening it in your editor. (Tyler, Brad, and eventually, Mark - You can save this file locally and then open it with gvim, which is located on the CD you're using to access Tera Term Pro. Run the gvim program, and then follow the instructions below.) Hopefully this won't be boring, but it may be at times. I urge you to go through every step, to familiarize yourself with the commands and get them under your fingers. You'll realize later that it was worth it. 1. Opening this File Open your file with gvim by running gvim and doing one of the following: Drag the icon for the locally saved copy of this file onto your gvim window -- OR -- run the following command on the gvim command line: :e c:\temp\vi_practice.txt Please observe that tab-completion is available; after you type ":e c:\temp\vi_" hit the tab key and watch what happens... (Also observe that command recall is available, so if (in command mode) you hit the up or down arrows, or CTRL-p or CTRL-n, your previous commands are recalled and avilable for your editing & execution of them.) The rest of this document assumes you are reading it from within a vim editing session. NOTE: You must substitute your path to the vi_practice.txt file for the one found above, if your vi_practice.txt file is not in c:\temp. 2. Undoing Mistakes We're doing this section first because it will be extremely important in doing these excercises; at times you will delete portions of this document, and you always want to be able to bring them back! First of all, recognize that if you ever quit vim without saving your changes (if you close the window, or run the ":q!" command), your document will still be saved in the state in which you last ran the ":w" command. So if you get too messed up, just close the editor and start over. Microsoft Word doesn't have an exclusive license on the idea of keeping "working backups", which enable you to restore changes you made to a file but did not write to the disk before your editor was closed. Vim does this by keeping a temporary "swap" file of your (relatively) recent changes. The filename of your working backup is your real filename prepended by a dot, and appended by ".swp". So editing the file "after_eating_beans.txt" will create the temporary file ".after_eating_beans.txt.swp", which will exist from the time you begin editing until the time you close your edition session on the actual file. You don't even need to open the .swp file if your editor crashes; just edit the other file again, and vim will detect that there is a leftover swap file, and give you instructions on how to restore the changes that you haven't saved in the real file. (You must delete the .swp file yourself, however, once you have used it to restore your changes.) Now on to REAL un-doing, using the "undo" command. To undo editing you've done in vi or vim, enter command mode (by pressing ESC), and type 'u'. In vi, this will only work once. But in vim, you can undo lots and lots of times. (I'm sure there's a way to set the limit, but I've never needed to.) To un-do your un-dos, you want to use the "restore" command. To restore editing you've done and then undone in vim, make sure you are in command mode, and type '^r' (CTRL-r). (If you are using vi, you can undo your one available undo by typing 'u' again.) Let's Practice: Navigate your cursor to the line below that is labeled #2.. (I hope you're using h,j,k, and l in command mode to navigate.) Type (in command mode) "dG" to delete the entire document from that line downward. Type "dd" two times in succession. This will delete up to the line labeled #1. Now type 'u', noticing how much text is restored each time. Try using '^r' to restore your editing changes... Now try adding text below, between lines 1 and 2. (Type 'i' to enter edit mode and type, and type ESC to enter command mode again.) Use 'u' to undo your editing changes, and '^r' to restore them. When you are an Undoing Master, proceed to the next section, excitingly labeled "Searching for Stuff". Line 1: i will get deleted too... help! Line 2: DELETE STARTING HERE 3. Searching for Stuff Let's suppose that you want to skip all of this boring stuff that you already know, and get to something more alluring, like "Miscellaneous Useful Stuff". To search, type a forward slash (in command mode), followed by the text for which you wish to search. (AKA your "searchstring".) To find each successive instance of it, type a lowercase 'n' (for "next"). To find each previous instance of it, type an uppercase 'N' (for "previous", of course). Let's suppose that you already forgot everything at the beginning of this file, and that you want to review the "Opening this File" section, because you didn't do that right, and you can't read this text right now. To search backwards, type a question mark (in command mode), followed by the text for which you wish to search. 'n' again finds the next successive instance of your searchstring - BACKWARDS. 'N' will reverse the direction of your original search... 4. Keeping Track of Stuff (using markers) Let's suppose that you want to practice your searching commands, and that you do so with great success. So now you've searched yourself down into the lower depths of this file, somewhere down in the "You're never going to find your way out of here, ha ha!" section. You could foil this malovent author's intentions simply by doing one of the following things: A. Following Thing Number One Search for "3. Searching for Stuff", and you'll surely find section 3 again, right? (You'll also find the same string in the above line, of course.) B. Following Thing Number Two Before you execute your search, type (in command mode) 'm', followed by any letter. That places an invisible, magic sign in your document, known as a "marker" (hence the command letter 'm'). When you want to return to that location, regardless of where you are in the file, you can type a tick mark (a single quote) ''' and the same letter you typed after the 'm' to do so. (I made up the invisible, magic sign. Vim just remembers the location.) Let's Practice "Following Thing Number Two": From now on, I'm going to assume you are in command mode when I tell you to type letters. It wouldn't make any sense for me to tell you what to type in editing mode, would it? (Except for the ESC key, which returns you to command mode, of course.) Type "ma" now to mark your current cursor location with "marker a". Now navigate with great abandon, remembering to return here by typing "'a". (Search for "You're never going to find your way out of here, ha ha!".) You can use any of the alphabetic characters as markers, probably up to something ridiculous like 52 all at one time. You can probably use non-alphabetic characters, too, but who would ever need that many? 5. Files 'n Stuff (saving, opening, closing, etc.) Like all of the other truly great editors, vim allows you to save the changes you make to your files. 5.1 Saving Files (writing files) You save with the "write" command, which you execute on the vim command line (You reach the command line by typing a colon (":") while you are in command mode.) like this: :write Vim has the useful feature of allowing you to run commands using the least number of characters required to make the command unique. (For example, if you had the commands "gesticulate" and "gestation" available to you, would need to type "gesti" and "gesta", respectively.) For the "write" command, however, you can simply type ":w". If you execute ":w" just like that, your file will be written to the location at which you opened it. If you wish to save your file somewhere else, you must give the "write" command a new filename: :w filename You can prepend paths to the filename, of course. (If you have never saved the file, meaning that you just opened vim and created your file anew, you must give the ":w" command a filename.) 5.2 Opening Files (from within vim) In order to close your current file and open another, use the "edit" command on the command line: :edit filename "edit" may be shortened to "e". If you have not saved the changes to your current file, vim will refuse and say so. If you wish to discard your changes and edit the other file anyway, use the exclamation point to tell vim "Hey, I am the boss here!". :e! filename 5.3 Closing Vim To close your editor, use the "quit" command, abbreviated "q". :q If you do not wish to save your current changes, use the I-am-the-boss-here character, the exclamation point: :q! If you wish to save and close your file with the same command (this is what I do), you can use a special combination of command abbreviations: :wq (Again, you may need the exclamation point to frighten vim into submission, if you wish to overwrite a read-only file, or something like that.) 5.4 Reading Other Files Into Your Current Session To insert the entire content of another file into your current one, use the "read" (abbreviated "r") command: :r filename I frequently use this instead of cutting and pasting (with either the mouse or vim's yank and place commands), if the other file is short. I read in the entire file, and then delete the stuff I don't want. 6. Getting Around (cursor navigation) I highly recommend navigating with the 'h', 'j', 'k', and 'l' keys in command mode. Moving your hand away from the home row to move the cursor is such a drag... If you're not doing that now, YOU SHOULD BE. Make sure you are in command mode (press ESC), and try those keys now. Don't worry, you will get used to them faster than you think, and other editors (such as anything else) will annoy you because you need to resort to the arrow keys (or even worse- the mouse!). You can use the arrow keys if you want, but I recommend against it... Typing a zero in command mode places your cursor at the beginning of the current line. Typing a $ places your cursor at the end of the current line. Try them a few times. You can move backward and forward a word-at-a-time with the "w", "W", "b", "B", "e", and "E" commands. (The lowercase ones stop for punctuation, the uppercase ones stop only for whitespace.) Try those out now. (Note that the E's put you at the End of the word...) The above navigation commands can all be prepended by a number; each will then be executed that many times. For example, typing "50j" will move you down 50 lines. Typing "3w" will move you forward 3 words. See if YOU can type numbers and commands all at once. Typing a capital G places you at the very end of the file. Mark your current location ("ma", use "'a" to return) and try it out. Typing a number before a capital G takes you to that line in the file. Simply typing a number on the command line takes you to that line in the file, just like typing that number and a capital G. Whichever floats your boat... Try using both methods to navigate to line 50. You can use the marker you made above to return here. Typing a capital L moves you to the Lowest line on the screen. Typing a capital M moves you to the Middle line on the screen. Typing a capital H moves you to the Highest line on the screen. Try those out now. 7. Edit Commands The "x" command deletes the character currently under the cursor. Try it out. The "d movement-command" command deletes whatever your movement command would have covered. For example, "dh" deletes the character to your left, "dj" deletes your current line and the one under your cursor's current location, "dW" deletes to the end of the next word (the next space, in this case), and "dG" deletes to the end of the file. Try 'em all. The "dd" command deletes your current line. Try it out. (I hope you're undoing each of these...) The tildy character is a command to switch the case of the alphabetic character currently under your cursor. (Tildy is located on the same key as Backtic, usually to the left of the !/1 key.) Try that one out, too. All of the previous commands can be prepended by a repetition number. For example: "15dw" deletes the next 15 words, "3dd" deletes the current line and the two subsequent lines, etc. The "r" command allows you to Replace your current character, "R" allows you to replace until you enter command mode again (by pressing ESC). (This is similar to "Insert" mode in other, unmentionable editors.) Give it a whirl. 8. Yanking (copying) and Placing/Putting (pasting) In vim you can copy and paste text, although I haven't found a way to cut yet (copy and delete simultaneously), short of writing a function to do it. So I just copy and then go back and delete. Paramount to the understanding of yanking and placing is an understanding of buffers. A buffer is simply a piece of memory where something is kept. Some programs give you just one buffer in which to store things, limiting you to copying (yanking) and pasting (placing) one thing at a time. Vi is not one of those programs. Vi does give you one buffer like that - you could call it the "un-named", "default", or "implicit" buffer. There are also other buffers, which are "named", or "explicit" buffers. With these, you can store multiple chunks of your file at once, making them all available for placing (pasting) at any time. "yy" yanks the current line into the default buffer. "p" places the contents of the default buffer after the current cursor position. "P" places the contents of the default buffer before the current cursor position. Each of these can be preceeded by a repitition number. For example, "15yy" yanks 15 lines, and "15p" places the default buffer 15 times. Try them all, if you dare... To use named buffers, you must specify the name of the buffer before you perform the yanking or placing command. To specify a named buffer, type a double quote followed by a single letter, which is the actual buffer name. For example, the following command yanks the current line and the next 2 lines into buffer "t": "t3yy This command will place it: "tp As will this command: "tP And these commands will place it 37 times: 37"tp 37"tP Try those out, too. 9. Visual Selection Mode To select a block of text without needing to know the number of lines, and without needing to select entire lines, I recommend using visual mode. "v" enters visual mode. Until you execute a command, or hit ESC, the movements of your cursor will cause text to be highlighted, just as if you were using the mouse to do so. Once you have text selected, you can execute yanking commands, deletion commands, searching commands, replacing commands, and command line commands on it. (Reach the command line by typing a colon, as always.) Select the paragraph above with visual mode, and delete it by pressing "d" after you have it selected. (Restore it with "u".) 10. Searching & Replacing (substituting) Now we're getting into some trickier stuff, because the search and replace operation becomes most powerful when it is used with regular expressions. But don't worry, we'll work up to that. We'll start with simple, plaintext searchstrings. You've already seen how to search for text, from section 3, above. So we'll jump right into searching and replacing. To search and replace in vi and vim, use the substitute command (abbreviated "s"). :s/searchstring/replacestring/ The above command will substitute on just one line. To expand the SCOPE of your substitution operation, include a scope argument before the command, using one of the following three methods: 1. :%s/searchstring/replacestring/ The percentage sign has a special meaning as a scope argument; it means "substitute in the whole file". 2. :beginning_line_num,ending_line_num s/searchstring/replacestring/ You can use two line numbers as the limits of your scope, if you know them. (You don't need the space between the ending line number and the s[ubstitute] command; I have it there for readability.) 3. :'<,'>s/searchstring/replacestring/ You don't ever need to type the above scope argument, it is made automatically whenever you have highlighted some text in visual mode, and then typed a colon to reach the command line. Just type your substitution command, and you're all set. Now comes the fun part - trying the substitute command out, and with regular expressions. For help on the metacharacters, either run :help regex or see http://www.css.tayloru.edu/~moquist/shs_is/vi_ref.html and click on "Search & Replace". The former is more complete and precise, the second is my attempt to make sense of the concepts for people who are new to regular expressions. I will now list several substitutions to try, and then give you some sample data to use. For these practice substitutions, I would recommend specifying your scope with visual mode. Just type "v" in command mode, select the text you want, and then do your substitution. The scope of the last visual selection is persistent, so if you just use command recall, you don't need to reselect your text every time. Important Things --> It is always best to define the application of your regex very carefully, so that you can write it with the appropriate level of specificity. (For practice #1 below, do not simply substitute strings of "01" for all strings of "00". Do you see how this will provide incorrect results sometimes?) There are many correct but different ways to write most regular expressions, and there are many correct but different ways to write regular expressions that perform the same function. My answers, which are included at the bottom, are there solely to show you one possible way to solve each problem. Please do the problem on your own first, and resort to my answer only if you are totally and absolutely stuck, or if you've completed it. Practice For Substituting Problems for both SAMPLES A & B ---> Perform these problems on the set of data labeled "SAMPLE A" below, and then on the set of data labeled "SAMPLE B". <--- 1AB. Change the year in each transaction to 2001. Undo. 2AB. Indent all lines by 2 spaces. Undo. 3AB. Make the data tab delimited, instead of comma delimited. 4AB. Use one substitution command to combine all the records onto one line. (This may not be possible if your version of vim is < 6.0.) 5AB. Switch fields 5 and 1, so that the purchase description is listed first, and the date is last. Undo this. (you can use undo...) 6AB. Reorder the fields as follows, verify, and undo: 1. check number/"CARD" 2. account number 3. amount 4. description 5. date 7AB. Drop field 3, and combine fields 2 and 4, separating them by only a space. Undo. (For SAMPLE B, drop all quotes around both fields.) ---> Now perform these problems on the set of data labeled "SAMPLE B" below. <--- ---> Perform the following problems only on SAMPLE B: 1B. Use three commands to surround every field in quotes. Undo. (two commands to deal with beginning and end of line, one to fix between every field) 2B. Use one command to surround every field in quotes. (It took me about 10 minutes to do this; it's not quick & easy. Remember to be as precise as possible.) All done, congratulations! ###################################################################### Sample Data Comma Separated Values (CSV) Data Fields 1. date 2. amount 3. account number 4. check number/"CARD" 5. purchase description SAMPLE A - all fields are surrounded by quotes - there are no quotes within fields - there are no commas within fields _____________________________________________________________________ "09/20/00","653.75","101239","CARD","CHICK-FIL-A INC PAYROLL 091800 50808" "09/06/00","-95.00","101239","652","CHECK" "09/05/00","-4.19","101239","CARD","VISA PURCHASE - RADIO SHACK 00167510 MA" "09/01/00","9.34","101237","CARD","VISA PURCHASE RETURN - BORDERS.COM 800-" "08/30/00","-17.88","101239","CARD","VISA PURCHASE - PHILLIPS 6600335280996" "08/30/00","-21.17","101239","CARD","VISA PURCHASE - CARTER LUMBER 30110282" "08/29/00","-350.00","101237","649","CHECK" "08/29/00","-11.24","101239","CARD","VISA PURCHASE - WM SUPERCENTER MARI IN" "08/29/00","-94.50","101237","CARD","VISA PURCHASE - NEEDLER HOME FURNISHINGS" "08/28/00","-8.77","101239","CARD","VISA PURCHASE - EASTBROOK FOODS INS4S" "08/28/00","-12.46","101237","CARD","VISA PURCHASE - QUIKTRIP #7 07007321 SM" "08/28/00","-16.76","101239","CARD","VISA PURCHASE - TEXACO INC 21504068103" "08/28/00","-33.25","101237","CARD","VISA PURCHASE - WM SUPERCENTER MARI IN" "08/28/00","-2.00","101239","CARD","NON-INSTANT CASH ATM WITHDRAWAL FEE" "08/28/00","-106.50","101237","CARD","ATM WITHDRAWAL - 674960039" "08/25/00","-7.85","101239","CARD","VISA PURCHASE - FUDDRUCKERS # 47 3000 G" "08/25/00","-11.99","101239","CARD","VISA PURCHASE - BP OIL 35262443 SELL IN" "08/25/00","-19.03","101237","CARD","VISA PURCHASE - BORDERS.COM 800- MI 023" "08/24/00","-286.50","101239","650","CHECK" "08/21/00","-13.64","101239","CARD","VISA PURCHASE - CIRCUIT CITY SS #0880 S" "08/21/00","-16.07","101237","CARD","VISA PURCHASE - QT 729 07007297 ATLA GA" "08/21/00","-20.99","101239","CARD","VISA PURCHASE - BEST BUY 00005025 SMYR" "08/21/00","-35.40","101239","CARD","VISA PURCHASE - CSI*ATT PREPAID 800- OR" "08/21/00","-62.41","101239","CARD","VISA PURCHASE - BORDERS BOOKS & MSC #256" "08/21/00","-251.96","101239","CARD","VISA PURCHASE - BEST BUY 00005025 SMYR" "08/18/00","1504.56","101239","CARD","CHICK-FIL-A INC PAYROLL 081600 50808" "08/17/00","-25.00","101239","CARD","NSF RETURN CHECK FEE" "08/17/00","350.00","101235","CARD","CHECK REVERSAL" "08/16/00","-350.00","101239","649","CHECK" "08/15/00","-115.00","101237","648","CHECK" "08/15/00","-6.70","101239","CARD","VISA PURCHASE - TEXACO INC 21480223297" "08/15/00","-7.64","101239","CARD","VISA PURCHASE - MICRO CENTER MARIETTA M" "08/14/00","-4.00","101239","CARD","VISA PURCHASE - WINN DIXIE 1821 S91 SMY" "08/10/00","-5.24","101239","CARD","VISA PURCHASE - CIRCUIT CITY SS #0880 S" "08/08/00","-200.00","101239","645","CHECK" "08/03/00","-135.15","101237","CARD","VISA PHONE/MAIL PURCHASE - DIRECTRON.COM" "08/03/00","-8.28","101239","CARD","VISA PURCHASE - WAL MART MARI GA 021529" "08/01/00","-234.93","101237","CARD","VISA PURCHASE - DESERT DEVILS GILB AZ 0" "07/31/00","-20.14","101239","CARD","VISA PURCHASE - QUIKTRIP #7 07007321 SM" "07/31/00","-72.60","101239","CARD","VISA PURCHASE - BEYOND COMPUTER INC NEW" "07/31/00","-75.52","101237","CARD","VISA PURCHASE - ABILITY COMPUTER INC 21" "07/28/00","-70.00","101239","644","CHECK" "07/25/00","-22.35","101239","CARD","VISA PURCHASE - SHELL NO.53902000610 AN" "07/24/00","-80.86","101239","643","CHECK" "07/24/00","-18.75","101239","CARD","VISA PURCHASE - TEXACO INC 20683220085" "07/24/00","-22.78","101239","CARD","VISA PURCHASE - QUIKTRIP #7 07007321 SM" "07/24/00","-2.00","101237","CARD","NON-INSTANT CASH ATM WITHDRAWAL FEE" "07/24/00","-51.50","101239","CARD","ATM WITHDRAWL - 5240 U.S. HWY 129 JEFF" "07/24/00","67.79","101239","CARD","VISA PURCHASE RETURN - JBC MANUFACTURING" _____________________________________________________________________ SAMPLE B - not all fields are surrounded by quotes - there are no quotes within fields - there are no commas within fields _____________________________________________________________________ "09/20/00",653.75,"101239","CARD",CHICK-FIL-A INC PAYROLL 091800 50808 "09/06/00","-95.00","101239","652","CHECK" "09/05/00",-4.19,"101239","CARD",VISA PURCHASE - RADIO SHACK 00167510 MA "09/01/00","9.34",101237,"CARD","VISA PURCHASE RETURN - BORDERS.COM 800-" 08/30/00,"-17.88",101239,"CARD",VISA PURCHASE - PHILLIPS 6600335280996 "08/30/00","-21.17",101239,"CARD","VISA PURCHASE - CARTER LUMBER 30110282" 08/29/00,"-350.00","101237",649,"CHECK" "08/29/00",-11.24,"101239",CARD,VISA PURCHASE - WM SUPERCENTER MARI IN "08/29/00",-94.50,101237,"CARD",VISA PURCHASE - NEEDLER HOME FURNISHINGS "08/28/00","-8.77",101239,"CARD",VISA PURCHASE - EASTBROOK FOODS INS4S "08/28/00","-12.46",101237,"CARD",VISA PURCHASE - QUIKTRIP #7 07007321 SM "08/28/00","-16.76",101239,"CARD",VISA PURCHASE - TEXACO INC 21504068103 "08/28/00",-33.25,"101237","CARD",VISA PURCHASE - WM SUPERCENTER MARI IN "08/28/00","-2.00",101239,"CARD",NON-INSTANT CASH ATM WITHDRAWAL FEE "08/28/00",-106.50,101237,"CARD",ATM WITHDRAWAL - 674960039 "08/25/00",-7.85,"101239",CARD,"VISA PURCHASE - FUDDRUCKERS # 47 3000 G" "08/25/00",-11.99,"101239","CARD",VISA PURCHASE - BP OIL 35262443 SELL IN 08/25/00,"-19.03",101237,"CARD",VISA PURCHASE - BORDERS.COM 800- MI 023 "08/24/00","-286.50",101239,"650",CHECK 08/21/00,"-13.64",101239,"CARD","VISA PURCHASE - CIRCUIT CITY SS #0880 S" 08/21/00,"-16.07",101237,CARD,"VISA PURCHASE - QT 729 07007297 ATLA GA" 08/21/00,"-20.99","101239",CARD,"VISA PURCHASE - BEST BUY 00005025 SMYR" 08/21/00,-35.40,"101239",CARD,"VISA PURCHASE - CSI*ATT PREPAID 800- OR" "08/21/00",-62.41,"101239",CARD,VISA PURCHASE - BORDERS BOOKS & MSC #256 "08/21/00",-251.96,"101239","CARD",VISA PURCHASE - BEST BUY 00005025 SMYR "08/18/00",1504.56,101239,"CARD",CHICK-FIL-A INC PAYROLL 081600 50808 "08/17/00","-25.00",101239,"CARD",NSF RETURN CHECK FEE 08/17/00,"350.00",101235,"CARD","CHECK REVERSAL" 08/16/00,"-350.00",101239,649,"CHECK" 08/15/00,"-115.00","101237",648,"CHECK" 08/15/00,-6.70,"101239",CARD,"VISA PURCHASE - TEXACO INC 21480223297" "08/15/00",-7.64,"101239",CARD,VISA PURCHASE - MICRO CENTER MARIETTA M "08/14/00",-4.00,"101239","CARD",VISA PURCHASE - WINN DIXIE 1821 S91 SMY "08/10/00",-5.24,101239,"CARD",VISA PURCHASE - CIRCUIT CITY SS #0880 S "08/08/00","-200.00",101239,"645",CHECK 08/03/00,"-135.15",101237,"CARD",VISA PHONE/MAIL PURCHASE - DIRECTRON.COM "08/03/00","-8.28",101239,"CARD","VISA PURCHASE - WAL MART MARI GA 021529" 08/01/00,"-234.93",101237,"CARD",VISA PURCHASE - DESERT DEVILS GILB AZ 0 "07/31/00",-20.14,"101239",CARD,"VISA PURCHASE - QUIKTRIP #7 07007321 SM" 07/31/00,"-72.60","101239","CARD","VISA PURCHASE - BEYOND COMPUTER INC NEW" "07/31/00","-75.52","101237","CARD",VISA PURCHASE - ABILITY COMPUTER INC 21 "07/28/00",-70.00,"101239",644,"CHECK" "07/25/00","-22.35",101239,"CARD","VISA PURCHASE - SHELL NO.53902000610 AN" "07/24/00","-80.86",101239,"643","CHECK" "07/24/00",-18.75,"101239","CARD",VISA PURCHASE - TEXACO INC 20683220085 "07/24/00","-22.78",101239,"CARD","VISA PURCHASE - QUIKTRIP #7 07007321 SM" 07/24/00,"-2.00",101237,"CARD","NON-INSTANT CASH ATM WITHDRAWAL FEE" "07/24/00",-51.50,"101239",CARD,ATM WITHDRAWL - 5240 U.S. HWY 129 JEFF "07/24/00","67.79",101239,CARD,VISA PURCHASE RETURN - JBC MANUFACTURING _____________________________________________________________________ ###################################################################### ANSWERS 1AB. Change the year in each transaction to 2001. SAMPLE A :'<,'>s/^\(\"\d\d\/\d\d\/\)00/\101/ SAMPLE B :'<,'>s/^\(\"\{0,1\}\d\d\/\d\d\/\)00/\101/ 2AB. Indent all lines by 2 spaces. Undo. SAMPLE A :'<,'>s/^/ / SAMPLE B :'<,'>s/^/ / (same as A) 3AB. Make the data tab delimited, instead of comma delimited. SAMPLE A :'<,'>s/,/\t/g SAMPLE B :'<,'>s/,/\t/g (same as A) 4AB. Use one substitution command to combine all the records onto one line. (This may not be possible if your version of vim is < 6.0.) SAMPLE A :'<,'>s/\r// SAMPLE B :'<,'>s/\r// (same as A) 5AB. Switch fields 5 and 1, so that the purchase description is listed first, and the date is last. Undo this. (you can use undo...) SAMPLE A :'<,'>s/^\([^,]\+\),\(.\+\),\([^,]\+\)$/\3,\2,\1/ SAMPLE B :'<,'>s/^\([^,]\+\),\(.\+\),\([^,]\+\)$/\3,\2,\1/ (same as for A) 6AB. Reorder the fields like this: 1. check number/"CARD" 2. account number 3. amount 4. description 5. date Then undo. SAMPLE A :'<,'>s/^\([^,]\+\),\([^,]\+\),\([^,]\+\),\([^,]\+\),\([^,]\+\)/\4,\3,\2,\5,\1/ SAMPLE B :'<,'>s/^\([^,]\+\),\([^,]\+\),\([^,]\+\),\([^,]\+\),\([^,]\+\)/\4,\3,\2,\5,\1/ (same as A) 7AB. Drop field 3, and combine fields 2 and 4, separating them by only a space. Undo. SAMPLE A :'<,'>s/^\([^,]\+\),\([^,]\+\)\",[^,]\+,\"\([^,]\+\)/\1,\2 \3/ SAMPLE B :'<,'>s/^\([^,]\+\),\"\{0,1\}\([^,\"]\+\)\"\{0,1\},[^,]\+,\"\{0,1\}\([^,\"]\+\)\"\{0,1\}/\1,\2 \3/ 1B. Use three commands to surround every field in quotes. Undo. (two commands to deal with beginning and end of line, one to fix between every field) 1. :'<,'>s/^[^\"]/\"/ 2. :'<,'>s/[^\"]$/\"/ 3. :'<,'>s/\"\=,\"\=/\",\"/g 2B. Use one command to surround every field in quotes. (It took me about 10 minutes to do this; it's not quick & easy. Remember to be as precise as possible.) :'<,'>s/^\"\{0,1\}\([^\",]\+\)\"\{0,1\},\"\{0,1\}\([^\",]\+\)\"\{0,1\},\"\{0,1\}\([^\",]\+\)\"\{0,1\},\"\{0,1\}\([^\",]\+\)\"\{0,1\},\"\{0,1\}\([^\",]\+\)\"\{0,1\}/\"\1\",\"\2\",\"\3\",\"\4\",\"\5\"/ ________________________________________________________________________ You're never going to find your way out of here, ha ha!