" Andrew McNabb's vimrc """ TODO: look at ftplugin-overrule """ """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Use Vim settings, rather then Vi settings (usually better). " This must be first, because it changes other options as a side effect. set nocompatible " 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 " Highlight match while typing search pattern set incsearch " Allow lower case to match upper case search targets. set smartcase " Show vim commands in the status bar as they're being typed set showcmd if executable("/bin/zsh") set shell=/bin/zsh endif " Force UTF-8. set termencoding=utf-8 " Improve smoothness of redrawing for fast connections, etc. set ttyfast " Briefly jump to the open paren when the matching close paren is typed. set showmatch " How long to show the matching paren. set matchtime=1 " Completion for ex command-line set wildmenu set wildmode=longest:full,full " Get rid of the Vim intro screen set shortmess+=I """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Colors " Switch syntax highlighting on, when the terminal has colors " Also switch on highlighting the last used search pattern. if &t_Co > 2 || has("gui_running") syntax on set hlsearch endif " Add a highlight group to look out for trailing whitespace. " Thanks to: http://vim.wikia.com/wiki/Highlight_unwanted_spaces highlight TrailingWhitespace ctermbg=red guibg=red autocmd colorscheme * highlight TrailingWhitespace ctermbg=red guibg=red 2match TrailingWhitespace /\s\+$/ " Explanation of the following: whitespace: \s , one or more: \+ , " current cursor position: \%# , negate: \@ :nohl " Toggle the 'paste' option with F11. set pastetoggle= " Spell Checking "nmap :w!:!aspell -x check %:e! nmap :set invspell " ReST editing stuff function ReST_Extend_Line() let cur = getline(".") let prev = getline( line(".") - 1 ) return repeat(cur[0], len(prev) - len(cur)) endfunction imap =ReST_Extend_Line() map yypVr " Turn off stupid mouse stuff. "set mouse=a ":map ":map! ":map ":map! " Disable motion keys in insert mode imap imap imap imap " Also disable delete key in insert mode imap " Don't use Ex mode. map Q " Make p in Visual mode replace the selected text with the "" register. vnoremap p :let current_reg = @"gvs=current_reg " This is an alternative that also works in block mode, but the deleted " text is lost and it only works for putting the current register. "vnoremap p "_dp """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Fold Settings (note that files will default to all folds being open) set foldenable set foldlevelstart=0 set foldopen=block,hor,jump,mark,percent,quickfix,search,tag,undo """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Default File Settings set autoindent set backspace=indent,eol set ignorecase " blank lines at bottom and top of screen set scrolloff=2 " split lines at a convenient point "set linebreak " show line and column number in the status bar set ruler set nosmartindent set smarttab " For all files set 'textwidth' to 78 characters. set textwidth=78 " Set default format options "default: formatoptions="tcq" set formatoptions=cql "no stupid tab-space mixing in indents set shiftround let g:detectindent_preferred_expandtab = 1 let domainname = substitute(system("hostname -d"),"\n","","g") if domainname == "mtv.corp.google.com" " Use 2 spaces when you hit the tab key. set et sw=2 sts=2 "let g:detectindent_preferred_indent = 2 "source /home/build/nonconf/google3/tools/tags/gtags.vim nmap :call Gtag(expand('')) " Correctly indent Java anonymous classes. autocmd FileType cpp setlocal cinoptions+=j1 " Indent a continuation line N addnl chars. autocmd FileType cpp setlocal cinoptions+=+2s " When in unclosed parens, indent N chars from the paren. autocmd FileType cpp setlocal cinoptions+=(0 " C++ scope declarations: N characters from indent of the block. autocmd FileType cpp setlocal cinoptions+=g1 " Statements after C++ scope decls: N chars from indent of the label. autocmd FileType cpp setlocal cinoptions+=h1 else " Use 4 spaces when you hit the tab key. set et sw=4 sts=4 let g:detectindent_preferred_indent = 4 "autocmd BufReadPost DetectIndent " Override stupid DetectIndent--tabs should always be 8 spaces: autocmd BufReadPost set ts=8 endif """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Filetype specific settings " 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 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Makefile Settings " Makefiles only work if you use actual tab characters. autocmd FileType make setlocal noet sw=8 sts=8 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Email " default formatoptions is tcq autocmd FileType mail setlocal formatoptions=tcql autocmd FileType mail setlocal textwidth=72 autocmd FileType mail setlocal iskeyword+=- """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " HTML autocmd FileType html setlocal formatoptions=ql " turn off crazy html indenting autocmd FileType html setlocal indentexpr= """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Go " Disable the strobe effect option: let go_highlight_trailing_whitespace_error = 0 autocmd FileType go setlocal noet sw=8 sts=8 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Python " " Close foldlevels 1 and greater by default (jpythonfold.vim is in ftplugins) autocmd FileType python setlocal foldlevel=1 autocmd BufNewFile *.py .! cat ~/.vim/skel.py """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " C/C++ autocmd FileType cpp setlocal cindent """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Shell Scripts " informs sh syntax that /bin/sh is actually bash let is_bash=1 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Modeline (potentially dangerous) set modeline " vim: ts=8