~ jmcantrell /.vimrc

" Options {{{

" Run in vim compatible mode (newer options and behavior).
set nocompatible
" Set color scheme (mine is a slight variation of default)
colorscheme mine
" Enable coloring for dark background terminals.
set background=dark
" Enable syntax highlighting and coloring.
syntax enable
" Enable filetype detection, plugins, and indention.
filetype plugin indent on
" Source filetype plugins.
" The ! indicates sourcing all vs just the 1st found.
runtime! ftdetect/*.vim
" Set grep to always display the filename.
set grepprg=grep\ -nH\ $*
" On win32, use shellslash
set shellslash
" Begin searching while typing.
set incsearch
" Ignore case while searching.
set ignorecase
" Use intelligent case while searching.
" If search string contains an upper case letter, disable ignorecase.
set smartcase
" Insert spaces for tabs according to shiftwidth.
set smarttab
" Use indent from current line when starting a new one.
set autoindent
" Use smart indenting when starting a new line.
set smartindent
" Don't use c style indenting.
set nocindent
" Highlight search results in buffer.
set hlsearch
" Expand tabs to spaces.
set expandtab
" Number of spaces that a tab counts for.
set tabstop=4
" Number of spaces to use for each step of indent.
set shiftwidth=4
" Allow backspace over ...
set backspace=indent,eol,start
" Strings to use in list mode.
set listchars=tab:>-,extends:>,precedes:<,trail:-,nbsp:%,eol:$
" Break lines at the nearest word boundary.
set linebreak
" Enable line wrapping.
set wrap
" When closing a block, show the matching bracket.
set showmatch
" Include angle brackets in matching.
set matchpairs+=<:>
" Do not redraw the screen while macros are running.
set lazyredraw
" Backup files.
set backup
" ... and back them up here (1st one that exists, wins).
set backupdir=~/.vim/backup,.
" Save files before performing certain actions.
set autowrite
" Show current mode in the status line.
set showmode
" Show the command in the status line.
set showcmd
" Start scrolling at this number of lines from the bottom.
set scrolloff=2
" Start scrolling horizontally at this number of columns.
set sidescrolloff=5
" Status line takes up this many lines.
" Make the status line always visible.
set laststatus=2
" Always show the ruler.
set ruler
" Indicates a fast terminal connection.
set ttyfast
" Enables wildmenu tab completion.
set wildmenu
" Type of wildmenu.
set wildmode=longest:full,list:full
" Massively detailed viminfo file.
set viminfo='500,f1,:100,/100
" Look for embedded modelines at the top of the file.
set modeline
" Only look at this number of lines for modeline
set modelines=10
" Try to detect file formats.
" Unix for new files and autodetect for the rest.
set fileformats=unix,dos,mac
" Command history size.
set history=50
" Disable the splash screen (and some various tweaks for messages).
set shortmess=aTItoO
" Enable the mouse.
set mouse=a
" Hide the mouse while typing.
set mousehide
" Enable the popup menu.
set mousem=popup
" Split vertically to the right.
set splitright
" Split horizontally below.
set splitbelow
" Status line definition.
set statusline=[%n]\ %<%f%m%r\ %w\ %y\ \ <%{&fileformat}>%=[%o]\ %l,%c%V\/%L\ \ %P
" Set folding method.
" =marker means to use an embedded tag to define the fold boundaries.
set foldmethod=marker
" Disable the beeping.
set noerrorbells
" Set the terminal window title.
set title
" }}}
" -------------------------------------------------------------------
" Plugin settings {{{
let html_use_css=1
let use_xhtml=1

let autodate_keyword_pre='Last Modified: '
let autodate_keyword_post='$'
let autodate_format='%a %Y-%m-%d %H:%M:%S (%z)'

let g:EnhCommentifyBindInInsert = 'No'
let g:EnhCommentifyPretty = 'Yes'
let g:EnhCommentifyAlignRight = 'Yes'
let g:EnhCommentifyUserMode = 'Yes'

let Tlist_GainFocus_On_ToggleOpen = 1
let Tlist_Exit_OnlyWindow = 1
let Tlist_File_Fold_Auto_Close = 1
let Tlist_Sort_Type = 'name'
let Tlist_Enable_Fold_Column = 0
" }}}
" -------------------------------------------------------------------
" Autocommands {{{
if !exists("autocmds_loaded")
    let autocmds_loaded = 1

    " Jump to last known position in file.
    autocmd BufReadPost *
        \ if line("'\"") > 0 && line("'\"") <= line("$") |
        \     exe "normal g`\"" |
        \ endif

    " Warn when file has changed externally.
    autocmd FileChangedShell *
        \ echohl WarningMsg |
        \ echo "File has been changed outside of vim." |
        \ echohl None

    " Recognize *.txt as text files.
    autocmd BufRead,BufNewFile *.txt setfiletype text
    " I store sensitive data in *.secure.* files, so don't backup.
    autocmd BufRead,BufNewFile *.secure.* setlocal nobackup
    " Recognize *.otl as VimOutliner files.
    autocmd BufRead,BufNewFile *.otl setfiletype vo_base
endif
" }}}
" -------------------------------------------------------------------
" Key mappings {{{

" Help keys
nnoremap <F1> :help<Space>
vmap <F1> <C-C><F1>
omap <F1> <C-C><F1>
map! <F1> <C-C><F1>
" Select all.
nnoremap <F2> ggVG
" Toggle line wrapping
nnoremap <F3> :set wrap!<CR>
" Toggle line numbering.
nmap <silent> <C-F4> :set nu!<CR>
" Toggle paste mode.
nnoremap \pt :set invpaste paste?<CR>
nmap <F5> \pt
imap <F5> <C-O>\pt
set pastetoggle=<F5>
" Cycle panes (forward).
noremap <silent> <F6> <C-W>w
" Cycle panes (reverse).
noremap <silent> <S-F6> <C-W>W
" Tottle taglist
nnoremap <silent> <F7> :TlistToggle<CR>
" File Explorer
nnoremap <silent> <F8> :Explore<CR>
nnoremap <silent> <C-F8> :Vexplore<CR>
nnoremap <silent> <S-F8> :Hexplore<CR>
" Buffer Explorer
nnoremap <silent> <F9> :BufExplorer<CR>
nnoremap <silent> <C-F9> :VSBufExplorer<CR>
nnoremap <silent> <S-F9> :SBufExplorer<CR>
" Remove carriage returns (CR,\r).
map <C-F12> :call RmCR()<CR>

" Turn off search highlights.
nmap <silent> <C-n> :silent noh<CR>
" Toggle fold state.
noremap <space> :call ToggleFold()<CR>
" Yank to the EOL.
noremap Y y$
" Auto-complete (OnmiFunc)
imap <C-Space> <C-X><C-O>
" Insert timestamp
iab xstamp <C-R>=strftime("%a %Y-%m-%d %H:%M:%S (%z)")
" Insert last modified header
iab lastmod Last Modified: <C-R>=strftime("%a %Y-%m-%d %H:%M:%S (%z)")<Esc>

" Justify text (center,left,right).
noremap <silent> ,c :ce <CR> << <CR>
noremap <silent> ,l :le <CR>
noremap <silent> ,r :ri <CR>

" Paragraph (re)formatting.
nnoremap Q gqap
vnoremap Q gq

" Open new tab
nnoremap <silent> \tt :tabnew<CR>
" Cycle tabs (forward)
nnoremap <silent> \tn :tabnext<CR>
" Cycle tabs (reverse)
nnoremap <silent> \tp :tabprevious<CR>

" Cycle files (forward).
nnoremap <silent> \fn :next<CR>
" Cycle files (reverse).
nnoremap <silent> \fp :prev<CR>

" Increase indent.
vnoremap <C-T> >
vmap <Tab> <C-T>
" Decrease indent.
vnoremap <C-D> <LT>
vmap <S-Tab> <C-D>

" }}}
" -------------------------------------------------------------------
" Functions {{{
function! RmCR() "{{{
    let oldLine=line('.')
    exe ":%s/\r//g"
    exe ':' . oldLine
endfunction "}}}
fun! ToggleFold() " {{{
    if foldlevel('.') == 0
        normal! l
    else
        if foldclosed('.') < 0
            . foldclose
        else
            . foldopen
        endif
    endif
    " Clear status line
    echo
endfun " }}}
" }}}
" -------------------------------------------------------------------

" Windows specific stuff
if $OS == 'Windows_NT'
    " Make the GnuWin32 binaries available to Vim (more Unix-like)
    let $PATH='C:\Program Files\GetGnuWin32\gnuwin32\bin;'.$PATH
endif