A List of Some Other Useful Features

The following is a list of spiffy features and a short explaination. Please look at Further Sources for more information.

  • <Ctrl>-g - Pressing these keys while in command mode gives additional information about the file we are working on, including the file name, modification status, and the number of lines.
  • <Shift>-g - While in command mode, this movement places the cursor at the end of the file. As this is a movement command, it allows you to combine it with any command that uses motion. For example, we could delete the rest of a document with “d<Shift>-g”.
  • Spell Checking - ViM has a built in spell checker. You can turn it on by using “:set spell”. Unfortunately, spell highlighting does not work too well with other types of highlighting, so you may need to turn on syntax highlighting. Words that are misspelled are highlighted in red. If you move the cursor to the word and type “z=” in command mode, you will get an interface for correcting the misspelled word. See “:help spell” for more information about spelling, particularly a large set of additional commands.
  • Using marks - ViM allows you to make “marks” in your text files, where a “mark” is a particular point within a file that you’d like to return to often. To mark a line of a file with the ‘a’ mark, move the cursor to that line and type “ma”. You may only use marks a-z. To return to the a mark within a text file, type “‘a”. Marks are persistent between sessions (by default), so you can close ViM and then reopen the file and have access to the same marks.
  • Visual Mode - In command mode, pressing ‘v’ causes you to enter Visual Mode. This mode allows you to access large blocks of text using the arrow keys. You can then yank, delete, or change the block with the same commands that are used in command mode. If you have set up your mouse, clicking and highlighting enters Visual Mode.
  • The Paste option - If you have autoindent set and you are copying data from a source that uses its own indentation, it can be extremely frustrating to paste in ViM because the autoindent indents the lines automatically, but so too does the source. One solution to this is the ‘paste’ option. If you use “:set paste” before pasting a chunk of text, ViM will ignore special indentation procedures. Typing “:set nopaste” afterwards returns auto-indentation.
  • Working with Ranges - Most of our commands that take movement parameters (such as delete, yank, etc.) also provide the option of accepting ranges of information. For example, the ‘,’ character represents “here” so that “y,20” yanks all the text from where the cursor is through line twenty. Similarly, the ‘$’ character represents the end of file so that “y,$’ yanks everything from here until the end of the file (like “y<Shift>-g”)
  • Using External Filters - ViM provides the option of sending chunks of your text file to an external filter and replacing it with the result of said filter. If you have a program that replaces all ‘a’s with ‘e’s, then you could send the next paragraph of information to that program with “!}progName”. Parsing this command, we see that ‘!’ tells ViM it will be working with an external filter, ‘}’ informs ViM to send the next paragraph, and progName is the name of the program that will be used to filter information. Good examples of this command include “!}fmt” which automatically wraps words at 75 characters and fills the paragraphs as fully as it can, “!}sort” which sorts the data, and “!}wc”, which gives a word count (you may want to undo after running “!}wc”.
  • Opening Multiple Files from the Command Line - As with most Unix software, ViM can be given several files as parameters and knows how to handle each. Perhaps unexpectedly, ViM will not open each file in a new ViM windows. Instead, ViM will open each file in succession. You may switch to the next file via the “:next” or “:n” command. For example, we could start ViM with “vim *”, which will open each file in the current directory in ViM and then “:n” through them until we “:q” the last one.
© C.M. Lubinski 2008-2021