2010-11-30 12:26:57 +11:00
|
|
|
set nocompatible
|
|
|
|
|
2011-02-09 00:42:20 +11:00
|
|
|
runtime! macros/matchit.vim
|
2011-01-15 16:32:50 +11:00
|
|
|
|
2010-11-30 01:02:34 +11:00
|
|
|
" Pathogen setup
|
2011-02-09 00:42:20 +11:00
|
|
|
runtime autoload/pathogen.vim
|
2010-11-30 01:35:37 +11:00
|
|
|
if exists('g:loaded_pathogen')
|
|
|
|
filetype off
|
|
|
|
|
2010-11-30 12:26:57 +11:00
|
|
|
call pathogen#runtime_append_all_bundles()
|
2010-11-30 01:35:37 +11:00
|
|
|
call pathogen#helptags()
|
|
|
|
endif
|
2010-11-30 01:02:34 +11:00
|
|
|
|
2010-12-06 13:06:09 +11:00
|
|
|
" Syntax
|
2010-11-30 01:02:34 +11:00
|
|
|
syntax on
|
2010-11-30 01:35:37 +11:00
|
|
|
filetype plugin indent on
|
2011-02-21 15:56:13 +11:00
|
|
|
"match ErrorMsg '\%>80v.\+'
|
2010-12-06 13:06:09 +11:00
|
|
|
|
|
|
|
" UI
|
|
|
|
set number
|
|
|
|
set ruler
|
2010-12-22 01:27:34 +11:00
|
|
|
set guioptions=ce
|
2010-12-06 13:06:09 +11:00
|
|
|
set mouse=a
|
2010-11-30 01:02:34 +11:00
|
|
|
colorscheme railscasts
|
|
|
|
|
2010-12-06 13:06:09 +11:00
|
|
|
" Tabs/Whitespace
|
2010-11-30 01:02:34 +11:00
|
|
|
set tabstop=2
|
|
|
|
set shiftwidth=2
|
|
|
|
set autoindent
|
|
|
|
set smarttab
|
|
|
|
set expandtab
|
2010-12-06 13:06:09 +11:00
|
|
|
set nowrap
|
2011-02-09 00:43:02 +11:00
|
|
|
set list
|
|
|
|
set listchars=tab:▸\ ,eol:¬,trail:·
|
2010-11-30 01:02:34 +11:00
|
|
|
|
2011-02-21 15:56:13 +11:00
|
|
|
set switchbuf=useopen " Don't re-open already opened buffers
|
|
|
|
set nostartofline " Avoid moving cursor to BOL when jumping around
|
|
|
|
set virtualedit=all " Let cursor move past the last char
|
|
|
|
set showmatch " Briefly jump to a paren once it's balanced
|
|
|
|
set whichwrap=b,s,h,l,<,>,[,]
|
|
|
|
let mapleader = ','
|
|
|
|
set statusline=%<%f\ %h%m%r%{fugitive#statusline()}%=%-14.(%l,%c%V%)\ %P
|
|
|
|
set autoread " watch for file changes
|
|
|
|
set fileformats=unix
|
|
|
|
|
|
|
|
|
2010-12-06 13:06:09 +11:00
|
|
|
" Searching
|
|
|
|
set hlsearch
|
|
|
|
set incsearch
|
|
|
|
set ignorecase
|
|
|
|
set smartcase
|
|
|
|
|
|
|
|
" Tab completion
|
|
|
|
set wildmode=list:longest,list:full
|
2011-02-09 00:44:39 +11:00
|
|
|
set wildignore+=*.o,*.obj,.git,*.rbc,*.swp
|
2010-12-06 13:06:09 +11:00
|
|
|
|
|
|
|
" Status bar
|
|
|
|
set laststatus=2
|
|
|
|
|
2011-03-24 16:28:27 +11:00
|
|
|
set linespace=2
|
|
|
|
|
2010-12-22 00:14:07 +11:00
|
|
|
" NERDTree configuration
|
|
|
|
let NERDTreeIgnore=['\.rbc$', '\~$']
|
2011-02-21 15:56:13 +11:00
|
|
|
map <Leader>n :NERDTreeToggle<CR>:wincmd l<CR>
|
2010-12-22 00:14:07 +11:00
|
|
|
|
|
|
|
" Project Tree
|
2011-02-09 00:42:20 +11:00
|
|
|
autocmd! VimEnter * call s:CdIfDirectory(expand("<amatch>"))
|
2010-12-22 00:14:07 +11:00
|
|
|
|
2011-02-09 00:42:20 +11:00
|
|
|
" Reselect visual block after adjusting indentation
|
|
|
|
vnoremap < <gv
|
|
|
|
vnoremap > >gv
|
2010-12-22 00:14:07 +11:00
|
|
|
|
2011-02-21 15:56:13 +11:00
|
|
|
" For when you forget to sudo.. Really Write the file.
|
|
|
|
cmap w!! w !sudo tee % >/dev/null
|
|
|
|
|
|
|
|
" TODO create function to generate tags for gemset and append a path to
|
|
|
|
" current tags that represents that gemset.
|
|
|
|
set tags=tmp/tags;/,./tmp/tags;/,tags;/,./tags;/
|
|
|
|
|
2010-12-22 00:14:07 +11:00
|
|
|
" If the parameter is a directory, cd into it
|
2011-02-09 00:42:20 +11:00
|
|
|
function! s:CdIfDirectory(directory)
|
2010-12-22 00:14:07 +11:00
|
|
|
let explicitDirectory = isdirectory(a:directory)
|
|
|
|
let directory = explicitDirectory || empty(a:directory)
|
|
|
|
|
|
|
|
if explicitDirectory
|
2011-02-18 12:45:40 +11:00
|
|
|
exe "ChangeDirectory " . a:directory
|
2010-12-22 00:14:07 +11:00
|
|
|
endif
|
|
|
|
|
|
|
|
if directory
|
|
|
|
NERDTree
|
|
|
|
wincmd p
|
|
|
|
bd
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" NERDTree utility function
|
2011-02-09 00:42:20 +11:00
|
|
|
function! s:UpdateNERDTree(...)
|
2010-12-22 00:14:07 +11:00
|
|
|
let stay = 0
|
|
|
|
|
|
|
|
if(exists("a:1"))
|
|
|
|
let stay = a:1
|
|
|
|
end
|
|
|
|
|
|
|
|
if exists("t:NERDTreeBufName")
|
|
|
|
let nr = bufwinnr(t:NERDTreeBufName)
|
|
|
|
if nr != -1
|
|
|
|
exe nr . "wincmd w"
|
|
|
|
exe substitute(mapcheck("R"), "<CR>", "", "")
|
|
|
|
if !stay
|
|
|
|
wincmd p
|
|
|
|
end
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists("CommandTFlush")
|
|
|
|
CommandTFlush
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Utility functions to create file commands
|
2011-02-09 00:42:20 +11:00
|
|
|
function! s:CommandCabbr(abbreviation, expansion)
|
2010-12-22 00:14:07 +11:00
|
|
|
execute 'cabbrev ' . a:abbreviation . ' <c-r>=getcmdpos() == 1 && getcmdtype() == ":" ? "' . a:expansion . '" : "' . a:abbreviation . '"<CR>'
|
|
|
|
endfunction
|
|
|
|
|
2011-02-09 00:42:20 +11:00
|
|
|
function! s:FileCommand(name, ...)
|
2010-12-22 00:14:07 +11:00
|
|
|
if exists("a:1")
|
|
|
|
let funcname = a:1
|
|
|
|
else
|
|
|
|
let funcname = a:name
|
|
|
|
endif
|
|
|
|
|
2011-02-09 00:42:20 +11:00
|
|
|
execute 'command! -nargs=1 -complete=file ' . a:name . ' :call ' . funcname . '(<f-args>)'
|
2010-12-22 00:14:07 +11:00
|
|
|
endfunction
|
|
|
|
|
2011-02-09 00:42:20 +11:00
|
|
|
function! s:DefineCommand(name, destination)
|
2010-12-22 00:14:07 +11:00
|
|
|
call s:FileCommand(a:destination)
|
|
|
|
call s:CommandCabbr(a:name, a:destination)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Public NERDTree-aware versions of builtin functions
|
2011-02-09 00:42:20 +11:00
|
|
|
function! ChangeDirectory(dir, ...)
|
2010-12-22 00:14:07 +11:00
|
|
|
execute "cd " . a:dir
|
|
|
|
let stay = exists("a:1") ? a:1 : 1
|
|
|
|
|
|
|
|
NERDTree
|
|
|
|
|
2011-03-24 16:28:27 +11:00
|
|
|
wincmd l
|
|
|
|
"if !stay
|
|
|
|
"wincmd p
|
|
|
|
"endif
|
2010-12-22 00:14:07 +11:00
|
|
|
endfunction
|
|
|
|
|
2011-02-09 00:42:20 +11:00
|
|
|
function! Touch(file)
|
2010-12-22 00:14:07 +11:00
|
|
|
execute "!touch " . a:file
|
|
|
|
call s:UpdateNERDTree()
|
|
|
|
endfunction
|
|
|
|
|
2011-02-09 00:42:20 +11:00
|
|
|
function! Remove(file)
|
2010-12-22 00:14:07 +11:00
|
|
|
let current_path = expand("%")
|
|
|
|
let removed_path = fnamemodify(a:file, ":p")
|
|
|
|
|
|
|
|
if (current_path == removed_path) && (getbufvar("%", "&modified"))
|
|
|
|
echo "You are trying to remove the file you are editing. Please close the buffer first."
|
|
|
|
else
|
|
|
|
execute "!rm " . a:file
|
|
|
|
endif
|
|
|
|
|
|
|
|
call s:UpdateNERDTree()
|
|
|
|
endfunction
|
|
|
|
|
2011-02-09 00:42:20 +11:00
|
|
|
function! Edit(file)
|
2010-12-22 00:14:07 +11:00
|
|
|
if exists("b:NERDTreeRoot")
|
|
|
|
wincmd p
|
|
|
|
endif
|
|
|
|
|
|
|
|
execute "e " . a:file
|
|
|
|
|
|
|
|
ruby << RUBY
|
|
|
|
destination = File.expand_path(VIM.evaluate(%{system("dirname " . a:file)}))
|
|
|
|
pwd = File.expand_path(Dir.pwd)
|
|
|
|
home = pwd == File.expand_path("~")
|
|
|
|
|
|
|
|
if home || Regexp.new("^" + Regexp.escape(pwd)) !~ destination
|
|
|
|
VIM.command(%{call ChangeDirectory(system("dirname " . a:file), 0)})
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Define the NERDTree-aware aliases
|
|
|
|
call s:DefineCommand("cd", "ChangeDirectory")
|
|
|
|
call s:DefineCommand("touch", "Touch")
|
|
|
|
call s:DefineCommand("rm", "Remove")
|
|
|
|
call s:DefineCommand("e", "Edit")
|
|
|
|
|
|
|
|
" This helps with RVM etc
|
2011-02-21 15:50:23 +11:00
|
|
|
set shell=zsh
|
2010-12-22 00:14:07 +11:00
|
|
|
|
2010-12-06 13:06:09 +11:00
|
|
|
" CTags
|
|
|
|
map <Leader>rt :!ctags --extra=+f -R *<CR><CR>
|
|
|
|
|
|
|
|
" Remember last location in file
|
|
|
|
if has("autocmd")
|
2011-02-09 00:42:20 +11:00
|
|
|
au! BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
|
2010-12-06 13:06:09 +11:00
|
|
|
\| exe "normal g'\"" | endif
|
|
|
|
endif
|
|
|
|
|
2011-02-09 00:42:20 +11:00
|
|
|
function! s:setupWrapping()
|
2010-12-06 13:06:09 +11:00
|
|
|
set wrap
|
|
|
|
set wm=2
|
|
|
|
set textwidth=72
|
|
|
|
endfunction
|
|
|
|
|
2011-02-09 00:42:20 +11:00
|
|
|
function! s:setupMarkup()
|
2010-12-06 13:06:09 +11:00
|
|
|
call s:setupWrapping()
|
|
|
|
map <buffer> <Leader>p :Mm <CR>
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" make and python use real tabs
|
2011-03-24 16:28:27 +11:00
|
|
|
au! FileType make set noexpandtab
|
|
|
|
au! FileType python set noexpandtab
|
|
|
|
|
|
|
|
au! FileType scss syntax cluster sassCssAttributes add=@cssColors
|
2010-12-06 13:06:09 +11:00
|
|
|
|
|
|
|
" Thorfile, Rakefile and Gemfile are Ruby
|
2011-02-09 00:42:20 +11:00
|
|
|
au! BufRead,BufNewFile {Gemfile,Rakefile,Thorfile,config.ru} set ft=ruby
|
2010-12-06 13:06:09 +11:00
|
|
|
|
2011-02-21 15:56:13 +11:00
|
|
|
au! BufRead,BufNewFile gitconfig set ft=gitconfig
|
|
|
|
|
2010-12-06 13:06:09 +11:00
|
|
|
" md, markdown, and mk are markdown and define buffer-local preview
|
2011-02-09 00:42:20 +11:00
|
|
|
au! BufRead,BufNewFile *.{md,markdown,mdown,mkd,mkdn} call s:setupMarkup()
|
2010-12-06 13:06:09 +11:00
|
|
|
|
2011-02-09 00:42:20 +11:00
|
|
|
au! BufRead,BufNewFile *.txt call s:setupWrapping()
|
2010-12-06 13:06:09 +11:00
|
|
|
|
2011-03-24 16:28:27 +11:00
|
|
|
cmap <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
|
|
|
|
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
|
|
|
|
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
|
|
|
|
|
2010-12-06 13:06:09 +11:00
|
|
|
" allow backspacing over everything in insert mode
|
|
|
|
set backspace=indent,eol,start
|
2010-11-24 17:43:17 +11:00
|
|
|
|
2010-12-22 00:14:07 +11:00
|
|
|
" Opens an edit command with the path of the currently edited file filled in
|
|
|
|
" Normal mode: <Leader>e
|
|
|
|
map <Leader>e :e <C-R>=expand("%:p:h") . "/" <CR>
|
2010-11-24 17:43:17 +11:00
|
|
|
|
|
|
|
" Nicer split controls
|
2010-12-22 00:36:30 +11:00
|
|
|
map <C-_> :split<CR>
|
|
|
|
map <C-\> :vsplit<CR>
|
2010-11-24 17:43:17 +11:00
|
|
|
|
2010-11-24 18:37:37 +11:00
|
|
|
" Emacs-like keys for the command line
|
|
|
|
cnoremap <C-A> <Home>
|
|
|
|
cnoremap <C-E> <End>
|
|
|
|
cnoremap <C-K> <C-U>
|
|
|
|
|
2010-11-24 18:38:01 +11:00
|
|
|
set wildignore+=Transmission*Remote*GUI
|
2010-11-24 18:37:37 +11:00
|
|
|
|
2010-12-22 00:14:07 +11:00
|
|
|
let g:ragtag_global_maps = 1
|
2010-11-30 01:03:50 +11:00
|
|
|
|
2011-02-21 15:49:31 +11:00
|
|
|
" persistent undos
|
|
|
|
|
|
|
|
set undodir=~/.vim/undos
|
|
|
|
set undofile
|
|
|
|
|
2010-12-22 00:14:07 +11:00
|
|
|
"Directories for swp files
|
2011-02-21 15:49:31 +11:00
|
|
|
set backupdir=~/.vim/dirs/backups
|
|
|
|
set undodir=~/.vim/dirs/undos
|
|
|
|
set directory=~/.vim/dirs/swaps
|
2010-12-22 00:14:07 +11:00
|
|
|
|
2011-03-24 16:28:27 +11:00
|
|
|
" To HTML
|
|
|
|
let html_number_lines = 0
|
|
|
|
let use_xhtml = 1
|
|
|
|
let html_use_css = 1
|
|
|
|
|
2011-02-09 00:43:56 +11:00
|
|
|
" Strip trailing whitespace
|
|
|
|
function! <SID>StripTrailingWhitespaces()
|
|
|
|
" Preparation: save last search, and cursor position.
|
|
|
|
let _s=@/
|
|
|
|
let l = line(".")
|
|
|
|
let c = col(".")
|
|
|
|
" Do the business:
|
|
|
|
%s/\s\+$//e
|
|
|
|
" Clean up: restore previous search history, and cursor position
|
|
|
|
let @/=_s
|
|
|
|
call cursor(l, c)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
autocmd! BufWritePre * :call <SID>StripTrailingWhitespaces()
|
|
|
|
|
2011-01-15 16:32:50 +11:00
|
|
|
" Align cucumber tables
|
|
|
|
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
|
|
|
|
|
|
|
|
function! s:align()
|
|
|
|
let p = '^\s*|\s.*\s|\s*$'
|
|
|
|
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
|
|
|
|
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
|
|
|
|
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
|
|
|
|
Tabularize/|/l1
|
|
|
|
normal! 0
|
|
|
|
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2011-02-21 15:56:13 +11:00
|
|
|
autocmd! FocusLost * :up
|
2011-02-18 12:45:40 +11:00
|
|
|
|
2011-01-15 16:32:50 +11:00
|
|
|
" Prevents '<Plug>DiscretionaryEnd' being inserted when pressing <Enter> in
|
|
|
|
" insert mode on new files. Blame SuperTab
|
|
|
|
let g:SuperTabCrMapping = 0
|
|
|
|
let g:SuperTabDefaultCompletionType = "context"
|
2010-12-22 00:14:07 +11:00
|
|
|
|
2011-02-08 22:24:35 +11:00
|
|
|
|
|
|
|
" vim wiki
|
|
|
|
let g:vimwiki_hl_cb_checked = 1
|
|
|
|
let g:vimwiki_menu = 'Plugin.Vimwiki'
|
|
|
|
let g:vimwiki_badsyms = ' '
|
|
|
|
let g:vimwiki_use_mouse = 1
|
|
|
|
let g:vimwiki_dir_link = 'index'
|
|
|
|
let g:vimwiki_list = [
|
|
|
|
\ {
|
|
|
|
\ 'path': '~/Dropbox/Wiki/Text',
|
|
|
|
\ 'path_html': '~/Dropbox/Wiki/HTML',
|
|
|
|
\ 'nested_syntaxes': {
|
|
|
|
\ 'ruby': 'ruby'
|
|
|
|
\ }
|
|
|
|
\ }
|
|
|
|
\]
|
|
|
|
|
2011-02-09 00:44:55 +11:00
|
|
|
" Command-T
|
|
|
|
let g:CommandTMaxFiles = 20000
|
|
|
|
let g:CommandTMaxHeight = 10
|
|
|
|
|
|
|
|
" Syntastic
|
|
|
|
let g:syntastic_enable_signs = 1
|
|
|
|
let g:syntastic_auto_loc_list = 0
|
|
|
|
|
|
|
|
" Indent Guides
|
2011-02-18 12:45:40 +11:00
|
|
|
let g:indent_guides_color_change_percent = 7
|
|
|
|
autocmd! VimEnter * IndentGuidesEnable
|
|
|
|
|
|
|
|
" snipMate config
|
|
|
|
let g:snips_author = 'Bodaniel Jeanes'
|
2011-02-09 00:44:55 +11:00
|
|
|
|
2011-02-08 22:24:35 +11:00
|
|
|
" Disable arrow keys
|
|
|
|
nnoremap <up> <nop>
|
|
|
|
nnoremap <down> <nop>
|
|
|
|
nnoremap <left> <nop>
|
|
|
|
nnoremap <right> <nop>
|
|
|
|
inoremap <up> <nop>
|
|
|
|
inoremap <down> <nop>
|
|
|
|
inoremap <left> <nop>
|
|
|
|
inoremap <right> <nop>
|
|
|
|
|
2011-02-18 12:45:40 +11:00
|
|
|
" Easy window management
|
|
|
|
map <C-h> <C-w>h
|
|
|
|
map <C-k> <C-w>k
|
|
|
|
map <C-j> <C-w>j
|
|
|
|
map <C-l> <C-w>l
|
|
|
|
|
2011-02-09 00:42:20 +11:00
|
|
|
" Source vimrc after saving it
|
|
|
|
autocmd! BufWritePost .vimrc,vimrc source $MYVIMRC | NERDTreeToggle | NERDTreeToggle
|
2011-02-18 12:45:40 +11:00
|
|
|
|
|
|
|
" Quick editing of common dot-files
|
2011-02-09 00:42:20 +11:00
|
|
|
map <Leader>vv :edit $MYVIMRC<CR>
|
|
|
|
map <Leader>gg :edit $MYGVIMRC<CR>
|
2011-02-18 12:45:40 +11:00
|
|
|
map <Leader>.. :ChangeDirectory ~/.config<CR>:wincmd l<CR>:enew<CR>
|
2011-02-09 00:42:20 +11:00
|
|
|
|
2011-01-15 16:32:50 +11:00
|
|
|
if filereadable(expand('~/.vimrc.local'))
|
|
|
|
source ~/.vimrc.local
|
|
|
|
endif
|
2011-02-09 00:42:20 +11:00
|
|
|
|