" 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 set hidden " allow hidden unsaved buffers set autoindent " if there's no better indenter, use heuristics. set tw=76 " a sane default wrap width set hidden " allow unsaved changes in hidden buffers set shiftwidth=4 " 4 space indents set shiftround " round to nearest width set smarttab " smart tabbing set expandtab " expand tabs to spaces set showmatch " show matching brackets set linebreak " turn on word wrap set backup " keep a backup file set history=50 " keep 50 lines of command line history set ruler " show the cursor position all the time set laststatus=2 " even if there's only one window set showcmd " display incomplete commands set incsearch " do incremental searching set mousemodel=popup " show a context menu if clicking in selection set encoding=utf-8 " use UTF8 encoding set autowrite " save buffer before stuff like :make set noerrorbells " disable error bells set tags+=~/.vim/systags " add the tags in /usr/include set cino=(0 " line up sublines with first ( set guioptions-=T " turn off the toolbar set guioptions-=m " turn off the toolbar set tags=tags;/ set cot=menuone " always show a menu with extra information set wildmode=longest,list " set tab completion to something bash-like, set vb t_vb= " disable the bell " where it only expands the longest common substring " omnicomplete options " do mappings: " map j and k to gj and gk, to allow moving normally on wrapped " lines in the UI. nmap j gj nmap k gk " map ; to : to avoid chording nmap ; : " switch to GNU indent style (ick) nmap gi :call UglifyIndent() nmap ft :call FindTag() " map wq variants to save all windows com W :windo :w com WQ :windo :wq com Wq :windo :wq " Switch syntax highlighting on, when the terminal has colors if &t_Co > 2 || has("gui_running") syntax on endif " if we're running in a GUI, run the moria style, but tweak " the comment color to a dirty yellow if has("gui_running") let moria_style='dark' colo moria set guifont=Monospace\ 8 " otherwise, dark background if running in terminal, since " I use a black background elseif &t_Co > 2 set bg=light endif command! -complete=file -nargs=+ Shell call s:RunShellCommand() function! s:RunShellCommand(cmdline) botright new setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap call setline(1,a:cmdline) call setline(2,substitute(a:cmdline,'.','=','g')) execute 'silent $read !'.escape(a:cmdline,'%#') 1 endfunction function! TexFixQuotes() let prevchar = getline(line('.'))[col('.')-2] if prevchar == '' || prevchar =~ '[[:space:]{\[(]' return "``" else return "''" endif endfunction function UglifyIndent() set cinoptions={.5s,:.5s,+.5s,t0,g0,^-2,e-2,n-2,p2s,(0,=.5s set formatoptions=croql set shiftwidth=4 set tabstop=8 endfunction if !exists(":DiffOrig") command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis \ | wincmd p | diffthis endif " find the base working directory of a project. This is assumed to be -- " searching upwards -- the first directory containing a 'configure' script, or " the input file for configure. If none of these exist, it takes the directory " as the current directory the file is saved in. " " If you want to work with a non-automake project, update the definition of " this function. function ProjectDir() let dir = expand('%:p') let olddir = '' if (dir =~ "^$") let dir = getcwd() endif " find the first directory with 'configure*' file while dir != olddir && \ glob(dir . "/configure*") =~ "^$" let olddir = dir let dir = fnamemodify(dir, ":h") endwhile " if we didn't find it, just use cwd as the project " directory if glob(dir . "/configure*") =~ "^$" let dir = getcwd() endif return dir endfunction " updates the projectwide tag file. First it strips out references to " the current file, so that duplicate tags aren't created, then it " incrementally updates the tags. function TagUpdate() if exists('b:tag_path') call system("sed -i '/".escape(expand("%:t"), '[]()\.{}^$')."/d' ". b:tag_path) call system("ctags -f ".b:tag_path." -a ".expand("%:p")) endif endfunction if has("autocmd") " Enable file type detection. " Use the default filetype settings, so that mail gets 'tw' set to 72, " 'cindent' is on in C files, etc. " Also load indent files, to automatically do language-dependent indenting. filetype plugin indent on filetype plugin on " Put these in an autocmd group, so that we can delete them easily. " au! " For all text files set 'textwidth' to 78 characters. autocmd FileType text setlocal textwidth=78 let b:is_source = 0 autocmd FileType c,cpp,java,perl,lisp,cpp,python,javascript,yacca,lua,haskell,cs,awk,sh,ruby \ let b:is_source=1 " When editing a file, always jump to the last known cursor position. " Don't do it when the position is invalid or when inside an event handler " (happens when dropping a file on gvim). autocmd BufReadPost * \ if line("'\"") > 0 && line("'\"") <= line("$") | \ exe "normal g`\"" | \ endif | \ let b:tag_path = ProjectDir() . "/tags" | \ let &tags = &tags . "," . b:tag_path " ctags handling let b:tag_path = ProjectDir() . "/tags" let &tags = &tags . "," . b:tag_path autocmd BufWritePost * \ if exists("b:is_source") && b:is_source | \ call TagUpdate() | \ endif " Insert the correct item for '"' in tex mode (`` before a word, '' after) autocmd FileType tex,latex \ imap " =TexFixQuotes()| \ setlocal spell spelllang=en_ca " Indent and color.myr files like .c files autocmd BufRead,BufNewFile *.myr set cindent | set noet | set sw=8 autocmd BufRead,BufNewFile *.myr source $VIMRUNTIME/syntax/c.vim " set filetype=mail for sylpheed's temporary mail files autocmd BufRead,BufNewFile ~/.sylpheed* set ft=mail endif command TV !texview % let OmniCpp_SelectFirstItem = 2 " select but don't complete the first item let OmniCpp_ShowPrototypeInAbbr = 1 " show prototype in abbrev