" Brendan O'Connor's .vimrc - dotfiles.org/~brendano - brenocon at gmail
" for Vim 6.x, 7.x
" make sure to liberally use :help TOPIC
" and get .vim/ from (at the moment) brendano.users.sonic.net/vim.tgz
set exrc
if filereadable(expand("$VIM/runtime/colors/macvim.vim"))
colo macvim
elseif filereadable(expand("$HOME/.vim/colors/brendano.vim"))
colo brendano
elseif has("gui_running")
colo zellner
" colo murphy
else
" colo evening
colo zellner
end
set background=light
"let xterm16_colormap = 'light'
"let xterm16_brightness = 'default'
"colo xterm16
" ------------------------ General Options -----------------------------
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
set encoding=utf8
" Gui options
" set guioptions=aigmrL "plays around with menu/toolbars
set guioptions=agimlLtT
" unix, windows, mac, etc all want different names
" set guifont=Courier_New:h10:cANSI
" set guifont=monospace_12
" set guifont=-misc-fixed-medium-r-normal-*-*-130-*-*-c-*-iso8859-15
" set guifont=-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1
set mouse=a " For mouse support on a good terminal (xterm, putty, iterm, *not*
" mac terminal by default)
" set term=xterm-color " normally is set by TERM but sometimes vim is smarter
" with an override
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" set autoindent
set backup " keep a backup file
set history=1000 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
set ignorecase smartcase
set scrolloff=2
set showmatch " parenthesis matching
syntax on
set hlsearch
" tab completion for e.g. :e is awesome with these
set wildmenu
"set wildmode=list:longest,full
set wildmode=list:longest
set hidden " have multiple buffers without saving all the time
set title
" Tabbing world... I *think* this is the best compromise between all
" the competing incompatible standards out there...
set expandtab " spaces not tabs
set tabstop=8 " the one true tab size
set shiftwidth=2 " size for auto/smartindent
set softtabstop=2 " when you press <tab> it moves by this much
set shiftround
set smartindent " :help says needs to have autoindent but doesn't seem so
" Don't put *~ backup files and .*.swp swap files in the current dir - instead
" put all in ~/.bak
set backupdir=~/.bak,.,~
set directory=~/.bak,.,~
if version>=700
set autochdir " so :e is relative to current file
set tags+=$PWD/tags " necessary since chdir keeps changing
endif
let g:explHideFiles='^\.,pyc$,.pyo$,.o$,.obj$'
" -------------------- Key Redefinitions ------------------------
" emacs/cocoa-style keybindings
noremap <C-Y> p
noremap <C-A> ^
noremap <C-E> $
noremap <C-D> x
inoremap <C-K> <C-O>D
inoremap <C-Y> <C-O>p
inoremap <C-A> <C-O>^
inoremap <C-E> <C-O>$
inoremap <C-D> <C-O>x
" Ctrl-style scrolling (stationary cursor)
noremap <C-Down> <C-E>
noremap <C-Up> <C-Y>
noremap <C-J> <C-E>
noremap <C-K> <C-Y>
" Arrow keys to screen lines, not physical lines.
" [jk default behavior preserved.]
noremap <up> gk
noremap <down> gj
" Tabs
" D- is the mac command key in gvim. Was trying to emulate safari
" keybindings, not sure how successful
noremap <D-]> :tabn<cr>
noremap <D-[> :tabp<cr>
noremap <D-t> :tabe<cr>
noremap <D-w> :tabclose<cr>
imap <D-]> <C-O>:tabn<cr>
imap <D-[> <C-O>:tabp<cr>
" Don't use Ex mode, use Q for formatting
map Q gq
" F-Keys
" For the upper-left-cramped IBM thinkpad keyboard... no more F1 -> help
map <F1> <Esc>
imap <F1> <Esc>
vmap <F1> <Esc>
" Compiler integration -- past F12 inteded for left side on a Sun keyboard
" they used to have in dear old sweet hall.
map <F13> :make<CR>
" These work with :grep matches, too
map <F11> :cp<CR>
map <F12> :cn<CR>
map <F14> :cc<CR>
map <F17> :colder<CR>
map <F18> :cnewer<CR>
" Buffer moving
map <F8> :bp<CR>
map <F9> :bn<CR>
" " vtreeexplorer.vim http://www.vim.org/scripts/script.php?script_id=184
" "map \te :vsp<CR>:vertical resize 30<CR>:VTreeExplore<CR>
" let g:treeExplVertical = 1
" let g:treeExplWinSize = 30
map \te :VSTreeExplore<CR>
" NERD tree is the best speedbar I've seen - it makes vim dramatically more
" useful for multi-file projects.
" http://www.vim.org/scripts/script.php?script_id=1658
map \ne :NERDTreeToggle<CR>
let NERDTreeMapActivateNode='<CR>'
" buffer explorer is like emacs electric-buffer-list -- it uses most recently
" visited sort order, so you can hit three close-by keystrokes:
" ; <down> <enter>
" to swap with the most recently visited file. This is the only multi-file
" editing feature missing from eclipse and textmate.
"
map ; \be
" tComment.vim http://www.vim.org/scripts/script.php?script_id=1173
" doesnt have visual mode commenting so we add it
vnoremap gc :TComment<CR>
vnoremap ,c :TComment<CR>
nmap ,c gcc
" really basic commenting -- vim.org tip #271
" lhs comments
map ,# :s/^\s*/\0#/<CR>:nohlsearch<CR>
map ,/ :s/^\s*/\0\/\//<CR>:nohlsearch<CR>
"map ,/ :s/^/\/\/ /<CR>:nohlsearch<CR>
map ,> :s/^\s*/\0>/<CR>:nohlsearch<CR>
map ," :s/^\s*/\0\"/<CR>:nohlsearch<CR>
map ,% :s/^\s*/\0%/<CR>:nohlsearch<CR>
map ,! :s/^\s*/\0!/<CR>:nohlsearch<CR>
map ,; :s/^\s*/\0;/<CR>:nohlsearch<CR>
map ,- :s/^\s*/\0-- /<CR>:nohlsearch<CR>
"map ,c :s/^\s*\/\/\\|^--\\|^> \\|^[#"%!;]//<CR>:nohlsearch<CR>
" wrapping comments
map ,* :s/^\(.*\)$/\/\* \1 \*\//<CR>:nohlsearch<CR>
map ,( :s/^\(.*\)$/\(\* \1 \*\)/<CR>:nohlsearch<CR>
map ,< :s/^\(.*\)$/<!-- \1 -->/<CR>:nohlsearch<CR>
map ,d :s/^\([/(]\*\\|<!--\) \(.*\) \(\*[/)]\\|-->\)$/\2/<CR>:nohlsearch<CR>
"
"" UN-commenting -- just kill first token on line, works only for lhs comments
"map ,, :s/\s*\S*\s\(.*\)/\1/<CR>:nohlsearch<CR>
" "map ,<Space> :s/^\(\s*\)\(\/\/\|[#%!><]\)/\1/<CR>:nohlsearch<CR>
" gotta double backslash the pipe because of "map"
map ,<Space> :s/^\(\s*\)\([#"%!;<>]\\|\/\/\)/\1/<CR>:nohlsearch<CR>
"map ,m :s/.*/"\0"/<CR>:nohlsearch<CR>
" Un-comment
map ,<Space> :s/^"\(.*\)"$/\1/<CR>:nohlsearch<CR>
ab pf printf(
" Make p in Visual mode replace the selected text with the "" register.
vnoremap p <Esc>:let current_reg = @"<CR>gvs<C-R>=current_reg<CR><Esc>
" 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
" Name completion with tab. Need to change this once I figure out how, so
" you can use the tab button more often.
" function! CleverTab()
" if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
" return "\<Tab>"
" else
" return "\<C-N>"
" endfunction
" inoremap <Tab> <C-R>=CleverTab()<CR>
" crappy hacky title setting
function! SetTitle(newtitle)
let zshcmd='\e]0;' . a:newtitle . '\a'
execute "silent ! print -Pn \"" . zshcmd ."\""
"" This should be the iterm escape sequence, but doesnt seem to work
"let zshcmd='\e]1;' . a:newtitle . '\a'
"execute "silent ! print -Pn \"" . zshcmd ."\""
redraw!
endfunction
" augroup mkd
" augroup END
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
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
au FileType text setlocal textwidth=78
au FileType make setlocal noexpandtab
" 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
" markdown filetype file
au BufRead *.md,*.mkd set ai formatoptions=tcroqn2 comments=n:>
" au FileType python source ~/.vim/python.vim
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
" if filereadable(expand("$HOME/.vim/plugin/vimbuddy.vim"))
" set statusline+=\ %{VimBuddy()} " vim buddy
" endif
" vim:sw=2:sts=2:noet: