Recipe 6.12. Customizing Vim
6.12.1 Problem
All
this customization is great, but it goes away when you quit. You
don't want to re-type all your abbreviations and
mappings each time you start. How do you customize your Vim
environment, and preserve your abbreviations and custom keymappings?
6.12.2 Solution
Create a
~/.vimrc file with
your desired options. You can create one from scratch, or copy and
modify the global /etc/vim/vimrc file.
What can you put in your ~/.vimrc? Any Vim
option that you want. And what might those options be? You can list
all option names by typing:
:set all
aleph=224
noarabic
arabicshape
noallowrevins
noaltkeymap
...
Then look up what they mean:
:help noaltkeymap
This opens the hyperlinked options help page:
:help options
As you can see, a person could happily spend a lifetime fine-tuning
Vim (and, with luck, completely avoid doing any real work).
6.12.3 Discussion
When you read the Vim documentation, it's easy to
become overwhelmed by its flexibility, and the sheer number of
possible options. Start with the basics, as illustrated here, and
don't worry about the super-duper geeky stuff until
you're sure you actually need it. There comes a
point where plain old typing does the job just fine.
This sample ~/.vimrc demonstrates three
fundamental Vim features: customizing startup options, abbreviations,
and keymaps. Quotation marks are used to comment out lines.
"""""""""""""""""""""""""""""""""""""""""
" Carla's vimrc, created 4/22/2004 "
" Vim options "
"""""""""""""""""""""""""""""""""""""""""
" Turn off vi compatibility, to get all of Vim's features
set nocompatible
" Tabs use 4 spaces
set tabstop=4
" more powerful backspacing
set backspace=indent,eol,start
" Syntax highlighting on by default
syntax on
" auto-detect filetypes for syntax highlighting
filetype plugin indent on
"""""""""""""""""""""""""""""""""""""""""
" Abbreviations "
"""""""""""""""""""""""""""""""""""""""""
:ab Qu Carla Has Gone Fishing, Back Much Later
:ab Co Copyright (c) 2004 Carla Schroder all rights reserved
:ab Em carla@bratgrrl.com
:ab Wb http://tuxcomputing.com
"""""""""""""""""""""""""""""""""""""""""
" HTML tag mappings, for Insert mode "
"""""""""""""""""""""""""""""""""""""""""
:map! ,ah <A href="">
:map! ,a </A>
:map! ,b <B><Esc>ea</B><Esc>a
:map! ,i <I><Esc>ea</I><Esc>a
:map! ,l <LI><Esc>ea</LI><Esc>a
Any changes made to ~/.vimrc take effect the
next time you open Vim.
6.12.4 See Also
vim(1) Vim's online help (:help vimrc, :help
usr_05.txt, :help ab) Chapter 11 of Learning the vi Editor Chapter 8 of Vi IMproved—Vim
|