--- /dev/null
+"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
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 ----
let mapleader = ";"
let g:mapleader = ";"
+" ---- Quick Save ----
+map <Leader>w :w<CR>
+
" ---- Toggle Fold ----
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
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
"==============================================================================
" 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
"==============================================================================
" 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