Skip to content

Instantly share code, notes, and snippets.

@JohnBrodie
Created January 30, 2012 21:02
Show Gist options
  • Save JohnBrodie/1706674 to your computer and use it in GitHub Desktop.
Save JohnBrodie/1706674 to your computer and use it in GitHub Desktop.
Vim setup
" Base Options
set nocompatible " Get rid of Vi compatibility mode. SET FIRST!
set isk+=_,$,@,%,#,- " Make these characters count as part of a word.
set viminfo+=! " Make sure we can save viminfo.
set ignorecase " Ignore case in searches
filetype on
filetype off
" Start Pathogen
call pathogen#infect()
" Syntastic
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
SyntasticEnable php
SyntasticEnable javascript
SyntasticEnable xhtml
SyntasticEnable python
let g:syntastic_enable_signs=1
let g:syntastic_auto_loc_list=1
"let g:syntastic_quiet_warnings=1
" pep8-text-width
let g:pep8_text_width = 79 " Default 79
let g:pep8_comment_text_width = 72 " Default 72
" GUI vim options
if has("gui_running")
set guioptions-=T " no : toolbar
set guioptions-=e " no : toolbar
set guioptions-=m " no : menu
set guioptions+=a " yes: autoselect
set guicursor=a:blinkon0 " set blinking cursor
set list listchars=tab:»·,trail:·
set showtabline=0 " remove tab line from top of vim
winpos 0 0 " set window position
colorscheme desert256 " enable delek color scheme
set guifont=Monaco:h12 " set vi font to Monaco 12pt
set transparency=8 " set transparancy to 15%
set lines=64 " make window columnsXlines
set columns=90 " make window columnsXlines
" set lines=45 " make window columnsXlines home
" set columns=100 " make window columnsXlines home
else
colorscheme delek " enable desert
endif
" UI Themes and colors
syntax enable " enable syntax highlighting
syntax on " NOT SURE IF NEEDED
set ruler " show info bar on bottom row
set noerrorbells " disable visual bells
set visualbell t_vb= " disable bells
set number " show line numbers
set t_Co=256 " enable 256 colors
set wildmenu " enable wildmenu Enter :e in the command line and press ^D.
" Visual Cues
set showmatch " show matching braces and brackets
set mat=2 " 1/10's of a second to show match
set hlsearch " dont highlight searches
set incsearch " highlight searches as you type them
set hidden " allow buffer nav without save
" Text formatting/layout
set tabstop=4 " tabspacing
set softtabstop=4 " unify?
set shiftwidth=4 " indent by 4 spaces
set shiftround " indent to nearest tabstop
set expandtab " use spaces instead of tabs
set foldlevel=10 " disable code folding
" Syntax highlighting
filetype plugin indent on
autocmd BufRead *.thtml set filetype=php
autocmd BufRead *.html set filetype=php
autocmd BufRead *.htm set filetype=php
autocmd BufRead *.ctp set filetype=php
autocmd BufRead *.zcml set filetype=xml
autocmd BufRead *.inc set filetype=php
autocmd BufRead *.pm set filetype=perl
autocmd BufRead *.t set filetype=perl
autocmd BufRead *.py set filetype=python
autocmd BufRead *.mako set filetype=html
" display >79 character highlighting in python
" autocmd FileType python setlocal errorformat=%f:%l:%c %m,%f:%l %m
" au BufEnter * if &filetype == "python" | match ErrorMsg '\%>179v.\+' | endif
autocmd FileType txt setlocal wrap
autocmd FileType txt setlocal spell spelllang=en_us
" Remove trailing whitespace from python files
autocmd FileType python autocmd BufWritePre <buffer> :call setline(1,map(getline(1,"$"),'substitute(v:val,"\\s\\+$","","")'))
" File Templates
" au BufNewFile *.pm :r $HOME/etc/vim/templates/perl-moose.pm | normal -1dd
" au BufNewFile *.pl :r $HOME/etc/vim/templates/perl-std.pl | normal -1dd
" au BufNewFile *.t :r $HOME/etc/vim/templates/perl-tests.t | normal -1dd
" au BufNewFile *.php :r $HOME/etc/vim/templates/php-std.php | normal -1dd
" au BufNewFile *.php :r $HOME/etc/vim/templates/bash-script.sh | normal -1dd
" au BufNewFile *.php :r $HOME/etc/vim/templates/sql-schemachanges.sql | normal -1dd
" au BufNewFile *.py :r $HOME/etc/vim/templates/python-std.py | normal -1dd
"
" Insert mode key mappings
imap <F1> <Esc>
map <F1> <Esc>
" Macros (All macros will save the buffer before running the external command)
"
" F5 run syntax checking / code convention check
" F6 show file in trac
" S+F6 show file in trac with revisions
" C+F6 display nice svn diff (not impliented)
" F7 run test suite
" F8 generate autodocs and display
" Global Macros ===========================================================================================================================
nmap <F6> :w<CR> :!~/svn/trunk/code/local/oit %<CR>
nmap <S-F6> :w<CR> :!~/svn/trunk/code/local/oit -r %<CR>
map <C-Right> :bn<CR>
map <C-Left> :bp<CR>
" Python Macros ===========================================================================================================================
"au FileType python setlocal makeprg=(echo\ 'expand([%])';\ ~/.vim/rpylint\ --include-pep8\ %)
"au FileType python setlocal errorformat=%f:%l:\ %m
"autocmd FileType python nmap <silent> <F5> :w<CR> :make<CR>:cw<CR>
au FileType python setlocal makeprg=(echo\ '[%:p]';\ ~/.vim/rpylint\ %:p)
au FileType python setlocal errorformat=%f:%l:\ %m
map <silent> <F5> :make<CR>:cw<CR>
au BufEnter * if &filetype == "python" | syntax match ErrorMsg '\%>79v.\+' | endif
au BufEnter * if &filetype == "php" | syntax match ErrorMsg '\%>120v.\+' | endif
au BufEnter * if &filetype == "javascript" | syntax match ErrorMsg '\%>80v.\+' | endif
" PHP Macros ==============================================================================================================================
autocmd FileType php nmap <F7> :w<CR> :!~/svn/trunk/code/local/oi_phptestsuite %<CR>
autocmd FileType php nmap <F8> :w<CR> :!~/svn/trunk/code/local/oi_phpdocs %<CR>
" NERD Tree ===============================================================================================================================
" GUI vim options
if has("gui_running")
let NERDTreeIgnore=['\~$', '\.pyc$', '\.egg-info$', '_compressed\.js$', '^build-python2\.[56]$', '^docs_build$', '^tags$', '^branches$']
let NERDTreeWinPos='right'
let NERDTreeSortOrder=['__init__\.py$', '\/$', '*', '\.swp$', '\.bak$', '\~$']
map <F15> :NERDTreeToggle<CR>
au GUIEnter :NERDTreeToggle<CR>
endif
" Tab completion
" Smart tab completion.
function! InsertTabWrapper()
let col = col('.') - 1
let line = getline('.')
if (match(line, '\(require\|include\)') >= 0)
return "\<C-x>\<C-f>"
elseif col && getline('.')[col - 1] == '('
return "\<tab>"
elseif col && getline('.')[col - 1] !~ '\k'
return "\<tab>"
elseif col
return "\<C-p>"
else
return "\<tab>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment