Hacking Vim – The Ultimate Vimrc
Posted by Jon Lee in Efficiency, Linux, Personal, tags: coding, Efficiency, programming, text editor, vim, vimrc
Maybe ultimate is the wrong word, but since my last post about a 256-color Vim colorscheme, I’ve gotten a few e-mails asking for a copy of my Vim configuration file (my .vimrc). I figure I might as well share it with everyone. I’ve added comments here and there so you’ll know what everything does. A lot of the settings are from the book Hacking Vim: A Cookbook to get the Most out of the Latest Vim Editor.
set nocompatible
set bs=2 “set backspace to be able to delete previous characters”Enable line numbering, taking up 6 spaces
set number“Turn off word wrapping
set wrap!“Turn on smart indent
set smartindent
set tabstop=4 “set tab character to 4 characters
set expandtab “turn tabs into whitespace
set shiftwidth=4 “indent width for autoindent
filetype indent on “indent depends on filetype“Shortcut to auto indent entire file
nmap <F11> 1G=G
imap <F11> <ESC>1G=Ga“Turn on incremental search with ignore case (except explicit caps)
set incsearch
set ignorecase
set smartcase“Informative status line
set statusline=%F%m%r%h%w\ [TYPE=%Y\ %{&ff}]\ [%l/%L\ (%p%%)]“Set color scheme
set t_Co=256
colorscheme desert256
syntax enable“Enable indent folding
set foldenable
set fdm=indent“Set space to toggle a fold
nnoremap <space> za“Hide buffer when not in window (to prevent relogin with FTP edit)
set bufhidden=hide“Have 3 lines of offset (or buffer) when scrolling
set scrolloff=3
The following apply only to gVim (GUI stuff). The script enables a little tooltip with spelling suggestions when you hover over a word with the mouse.
“Set the font and size
set guifont=Lucida\ Console”Hide toolbar
set guioptions-=T“Enable balloon tooltips on spelling suggestions and folds
function! FoldSpellBalloon()
let foldStart = foldclosed(v:beval_lnum )
let foldEnd = foldclosedend(v:beval_lnum)
let lines = []
” Detect if we are in a fold
if foldStart < 0
” Detect if we are on a misspelled word
let lines = spellsuggest( spellbadword(v:beval_text)[ 0 ], 5, 0 )
else
” we are in a fold
let numLines = foldEnd – foldStart + 1
” if we have too many lines in fold, show only the first 14
” and the last 14 lines
if ( numLines > 31 )
let lines = getline( foldStart, foldStart + 14 )
let lines += [ '-- Snipped ' . ( numLines - 30 ) . ' lines --' ]
let lines += getline( foldEnd – 14, foldEnd )
else
“less than 30 lines, lets show all of them
let lines = getline( foldStart, foldEnd )
endif
endif
” return result
return join( lines, has( “balloon_multiline” ) ? “\n” : ” ” )
endfunction
set balloonexpr=FoldSpellBalloon()
set ballooneval
Some extra options available only on Vim version 7 and up so don’t use these on a system running anything lower or it’ll give annoying messages on load.
“Set line numbering to take up 5 spaces
set numberwidth=5″Highlight current line
set cursorline“Turn on spell checking with English dictionary
set spell
set spelllang=en
set spellsuggest=9 “show only 9 suggestions for misspelled words
My custom .vimrc is by no means exhaustive, it’s always changing and growing. If you have any tips on customizing Vim I’d like to hear it!
Popularity: 13% [?]
Entries (RSS)