"Use Vim settings, rather then Vi settings (much better!). "This must be first, because it changes other options as a side effect. set nocompatible "allow backspacing over everything in insert mode set backspace=indent,eol,start "store lots of :cmdline history set history=1000 set showcmd "show incomplete cmds down the bottom set showmode "show current mode down the bottom set incsearch "find the next match as we type the search set hlsearch "hilight searches by default set nowrap "dont wrap lines set linebreak "wrap lines at convenient points "statusline setup set statusline=%f "tail of the filename "display a warning if fileformat isnt unix set statusline+=%#warningmsg# set statusline+=%{&ff!='unix'?'['.&ff.']':''} set statusline+=%* "display a warning if file encoding isnt utf-8 set statusline+=%#warningmsg# set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''} set statusline+=%* set statusline+=%h "help file flag set statusline+=%y "filetype set statusline+=%r "read only flag set statusline+=%m "modified flag "display a warning if &et is wrong, or we have mixed-indenting set statusline+=%#error# set statusline+=%{StatuslineTabWarning()} set statusline+=%* set statusline+=%{StatuslineTrailingSpaceWarning()} set statusline+=%{StatuslineLongLineWarning()} set statusline+=%#warningmsg# set statusline+=%{StatuslineSyntaxWarning()} set statusline+=%* "display a warning if &paste is set set statusline+=%#error# set statusline+=%{&paste?'[paste]':''} set statusline+=%* set statusline+=%= "left/right separator set statusline+=%{StatuslineCurrentHighlight()}\ \ "current highlight set statusline+=%c, "cursor column set statusline+=%l/%L "cursor line/total lines set statusline+=\ %P "percent through file set laststatus=2 "recalculate the trailing whitespace warning when idle, and after saving autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning "return '[\s]' if trailing white space is detected "return '' otherwise function! StatuslineTrailingSpaceWarning() if !exists("b:statusline_trailing_space_warning") if search('\s\+$', 'nw') != 0 let b:statusline_trailing_space_warning = '[\s]' else let b:statusline_trailing_space_warning = '' endif endif return b:statusline_trailing_space_warning endfunction "return the syntax highlight group under the cursor '' function! StatuslineCurrentHighlight() let name = synIDattr(synID(line('.'),col('.'),1),'name') if name == '' return '' else return '[' . name . ']' endif endfunction "recalculate the tab warning flag when idle and after writing autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning "return '[&et]' if &et is set wrong "return '[mixed-indenting]' if spaces and tabs are used to indent "return an empty string if everything is fine function! StatuslineTabWarning() if !exists("b:statusline_tab_warning") let tabs = search('^\t', 'nw') != 0 let spaces = search('^ ', 'nw') != 0 if tabs && spaces let b:statusline_tab_warning = '[mixed-indenting]' elseif (spaces && !&et) || (tabs && &et) let b:statusline_tab_warning = '[&et]' else let b:statusline_tab_warning = '' endif endif return b:statusline_tab_warning endfunction "load all the syntax checkers runtime! syntax_checkers/*.vim "recalculate the syntax warning when saving and changing filetype autocmd bufwritepost,filetype * unlet! b:statusline_syntax_warning "return [syntax:X] if syntax errors are detected in the buffer, where X is the "line number of the first error. "return '' if no errors or if no syntax checker exists for the current filetype function! StatuslineSyntaxWarning() if !exists("b:statusline_syntax_warning") let b:statusline_syntax_warning = '' "if &ft is e.g. ruby.sinatra then syntax check both filetypes for ft in split(&ft, '\.') if exists("*CheckSyntax_" . ft) && filereadable(expand("%")) let first_err_line = CheckSyntax_{ft}() if first_err_line != 0 let b:statusline_syntax_warning = '[syntax:' . first_err_line . ']' break endif endif endfor endif return b:statusline_syntax_warning endfunction "recalculate the long line warning when idle and after saving autocmd cursorhold,bufwritepost * unlet! b:statusline_long_line_warning "return a warning for "long lines" where "long" is either &textwidth or 80 (if "no &textwidth is set) " "return '' if no long lines "return '[#x,my,$z] if long lines are found, were x is the number of long "lines, y is the median length of the long lines and z is the length of the "longest line function! StatuslineLongLineWarning() if !exists("b:statusline_long_line_warning") let long_line_lens = s:LongLines() if len(long_line_lens) > 0 let b:statusline_long_line_warning = "[" . \ '#' . len(long_line_lens) . "," . \ 'm' . s:Median(long_line_lens) . "," . \ '$' . max(long_line_lens) . "]" else let b:statusline_long_line_warning = "" endif endif return b:statusline_long_line_warning endfunction "return a list containing the lengths of the long lines in this buffer function! s:LongLines() let threshold = (&tw ? &tw : 80) let spaces = repeat(" ", &ts) let long_line_lens = [] let i = 1 while i <= line("$") let len = strlen(substitute(getline(i), '\t', spaces, 'g')) if len > threshold call add(long_line_lens, len) endif let i += 1 endwhile return long_line_lens endfunction "find the median of the given array of numbers function! s:Median(nums) let nums = sort(a:nums) let l = len(nums) if l % 2 == 1 let i = (l-1) / 2 return nums[i] else return (nums[l/2] + nums[(l/2)-1]) / 2 endif endfunction "indent settings set shiftwidth=4 set softtabstop=4 set expandtab set autoindent "folding settings set foldmethod=indent "fold based on indent set foldnestmax=3 "deepest fold is 3 levels set nofoldenable "dont fold by default set wildmode=list:longest "make cmdline tab completion similar to bash set wildmenu "enable ctrl-n and ctrl-p to scroll thru matches set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing "display tabs and trailing spaces set list set listchars=tab:▷⋅,trail:⋅,nbsp:⋅ set formatoptions-=o "dont continue comments when pushing o/O "vertical/horizontal scroll off settings set scrolloff=3 set sidescrolloff=7 set sidescroll=1 "load ftplugins and indent files filetype plugin on filetype indent on "turn on syntax highlighting syntax on "some stuff to get the mouse going in term set mouse=a set ttymouse=xterm2 "tell the term has 256 colors set t_Co=256 "hide buffers when not displayed set hidden "dont load csapprox if we no gui support - silences an annoying warning if !has("gui") let g:CSApprox_loaded = 1 endif "make clear the highlight as well as redraw nnoremap :nohls inoremap :nohls "map to bufexplorer nnoremap :BufExplorer "map to fuzzy finder text mate stylez nnoremap :FuzzyFinderTextMate "map Q to something useful noremap Q gq "make Y consistent with C and D nnoremap Y y$ "snipmate setup source ~/.vim/snippets/support_functions.vim autocmd vimenter * call s:SetupSnippets() function! s:SetupSnippets() "if we're in a rails env then read in the rails snippets if filereadable("./config/environment.rb") call ExtractSnips("~/.vim/snippets/ruby-rails", "ruby") call ExtractSnips("~/.vim/snippets/eruby-rails", "eruby") endif call ExtractSnips("~/.vim/snippets/html", "eruby") call ExtractSnips("~/.vim/snippets/html", "xhtml") call ExtractSnips("~/.vim/snippets/html", "php") endfunction "visual search mappings function! s:VSetSearch() let temp = @@ norm! gvy let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g') let @@ = temp endfunction vnoremap * :call VSetSearch()// vnoremap # :call VSetSearch()?? "jump to last cursor position when opening a file "dont do it when writing a commit log entry autocmd BufReadPost * call SetCursorPosition() function! SetCursorPosition() if &filetype !~ 'commit\c' if line("'\"") > 0 && line("'\"") <= line("$") exe "normal! g`\"" normal! zz endif end endfunction "define :HighlightLongLines command to highlight the offending parts of "lines that are longer than the specified length (defaulting to 80) command! -nargs=? HighlightLongLines call s:HighlightLongLines('') function! s:HighlightLongLines(width) let targetWidth = a:width != '' ? a:width : 79 if targetWidth > 0 exec 'match Todo /\%>' . (targetWidth) . 'v/' else echomsg "Usage: HighlightLongLines [natural number]" endif endfunction