Why text editing & why VIM? =========================== If you think about it, text is all we ever need. As engineers, we need to do a lot of scripting and programming. We also need to pass on electronic info to others. Text files ensure that it can be viewed and modified on any platform. Portability. Forget about the lush fonts in MS Word and the files it creates that "should" only be opened by the proprietary software. Why do you think HTML is such a success? VIM is possibly the most configurable software ever made. It can be made to play with text in almost any possible manner. From the basic functions to actions like changing the case of a word, folding code & justifying text, to the more complex functions like tab-completion, code alignment & line sorting. A Tetris game has even been made for it. 1. Getting Help =============== VIM has a very comprehensive documentation of its use. To invoke help, simply type ":help". If you need help on a topic, then do ":help ". If you are unsure if the topic is available, type as much of the topic as you can and then press Ctrl-d before hitting Enter. For example, typing ":help undo" and pressing Ctrl-d displays help topics that contain the word "undo". 2. Modes of Operation ===================== VIM has many modes of operation. This is the essence of VIM's power over other text editors. Encourages the user to think ahead before hacking away at editing text. Type ":help modes" for help. Important modes to remember: Normal mode, Edit mode, Command-Line mode You begin in Normal mode. To invoke Edit mode, hit "i" or "a" or "r". To invoke Command-Line mode, hit ":". Hit "Esc" to get back to Normal mode. Question: What mode is required to invoke help? 3. Saving & Opening Files and Quitting ====================================== New file ":new" To save ":w " To open ":e " To quit ":q" You can append "!" to force the action. For example, ":w! " forces an overwrite (e.g. writing to a Read-Only file) ":e! " opens another file without saving the current one ":q!" quits the program without saving For EMERGENCY RECOVERY use ":recover " 4. Undo & Redo ============== Undo "u" Redo "Ctrl-r" Question: In what mode? 5. Moving around ================ Arrow keys = Left, Down, Up, Right = h, j, k, l H, M, L screen positions 0 Go to start-of-line ^ Go to first non-blank character of line $ Go to end-of-line g_ Go to last non-blank character of line Shift-g Go to line gg Go to first line, first non-blank character Shift-g Go to last line, first non-blank character [w,b] Scroll beginning word-by-word (same as Shift-right arrow) [e,ge] Scroll end word-by-word [(;)] Scroll beginning sentence-by-sentence [forward; backward] [{;}] Scroll end paragraph-by-paragraph [forward; backward] Example text: Here is a very short paragraph. It was intended to be short. I wasn't sure how short I needed to make it. I should check with Roger. This is the second paragraph. Did I need to make two paragraphs? Again, I wasn't sure. 6. Yanking, Deleting and Pasting ================================ In Windows terms, Copying = (Y)anking Cutting = (D)eleting Pasting = (P)asting To yank a line "yy" To delete a line "dd" To paste "p" Apply a multiplier number to the commands above to repeat for many lines. For example, to yank 3 lines from the cursor position, hit "3yy". You can even use Command-Line mode to do yanking and deleting. 7. Search and Replace ===================== To search for a word "/" To replace, use Command-Line ":%s///g" Example text: billy bob thornton angelina jolie brad pitt 8. Let's Do The Split! ====================== To split windows horizontally ":split " To split windows vertically ":vsplit " New file in vertical window ":vnew" Switch windows "Ctrl-w,w" Rotate windows "Ctrl-w,r" Resize windows with mouse or "Ctrl-w[=;+-;<>;Ctrl-_;|]" 9. Highlight mode Called a Visual. Invoke with "v". Visual Block invoked with "Ctrl-v" Visual Line invoked with "Shift-v" 18. Neat Tricks =============== Take your own notes here. incrementing/decrementing "Ctrl-[a;x]" start recording "q " stop recording "q" replay recording "@ " Example text: The amount of beer left in my fridge is 24 jump to matching bracket "%" fix indent "==" combine "=%" Example code: if ((curmax != curmin) && ((curmax-curmin) < BUFSIZE)) { free(lnstr); // allocate char array for line input lnstr = (char *) malloc((curmax - curmin + 1) * sizeof(char)); for (i = curmin; i < curmax; i++) { move(y, i); lnstr[i-curmin] = inch(); } move(y, i); for (i = 0; i < fillbuf; i++) if (!strcmp(&lnbuf[i * BUFSIZE], lnstr)) dupflag = 1; printw("\nYou typed: %s\nLine input: ", lnstr); }