Plugins
There are various kinds of plugins that can be written:
- vimrc
- global plugin
- filetype plugin
- syntax highlighting plugin
- compiler plugin
Not only can you write your own plugins but also download and .
When I install a new Linux distribution or reinstall Windows, the first thing I do after installing Vim is fetch my latest file from my backups, and then start using Vim. Why is this important? Because the vimrc
file contains various customizations/settings I like which makes Vim more useful and comfortable for me.
There are two files you can create to customize Vim to your taste:
- vimrc - for general customizations
- gvimrc - for GUI specific customizations
These are stored as:
$HOME/.vimrc
and$HOME/.gvimrc
on Linux/BSD/Mac OS X
See :help vimrc
on the exact location on your system.
These vimrc and gvimrc files can contain any Vim commands. The convention followed is to use only simple settings in the vimrc files, and advanced stuff are sourced from plugins.
For example, here’s a portion of my vimrc file:
If you want to learn detailed usage of each setting mentioned above, refer :help
.
A portion of my gvimrc file is:
" Size of GVim window
set lines=35 columns=99
set guioptions-=m
set guioptions-=T
" Font.
if has('win32') || has('win64')
" set guifont=Monaco:h16
set guifont=Consolas:h12:cANSI
elseif has('unix')
let &guifont="Monospace 10"
There are various example vimrc files out there that you should definitely take a look at and learn the various kinds of customizations that can be done, then pick the ones you like and put it in your own vimrc.
A few good ones that I have found in the past are:
It is a known fact that a person’s vimrc usually reflects how long that person has been using Vim.
Global plugins can be used to provide global/generic functionality.
Global plugins can be stored in two places:
$VIMRUNTIME/plugin/
for standard plugins supplied by Vim during its installationTo install your own plugins or plugins that you have download from somewhere, you can use your own plugin directory:
$HOME/.vim/plugin/
on Linux/BSD/Mac OS X- See
:help runtimepath
for details on your plugin directories.
A useful plugin to have is highlight_current_line.vim
by Ansuman Mohanty which does exactly as the name suggests. Download the latest version of the file highlight_current_line.vim
and put it in your plugin directory (as mentioned above). Now, restart Vim and open any file. Notice how the current line is highlighted compared to the other lines in the file.
But what if you don’t like it? Just delete the highlight_current_line.vim
file and restart Vim.
Similarly, we can install our own related.vim
or capitalize.vim
from the Scripting chapter into our plugin directory, and this avoids us the trouble of having to use :source every time. Ultimately, any kind of Vim plugin that you write should end up somewhere in your .vim/vimfiles
plugin directory.
Filetype plugins are written to work on certain kinds of files. For example, programs written in the C programming language can have their own style of indentation, folding, syntax highlighting and even error display. These plugins are not general purpose, they work for these specific filetypes.
Let’s try a filetype plugin for XML. XML is a declarative language that uses tags to describe the structure of the document itself. For example, if you have a text like this:
(Excerpt taken from under the GNU Free Documentation License)
It can be written in XML form (specifically, in ‘DocBook XML’ format) as: