]> git.mdlowis.com Git - archive/vim_config.git/commitdiff
Updated vimrc to support project.vim files
authorMike D. Lowis <mike@mdlowis.com>
Fri, 17 Feb 2012 18:54:39 +0000 (13:54 -0500)
committerMike D. Lowis <mike@mdlowis.com>
Fri, 17 Feb 2012 18:54:39 +0000 (13:54 -0500)
plugin/kwbd.vim [new file with mode: 0644]
vimrc

diff --git a/plugin/kwbd.vim b/plugin/kwbd.vim
new file mode 100644 (file)
index 0000000..3c5bd64
--- /dev/null
@@ -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 <SID>Kwbd(1)
+nnoremap <silent> <Plug>Kwbd :<C-u>Kwbd<CR>
+
+" Create a mapping (e.g. in your .vimrc) like this:
+"nmap <C-W>! <Plug>Kwbd
diff --git a/vimrc b/vimrc
index c5a0cba84b2458207fe10367e274faadb79d2654..9d6facfd4db8dbd0800c18690e54f5a83e7caab7 100644 (file)
--- 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 "<line1>,<line2>s/;/\r{\r\r}\r/"
 let mapleader = ";"
 let g:mapleader = ";"
 
+" ---- Quick Save ----
+map <Leader>w :w<CR>
+
 " ---- Toggle Fold ----
 map  zz <ESC>za
 
@@ -86,17 +90,22 @@ map  zz <ESC>za
 vnoremap < <gv
 vnoremap > >gv
 
-" ---- Tab Triggers Omni Complete ----
-inoremap <tab> <C-n>
-inoremap <S-tab> <C-p>
+" ---- Clear Search Highlighting ----
+map <Leader>h :nohl<CR>
+
+" ---- Omni Complete ----
+inoremap <S-tab> <C-n>
+
+" ---- Nerd Tree Toggle ----
+map <Leader>t :NERDTreeToggle<CR>
 
 " ---- Buffer Management ----
 map  <C-S-tab>  :bp<CR>
 imap <C-S-tab>  <ESC>:bp<CR>
 map  <C-tab>    :bn<CR>
 imap <C-tab>    <ESC>:bn<CR>
-map  <Leader>d  :bd<CR>
-imap <Leader>d  <ESC>:bd<CR>
+map  <Leader>d  :Kwbd<CR>
+imap <Leader>d  <ESC>:Kwbd<CR>
 
 " ---- Working With Windows ----
 map <M-h> <C-w>h
@@ -105,7 +114,7 @@ map <M-k> <C-w>k
 map <M-l> <C-w>l
 map <M-c> <C-w>c
 map <M-v> :vs<CR>
-map <M-h> :split<CR>
+map <M-s> :split<CR>
 
 " ---- Moving Lines Around ----
 nmap <C-j> ddp
@@ -126,12 +135,14 @@ map <Leader>fi :cs find i <cword><CR>
 "==============================================================================
 " Abbreviations
 "==============================================================================
+" Normal mode abbreviations
 abbreviate inc #include
 abbreviate def #define
+abbreviate ifdef #ifdef<CR>#endif<up><END>
 abbreviate ifndef #ifndef<CR>#endif<up><END>
 abbreviate prf printf("");<left><left><left>
 
-
+" Command mode abbreviations
 cnoreabbrev trim %s/\s\+$//
 cnoreabbrev print hardcopy
 cnoreabbrev tofn ToFn
@@ -142,17 +153,11 @@ cnoreabbrev <expr> 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