From: Mike D. Lowis Date: Fri, 17 Feb 2012 18:54:39 +0000 (-0500) Subject: Updated vimrc to support project.vim files X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=c47b183c317774b62d09bf9170ebec16961aabf0;p=archive%2Fvim_config.git Updated vimrc to support project.vim files --- diff --git a/plugin/kwbd.vim b/plugin/kwbd.vim new file mode 100644 index 0000000..3c5bd64 --- /dev/null +++ b/plugin/kwbd.vim @@ -0,0 +1,64 @@ +"here is a more exotic version of my original Kwbd script +"delete the buffer; keep windows; create a scratch buffer if no buffers left +function s:Kwbd(kwbdStage) + if(a:kwbdStage == 1) + if(!buflisted(winbufnr(0))) + bd! + return + endif + let s:kwbdBufNum = bufnr("%") + let s:kwbdWinNum = winnr() + windo call s:Kwbd(2) + execute s:kwbdWinNum . 'wincmd w' + let s:buflistedLeft = 0 + let s:bufFinalJump = 0 + let l:nBufs = bufnr("$") + let l:i = 1 + while(l:i <= l:nBufs) + if(l:i != s:kwbdBufNum) + if(buflisted(l:i)) + let s:buflistedLeft = s:buflistedLeft + 1 + else + if(bufexists(l:i) && !strlen(bufname(l:i)) && !s:bufFinalJump) + let s:bufFinalJump = l:i + endif + endif + endif + let l:i = l:i + 1 + endwhile + if(!s:buflistedLeft) + if(s:bufFinalJump) + windo if(buflisted(winbufnr(0))) | execute "b! " . s:bufFinalJump | endif + else + enew + let l:newBuf = bufnr("%") + windo if(buflisted(winbufnr(0))) | execute "b! " . l:newBuf | endif + endif + execute s:kwbdWinNum . 'wincmd w' + endif + if(buflisted(s:kwbdBufNum) || s:kwbdBufNum == bufnr("%")) + execute "bd! " . s:kwbdBufNum + endif + if(!s:buflistedLeft) + set buflisted + set bufhidden=delete + set buftype=nofile + setlocal noswapfile + endif + else + if(bufnr("%") == s:kwbdBufNum) + let prevbufvar = bufnr("#") + if(prevbufvar > 0 && buflisted(prevbufvar) && prevbufvar != s:kwbdBufNum) + b # + else + bn + endif + endif + endif +endfunction + +command! Kwbd call Kwbd(1) +nnoremap Kwbd :Kwbd + +" Create a mapping (e.g. in your .vimrc) like this: +"nmap ! Kwbd diff --git a/vimrc b/vimrc index c5a0cba..9d6facf 100644 --- a/vimrc +++ b/vimrc @@ -43,30 +43,31 @@ set tags=tags;/ " Search from current directory to root for cta set fileformats=unix,dos,mac " support all three, in this order set list " Show control and whitespace characters (tabs, spaces, etc.) set listchars=tab:>-,trail:- " Show only trailing spaces and tabs -setlocal spell spelllang=en_us " Turn on spell checking set lazyredraw " Don't redraw unless we need to -"set cursorline " Highlights current line -"set textwidth=79 " Wrap to next line if the next character is at the margin +set formatoptions+=r " Enable continuation of comments after a newline "============================================================================== " Function and Command Definitions "============================================================================== -function! LoadCscope() - let db = findfile("cscope.out", ".;") - if (!empty(db)) - let path = strpart(db, 0, match(db, "[\\\/]cscope.out$")) - set nocscopeverbose " suppress 'duplicate connection' error - exe "cs add " . db . " " . path - set cscopeverbose - endif +function! LoadProject() + let proj = findfile("project.vim", ".;") + let path = strpart(proj, 0, match(proj, "[\\\/]project.vim$")) + + if (!empty(path)) + silent! exec "cd " . path + endif + + if (!empty(proj)) + exec "source " . proj + endif endfunction -function! SwitchToProjectDir() - let db = findfile("rakefile.rb", ".;") - if (!empty(db)) - let path = strpart(db, 0, match(db, "[\\\/]rakefile.rb$")) - exec "cd " . path - endif +function! ReformatWhiteSpace() + if &modifiable + retab + silent! exec("%s/\\s\\+$//") + exec("=") + endif endfunction " ---- ToFn - Converts a group of C function prototypes to definitions ---- @@ -79,6 +80,9 @@ command! -range=% -nargs=0 ToFn execute ",s/;/\r{\r\r}\r/" let mapleader = ";" let g:mapleader = ";" +" ---- Quick Save ---- +map w :w + " ---- Toggle Fold ---- map zz za @@ -86,17 +90,22 @@ map zz za vnoremap < >gv -" ---- Tab Triggers Omni Complete ---- -inoremap -inoremap +" ---- Clear Search Highlighting ---- +map h :nohl + +" ---- Omni Complete ---- +inoremap + +" ---- Nerd Tree Toggle ---- +map t :NERDTreeToggle " ---- Buffer Management ---- map :bp imap :bp map :bn imap :bn -map d :bd -imap d :bd +map d :Kwbd +imap d :Kwbd " ---- Working With Windows ---- map h @@ -105,7 +114,7 @@ map k map l map c map :vs -map :split +map :split " ---- Moving Lines Around ---- nmap ddp @@ -126,12 +135,14 @@ map fi :cs find i "============================================================================== " Abbreviations "============================================================================== +" Normal mode abbreviations abbreviate inc #include abbreviate def #define +abbreviate ifdef #ifdef#endif abbreviate ifndef #ifndef#endif abbreviate prf printf(""); - +" Command mode abbreviations cnoreabbrev trim %s/\s\+$// cnoreabbrev print hardcopy cnoreabbrev tofn ToFn @@ -142,17 +153,11 @@ cnoreabbrev ff "============================================================================== " Auto Commands "============================================================================== -" Auto locate and connect to cscope db. -au BufEnter * call SwitchToProjectDir() - -" Auto locate and connect to cscope db. -au BufEnter * call LoadCscope() - -" Replace all tabs with spaces -au BufEnter * retab +" Auto locate and load project specific settings +autocmd BufEnter * call LoadProject() -" Trim any trailing whitespace -au BufEnter * silent! exec("%s/\\s\\+$//") +" Reformat the whitespace to remove tabs and trailing space +autocmd BufWritePre * call ReformatWhiteSpace() "============================================================================== " GVim