Vim is a very customizable editor. Many of the options you can set require you to type in a command like this:
:set autoindent |
This is the option to set autoindent which keeps the indentation level you are currently at when you hit the enter key. Rather than retype this command every time you want this option enabled, vim has a resource file it checks to see which options you would like set when vim starts. Technically, there are two such files, /etc/vimrc, and ~/.vimrc. Within these files you can set standard options which will automatically be set when you start vim.
The /etc/vimrc is the system wide configuration file and shouldn't really be edited unless you know what you are doing or you're the administrator for that machine. The ~/.vimrc file is located in your home directory (that's what the ~/ means, in case you were wondering) and is meant specifically for the purpose of customization.
Before editing a vimrc file it's a good idea to back it up just in case you mess it up beyond repair. |
You can see a list of available options that can be set by typing the following command:
:set all |
The output of that command looks something like this:
autoindent noincsearch scroll=18 textwidth=0 noautowrite noinfercase noscrollbind notildeop background=dark noinsertmode scrolljump=1 timeout backspace=2 isprint=@,161-255 scrolloff=0 timeoutlen=1000 nobackup joinspaces nosecure notitle backupext=~ key= selectmode= titlelen=85 nobinary keymodel= shell=/bin/bash titlestring= nocindent keywordprg=man shellcmdflag=-c nottimeout cinoptions= langmap= shellquote= ttimeoutlen=-1 cmdheight=1 laststatus=1 shellxquote= ttybuiltin columns=98 nolazyredraw noshiftround ttyfast nocompatible nolinebreak shiftwidth=4 ttymouse=xterm noconfirm lines=38 noshortname ttyscroll=999 cpoptions=aABceFs nolisp showbreak= ttytype=xterm dictionary= nolist noshowcmd undolevels=1000 nodigraph listchars=eol:$ noshowfulltag updatecount=200 display= magic showmatch updatetime=4000 noedcompatible makeprg=make showmode verbose=0 endofline matchtime=5 sidescroll=0 viminfo='20,"50 equalalways maxfuncdepth=100 nosmartcase visualbell equalprg= maxmapdepth=1000 nosmartindent warn noerrorbells maxmem=5120 nosmarttab noweirdinvert noexpandtab modelines=5 startofline wildcharm=^@ noexrc nomodified statusline= wildignore= fileencoding=ansi more swapfile nowildmenu fileformat=unix mouse= swapsync=fsync wildmode=full filetype= mousemodel=extend switchbuf= winheight=1 formatoptions=tcq mousetime=500 syntax= winminheight=1 formatprg= nonumber tabstop=4 wrap nogdefault nopaste tagbsearch wrapmargin=0 grepprg=grep -n pastetoggle= taglength=0 wrapscan helpheight=20 patchmode= tagrelative write |
As you can see there are a lot of options to set/unset. To get more information on what an option does simply type :help name_of_option replacing name_of_option with the option you're interested in.
Once you decide how you want an option to be set you can add it to your ~/.vimrc file. Using the autoindent example above, simply add this line to your vimrc file:
set autoindent "this sets the autoindent option " set noautoindent |
Comments are created in vimrc files using the " (quote) character. As you can see I put a comment next to the autoindent option and also added a "commented out" option which disables the previous noautoindent option I had set. Most of the options follow this convention; if you wish to disable it, simply put no in front of the option.
For more information about vimrc files type:
:help vimrc |
TODO. Need some useful examples of color schemes. Anyone want to coauthor?
For more information about color schemes type:
:help |
If you installed the vim-rt package described in Installing vim, all you have to do to enable syntax highlighting is add syntax on to your .vimrc file. The highlighting syntax is chosen based on filename extension so it happens pretty much automatically.
You can change the default colors of a syntax highlight by using the highlight command. For example, to change all comments to the color green type:
:highlight Comment ctermfg=green |
The second argument to that command is the group name. To make the setting permanent simply add it to your .vimrc.
In order for the color change to work the highlight command should come after the syntax on command in your .vimrc. |
To see what group names are available to be changed type:
:help group-name |
The available colors can be found by typing:
:help cterm-colors |
Some colors may not be available. Reference :help xterm-colors and :help xiterm for more information. |
TODO. Need some useful examples of customized syntax. Anyone want to coauthor?
For more information about syntax highlighting type:
:help syntax |
Abbreviations are just shortcuts you type which expand to longer versions of themselves. You can create an abbreviation simply by typing:
:ab dmv Department of Motor Vehicles |
Abbreviations take the form:
:ab abbreviation Full text, spaces are ok |
What happens is when you type the abbreviation in vim, as soon as you hit the space bar it is expanded to the full text. The abbreviation dmv in the prior example would expand to "Department of Motor Vehicles." If you close vim these settings are lost unless you commit them to your .vimrc file.
Unless you are only using the abbreviation on a small document, abbreviations are usually added to your personal .vimrc file. This is accomplished by adding the abbreviation like this:
ab abbreviation Everything after abbreviation will be input |
To find out which abbreviations you currently have defined, just type :ab and hit enter and the abbreviation definition will show up in the "status bar." |
For more information about abbreviations type:
:help ab |