diff --git a/vim/gvimrc b/vim/gvimrc index 02c15cd..d48b920 100644 --- a/vim/gvimrc +++ b/vim/gvimrc @@ -22,3 +22,8 @@ if has("gui_macvim") map :CommandT imap :CommandT end + +" Source vimrc after saving it +autocmd! BufWritePost .gvimrc,gvimrc source $MYGVIMRC +autocmd! BufWritePost .vimrc,vimrc source $MYVIMRC | source $MYGVIMRC | NERDTreeToggle | NERDTreeToggle + diff --git a/vim/vimrc b/vim/vimrc index 4f9f0a9..4cc9078 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -1,9 +1,9 @@ set nocompatible -runtime macros/matchit.vim +runtime! macros/matchit.vim " Pathogen setup -runtime! autoload/pathogen.vim +runtime autoload/pathogen.vim if exists('g:loaded_pathogen') filetype off @@ -50,11 +50,14 @@ let NERDTreeIgnore=['\.rbc$', '\~$'] map n :NERDTreeToggle " Project Tree -autocmd VimEnter * call s:CdIfDirectory(expand("")) +autocmd! VimEnter * call s:CdIfDirectory(expand("")) +" Reselect visual block after adjusting indentation +vnoremap < >gv " If the parameter is a directory, cd into it -function s:CdIfDirectory(directory) +function! s:CdIfDirectory(directory) let explicitDirectory = isdirectory(a:directory) let directory = explicitDirectory || empty(a:directory) @@ -70,7 +73,7 @@ function s:CdIfDirectory(directory) endfunction " NERDTree utility function -function s:UpdateNERDTree(...) +function! s:UpdateNERDTree(...) let stay = 0 if(exists("a:1")) @@ -94,27 +97,27 @@ function s:UpdateNERDTree(...) endfunction " Utility functions to create file commands -function s:CommandCabbr(abbreviation, expansion) +function! s:CommandCabbr(abbreviation, expansion) execute 'cabbrev ' . a:abbreviation . ' =getcmdpos() == 1 && getcmdtype() == ":" ? "' . a:expansion . '" : "' . a:abbreviation . '"' endfunction -function s:FileCommand(name, ...) +function! s:FileCommand(name, ...) if exists("a:1") let funcname = a:1 else let funcname = a:name endif - execute 'command -nargs=1 -complete=file ' . a:name . ' :call ' . funcname . '()' + execute 'command! -nargs=1 -complete=file ' . a:name . ' :call ' . funcname . '()' endfunction -function s:DefineCommand(name, destination) +function! s:DefineCommand(name, destination) call s:FileCommand(a:destination) call s:CommandCabbr(a:name, a:destination) endfunction " Public NERDTree-aware versions of builtin functions -function ChangeDirectory(dir, ...) +function! ChangeDirectory(dir, ...) execute "cd " . a:dir let stay = exists("a:1") ? a:1 : 1 @@ -125,12 +128,12 @@ function ChangeDirectory(dir, ...) endif endfunction -function Touch(file) +function! Touch(file) execute "!touch " . a:file call s:UpdateNERDTree() endfunction -function Remove(file) +function! Remove(file) let current_path = expand("%") let removed_path = fnamemodify(a:file, ":p") @@ -143,7 +146,7 @@ function Remove(file) call s:UpdateNERDTree() endfunction -function Edit(file) +function! Edit(file) if exists("b:NERDTreeRoot") wincmd p endif @@ -175,32 +178,32 @@ map rt :!ctags --extra=+f -R * " Remember last location in file if has("autocmd") - au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") + au! BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") \| exe "normal g'\"" | endif endif -function s:setupWrapping() +function! s:setupWrapping() set wrap set wm=2 set textwidth=72 endfunction -function s:setupMarkup() +function! s:setupMarkup() call s:setupWrapping() map p :Mm endfunction " make and python use real tabs -au FileType make set noexpandtab -au FileType python set noexpandtab +au! FileType make set noexpandtab +au! FileType python set noexpandtab " Thorfile, Rakefile and Gemfile are Ruby -au BufRead,BufNewFile {Gemfile,Rakefile,Thorfile,config.ru} set ft=ruby +au! BufRead,BufNewFile {Gemfile,Rakefile,Thorfile,config.ru} set ft=ruby " md, markdown, and mk are markdown and define buffer-local preview -au BufRead,BufNewFile *.{md,markdown,mdown,mkd,mkdn} call s:setupMarkup() +au! BufRead,BufNewFile *.{md,markdown,mdown,mkd,mkdn} call s:setupMarkup() -au BufRead,BufNewFile *.txt call s:setupWrapping() +au! BufRead,BufNewFile *.txt call s:setupWrapping() " allow backspacing over everything in insert mode set backspace=indent,eol,start @@ -289,6 +292,12 @@ inoremap inoremap inoremap +" Source vimrc after saving it +autocmd! BufWritePost .vimrc,vimrc source $MYVIMRC | NERDTreeToggle | NERDTreeToggle +map vv :edit $MYVIMRC +map gg :edit $MYGVIMRC + if filereadable(expand('~/.vimrc.local')) source ~/.vimrc.local endif +