Automatically reload (g)vimrc when saved, and add shortcut for opening (g)vimrc files for editing

pull/2/head
Bodaniel Jeanes 2011-02-08 23:42:20 +10:00
parent cd3fdf5480
commit a2d0d21d24
2 changed files with 35 additions and 21 deletions

View File

@ -22,3 +22,8 @@ if has("gui_macvim")
map <D-t> :CommandT<CR> map <D-t> :CommandT<CR>
imap <D-t> <Esc>:CommandT<CR> imap <D-t> <Esc>:CommandT<CR>
end end
" Source vimrc after saving it
autocmd! BufWritePost .gvimrc,gvimrc source $MYGVIMRC
autocmd! BufWritePost .vimrc,vimrc source $MYVIMRC | source $MYGVIMRC | NERDTreeToggle | NERDTreeToggle

View File

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