mirror of https://github.com/bjeanes/dotfiles.git
Automatically reload (g)vimrc when saved, and add shortcut for opening (g)vimrc files for editing
parent
cd3fdf5480
commit
a2d0d21d24
|
@ -22,3 +22,8 @@ if has("gui_macvim")
|
|||
map <D-t> :CommandT<CR>
|
||||
imap <D-t> <Esc>:CommandT<CR>
|
||||
end
|
||||
|
||||
" Source vimrc after saving it
|
||||
autocmd! BufWritePost .gvimrc,gvimrc source $MYGVIMRC
|
||||
autocmd! BufWritePost .vimrc,vimrc source $MYVIMRC | source $MYGVIMRC | NERDTreeToggle | NERDTreeToggle
|
||||
|
||||
|
|
51
vim/vimrc
51
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 <Leader>n :NERDTreeToggle<CR>
|
||||
|
||||
" 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
|
||||
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 . ' <c-r>=getcmdpos() == 1 && getcmdtype() == ":" ? "' . a:expansion . '" : "' . a:abbreviation . '"<CR>'
|
||||
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 . '(<f-args>)'
|
||||
execute 'command! -nargs=1 -complete=file ' . a:name . ' :call ' . funcname . '(<f-args>)'
|
||||
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 <Leader>rt :!ctags --extra=+f -R *<CR><CR>
|
|||
|
||||
" 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 <buffer> <Leader>p :Mm <CR>
|
||||
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 <down> <nop>
|
|||
inoremap <left> <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'))
|
||||
source ~/.vimrc.local
|
||||
endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue