Parent page: Programming Applications
Vim is a popular text editor based off of the venerable vi editor. To install Vim, run the following in a terminal:
sudo apt-get install vim
Vim exists as a console application, and is therefore launched by issuing the following command in a terminal emulator or virtual console:
To quit vim and discard all changes, press the escape key and then type
Vim is designed around modality, composability and extensability.
Vim assumes that users edit text more often than they type it. It thus has a mode for inserting text and several modes for editing text. The behavior of vi depends on which mode it is set to:
Command mode is the default mode of vi. It provides a library of keyboared-based commands to edit text. Pressing the escape key switches to this mode.
Insert mode allows for the insertion of text. This is the functionality most users associate with text editors. Pressing the i key in command mode switches to this mode.
Visual mode provides functionality for text selection. Pressing the v key in command mode switches to this mode.
Vim is designed similar to that of the Unix operating system. That is, functionality is provided through a library of simple commands that can be combined into more complex commands.
For example, the w command moves the cursor to the beginning of the next word. The d command is the deletion command. Thus dw deletes the next word; d2w deletes the next two words.
Vim's functionality can be extended through a multitude of third-party plugins written in vimscript. The vim-script package includes a selection of useful plugins.
Managing vim plugins is unpleasant, but can be automated by plugin managers like Vundle.
To learn the basics of vim editing, issue the following command in a terminal emulator:
More advanced tutorials can be found online. See, for example, Vimcasts. Also check the official documentation.
The ~/.vimrc file provides Vim's default configuration. To create and open the file for editing, run the following in a terminal:
Below are examples of Vim configurations that can be added to the .vimrc file. Lines beginning with a " are comments:
" Indent automatically depending on filetype filetype indent on set autoindent " Turn on line numbering. Turn it off with "set nonu" set number " Set syntax on syntax on " Case insensitive search set ic " Higlhight search set hls " Wrap text instead of being on one line set lbr " Change colorscheme from default to delek colorscheme delek
Other .vimrc configurations can be found at dotfiles. Note that some .vimrc files won't work if the correct plugins aren't installed.
Editing docbook documents with vim
To contribute to the Ubuntu Documentation, you will need to use the docbook format. If so, you might be interested in the VIM filetype plugin xmledit.
Add the following to your ~/.vimrc
map! ,e <emphasis> map! ,p <para> map <F3> v/>^Mx
If you are at the beginning of an opening XML tag you can just press F3 and the tag gets cut to the buffer. Go the end of the section and press 'p' (=paste) and it will be appended after the current char.
This is useful to add tags after the text is already written. A typical usecase is when it is necessary to add formatting to current documents which have been copy/pasted from a web site.
Editing the Ubuntu Wiki
You can use VIM to edit articles in the Ubuntu wiki. Since we use the MoinMoin engine, we can use the Vim syntax plugin moin to get syntax highlighting for the wiki text in vim. Enable the plugin by using the instructions in the previous link.
Just click the More Actions: drop down list on the page you want to edit. Then select Show Raw Text. Copy the source of the wiki page you are editing, and paste it into vim. If you are using the console version of vim, it might be a good idea to turn off autoindenting, as vim autoformats the text as you paste it. This is not a issue in the gui version of vim.