UNIX SIG By Christopher J. Fearnley VIM 2.0: Vi IMproved - a vi-like text editor for Beginners and Gurus [It even has on-line help!]. For Amiga, DOS and UNIX. When I first installed Linux on my PC I had GNU Emacs. But it took up too much disk space so with latter installations I switched to vi for its smaller size and great power. Most Linux distributions come with elvis, a free vi clone by Steve Kirkendall under the GNU public license. It offers a visual mode, but few other advantages over traditional vi. So when I heard about vim, I decided to try it out. It has many features above and beyond traditional vi. Vim's nicest feature is its extensive on-line help. One only needs to know the ":help" command to get started. Practically one also needs to understand the "philosophy" or "mind set" of vi editing too. Vim was written by Bram Moolenaar originally for the Amiga, but with ports to Unix and DOS. Vim is in the public domain. For me learning vi offered two major hurdles to overcome. First, there is little on-line help (a difficiency happily lacking in vim) so I had to buy a book to figure it out. Secondly, I never used an editor with so many modes and until I figured that out, I kept getting "lost." Vim has four basic modes of operation: command mode, insert mode, replace mode and command-line mode. Command mode is the mode vim starts up in. It allows you to switch to any of the other modes in one keystroke. It uses the touch typists' keyboard for it's commands (unlike most text editors or word processors which require the use of bazaar sequences of control codes to access the basic editing functions). One very important thing to remember about command mode is that you can always get back to it by typing [Esc] twice. Insert mode is entered from command mode by typing "i" (insert at the cursor position), "I" (insert at beginning of the line), "o" (insert at a new line below the current line), "O" (insert at a new line above the current line), "a" (append after the cursor position), or "A" (insert at the end of the current line). Once you are in insert mode you need to hit [Esc] to re-enter command mode. In vim if the "showmode" option has been set "-- INSERT --" is shown at the bottom of the screen. Replace mode is entered by typing "R". This mode is a variation on insert mode in which one character of the pre-existing text is deleted for each new one entered. [Esc] again returns you to command mode. If "showmode" is set, "-- REPLACE --" appears at the bottom of the screen. Finally, command-line mode is the "ex" commands mode. Ex is the line editor that can be entered from vi with the ":" prefix. This is a very powerful mode, but I haven't space to do it justice. I use all four modes regularly (replace mode the least). Enough of the basics. First, you can download vim from sunsite.unc.edu: /pub/Linux/apps/editors/vim-2.0.tar.gz. This is the full source code which shouldn't be any different for other systems (a msdos binary is included). I will upload it to the PACS BBS once the message base has been restored. Now I want to discuss the features that vim has that make it special. Here's some miscellany: Vim supports multi-level undo using the traditional "u" command. "Ctrl + r" takes you forward through the re-do/undo list. By default only 100 undos are available. This can be changed with the ":set undolines=" command. ":set undolines=0" is vi compatibility mode. In insert mode "^O" allows you to enter a command mode command and at its completion return to insert mode. I find this to be very useful in building nice key mappings (":map! key command" for those unfamiliar with vi - map with no "!" is useful for command mode mappings or macros). The ":wrap" option will toggle between long lines wrapping onto the next line or ":nowrap" for scrolling horizontally to see the ends of long lines. Wrap is on by default. ":center", ":right", and ":left" will center-, right-, or left-justify a line of text (e.g., use ":5,9center" to center lines 5 through 9). ":textwidth=75" will format lines typed in to 75 characters (similar to vi's wrapmargin=5). The file doc/difference.doc documents all the differences between vim and vi more fully. In command-line mode (ex mode), vim supports command line editing with both insert and delete. Use the arrow keys to move around on the command line and and or to delete text. Ctrl + "B" and Ctrl + "E" toggle between the beginning and ending of a line. Vim stores a command line history accessible through the up/down arrow keys (or Ctrl + "P"/Ctrl + "N"). Finally vim supports filename completion. A will "complete" the filename defaulting to the first (in alphabetical order) if multiple matches are found ( after a wildcard will expand the wildcard). Use or Ctrl + "N" to walk forward through the matched filenames and Ctrl + "P" to go backwards through the matches. Vim (like elvis) has a visual mode. From command mode "v" starts visual mode on characters, "V" for lines, and "Ctrl + V" for blockwise edits (i.e., you can highlight columns). When defining your highlighted inverse-video region (use the h, j, k, and l keys or actually any of the vi motion keys such as b, w, B, W and etc.,) if you suddenly realize that you missed one or more characters at the other end of the region, "o" will allow you to extend or decrease a region on the other side of the "block". Then type one of the following commands: "d" (delete), "c" (change), "y" (yank), ">" or "<" (insert or delete indent), "!" (filter through external program), "=" (filter through indent), ":" (apply ex command), "Q" (format text to "textwidth" columns), "J" (join lines), "~" (swap case), "u" (make lowercase), and "U" (make uppercase). For programmers, if you redirect the output of your compiler's error messages to a file "errors" and invoke "vim -e", it will open the source file with the compile-time errors and place you to the line in question ready for editing. At the bottom of the screen the display will show the compiler's error message. You may need to ":set errorformat=%f:%l:%m" so that vim can understand the format of your compiler's output (the text works for gcc - other compilers may require a different code). Typing ":cn" takes you to the next error, ":cp" brings up the previous one, etc., See the file doc/reference.doc for full details. ------- Local Unix support: The PACS MULTI-SIG BBS under Magpie has a Unix board (842-960[0-3]). We may use the files command to store key Linux files for download - more on this next month. Alternatively we may use the files board under Magpie. You can contact me at cfearnl@pacs.pha.pa.us or cfearnl@cpp.pha.pa.us. ------- Next month I will talk on "Linux: Turning Your PC into a Workstation"