The VIM text editor

http://www.vim.org


FVLUG VIM presentation

This presentation was to highlight some of the more powerful ways to move about and edit in VIM and some of the very basics for those finding themselves in VIM without warning.

The first thing you need to know about VIM is the difference between command mode and edit mode. Edit mode is simply where you type content. Command mode is necessary for entering commands, to get to command mode at any time press the Escape key. From there the next thing you may want to know is how to get out of VIM, use :q! to force an exit without saving and :x to save and then exit.

There are also some shortcuts for moving around that you will be more comfortable if you know. For instance, gg jumps to the first line of the document and G hops to the last line; nG will jump to the nth line. Once on the line you want, to get into edit mode press the Insert key (it acts as a toggle for insert and replace modes). If you can't use the extended keys for some reason, try i for insert mode or R for replace mode. To get to insert mode at the end of the line in one easy step try A and for the beginning of the line try I .

Another useful way to move around is to move through text one word at a time by pressing w to move forward and b to go back. If you want to go one sentence at a time, try ) to go forward and ( to move backwards. And if you want to move a paragraph at a time use } to move forward and { to go back. Note that all of these commands will accept numeric input, for instance type 7w to move forward 7 words.

For more advanced tips we looked at using Visual and Visual Block modes. Visual mode is entered by pressing v when in command mode. This sets one end of a text selection and your cursor will mark the other end, you can move it around using VIM's regular navigation keys. Once you have highlighted a desired piece of text you can use commands such as d to delete it or yy to copy it. Additionally, while you are still in visual mode, you can press : to have it automatically give you '<,'> as a parameter for commands that use it. This will allow you to perform operations such as search and replace on just the selected text. It will remember the current selection until you make another one so that you can perform multiple operations on the same selection by using :'<,'> as the beginning of your command.

Visual Block mode is started by pressing C-v when in command mode. This sets one end of a rectangular selection and your cursor will mark the other end. The selection will only exist on lines that have content that stretches out that far, for instance blank lines would almost never be affected and a line with only 10 characters wouldn't be affected by a selection that went from characters 15 to 25. Once you have the block you want selected press I to get into insert mode, type anything you want to add and then press Escape to finish. Alternatively with the block selected you can also press d to delete it. This is very useful for editing tables of information.


Vim works on many operating systems. It also has plugins for many other editting environments. For example, it integrates with Gnome, KDE, and even JBuilder:

http://jvi.sourceforge.net/


See also: FVLUG, LinuxApplications