samba /.vimrc

Work in progress. (Various pieces amassed from numerous other sources.) Intuitive tab and window controls, via [C-T] and [C-W] respectively. [C-T] [C-T] toggles tabs to the previously selected one. Code completion via omnicomplete and syntax completion: [C-O c] initiates omnicomplete, [C-U c] initiates 'user' syntax completion. Pretty colors and nicer status line. Lots of filetype sensitivity.
" Standard configuration options {{{
scriptencoding utf-8
" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim

" Syntax highlighting for vim5 and later if the terminal supports it
if has('syntax') && (&t_Co > 2)
  syntax on
endif

" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark

" Uncomment the following to have Vim jump to the last position when
" reopening a file
if has("autocmd")
  au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
    \| exe "normal g'\"" | endif
endif
" }}}
"{{{ Filetype Handling Features
" Uncomment the following to have Vim load indentation rules according to the
" detected filetype. Per default Debian Vim only load filetype specific
" plugins.
if has("autocmd")
  filetype plugin indent on
endif


"}}}
" Simple widely-compabitle options {{{ 
" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
set showcmd		" Show (partial) command in status line.
set matchtime=4         " matchtime: tenths of a second to show a match. 
set showmatch		" Show matching brackets.
set showfulltag		" Show full tags when doing search completion
set ignorecase		" Do case insensitive matching
set smartcase		" Do smart case matching - ignores 'ignorecase' when search text contains capitals
set incsearch		" Incremental search
set hlsearch		" Highlight search
set autowrite		" Automatically save before commands like :next and :make
set mouse=v		" a: [Enable mouse usage (all modes) in terminals]; v: [visual mode only]

" startofline: jump to first character of next line? No, keep column. 
set nostartofline 

"}}}

" Terminal settings {{{
" Extra terminal things
if (&term =~ "xterm") && (&termencoding == "")
    set termencoding=utf-8
endif

set title

if (&term =~ "xterm") || (&term =~ "gnome")
    " change cursor colour depending upon mode
    if exists('&t_SI')
        let &t_SI = "\]12;lightgoldenrod\x7"
        let &t_EI = "\]12;grey80\x7"
    endif
endif


" }}}
" Miscellaneous Function Key (F*) Shortcuts {{{
"" SHORTCUTS

nmap   :silent nohlsearch
imap   :silent nohlsearch
nmap  :Kwbd


" Toggle paste mode with F5
set pastetoggle= 		"pt:    useful so auto-indenting doesn't mess up code when pasting
" nmap  c

" Toggle hidden characters display (with F6)
map   :set nolist!:set nolist?


nmap  :make all-then-check
nmap  :exec "make -C " . expand("%:p:h") . " check"
nmap  :make
nmap  :exec "make -C " . expand("%:p:h")
" nmap  :!if [[ -d .svn ]] ; then svn update ; else svk update ; fi
" nmap  :!if [[ -d .svn ]] ; then svn status ; else svk status ; fi \| grep -v '^?' \| sort -k2



" }}}
" Additional filetype-specific behaviors {{{
if has("autocmd")
    " in human-language files, automatically format everything at 72 chars:
        au BufRead,BufNewFile *.txt setfiletype text
	autocmd FileType mail,human,text set formatoptions+=t textwidth=72 spell spelllang=en
         


	" Not sure why the cron filetype isn't catching this...
        au FileType crontab set backupcopy=yes

	" in makefiles, don't expand tabs to spaces, since actual tab characters are
	" needed, and have indentation at 8 chars to be sure that all indents are tabs
	" (despite the mappings later):
	autocmd FileType make set noexpandtab shiftwidth=8

        autocmd FileType python set omnifunc=pythoncomplete#Complete
        autocmd FileType ruby set omnifunc=rubycomplete#Complete
        autocmd FileType sql set omnifunc=sqlcomplete#Complete

        " Web languages (XHTML, CSS, etc) {{{
        " For standards-compliant :TOhtml output
        let html_number_lines=1
        let html_use_css=1
        let use_xhtml=1

        " (use :cn & :cp to jump between errors)
        au FileType xml,xslt compiler xmllint
        au FileType html compiler tidy
        autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags

        " for CSS, also have things in braces indented:
        autocmd FileType css set smartindent
        autocmd FileType css set omnifunc=csscomplete#CompleteCSS
  
        " for HTML, generally format text, but if a long line has been created leave it
        " alone when editing:
        autocmd FileType html set formatoptions+=tl
        autocmd FileType html set omnifunc=htmlcomplete#CompleteTags

        " for both CSS and HTML, use genuine tab characters for indentation, to make
        " files a few bytes smaller:
        autocmd FileType html,css set noexpandtab tabstop=2

        
        
        " }}}
	" C-like languages (including PHP, Javascript) {{{
	" for C-like programming, have automatic indentation:
	autocmd FileType c,cpp,slang set cindent
        
        autocmd FileType c,cpp 
                    \ ab cmain main(int argc, char **argv){  } |
                    \ ab cmmap mmap(NULL,st.st_size,PROT_READ,MAP_SHARED,fd,0);

	" for actual C (not C++) programming where comments have explicit end
	" characters, if starting a new line in the middle of a comment automatically
	" insert the comment leader characters:
	autocmd FileType c set formatoptions+=ro
        autocmd FileType c set omnifunc=ccomplete#Complete

        " for Perl programming, have things in braces indenting themselves:
	autocmd FileType perl,php,javascript set smartindent
        autocmd FileType php set omnifunc=phpcomplete#CompletePHP
        autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS

        " Perl specific options
       let perl_include_pod=1
       let perl_fold=1
       let perl_fold_blocks=1

 


        " }}}

" Generic completion of all syntax features
    autocmd FileType * set completefunc=syntaxcomplete#Complete	" automatic based on syntax highlighting

" {{{ Vim Help docs: hit enter to activate links, and backspace as a back button
    autocmd FileType help nmap   
    autocmd FileType help nmap   
"}}}
endif
"}}}
"{{{ Development Environment
        set number      " enable line numbering


" Code Folding {{{
" reference: http://varnit.wordpress.com/2007/10/23/vim-code-folding/

" The default fold color is too bright and looks too much like the statusline
hi Folded cterm=bold ctermfg=DarkBlue ctermbg=none
hi FoldColumn cterm=bold ctermfg=DarkBlue ctermbg=none

set fillchars+=fold:_

"" SHORTCUTS

" Spacebar toggles a fold, zi toggles all folding, zM closes all folds
nnoremap     :exe 'silent! normal! za'.(foldlevel('.')?'':'l')

" syntax isn't entirely reliable, as some syntax files don't include folding
"set foldmethod=syntax
set foldmethod=indent		" useful options: indent, marker, syntax, expr (determined by 'foldexpr')
set foldcolumn=4                "fdc:   creates a small left-hand gutter for displaying fold info

"}}}

"" SHORTCUTS
" User-dictionary completion (usually syntax completion)
imap c 
" Omnifunc completion (uses supplied omnifunc if available.)
imap c 

" inoremap  . MayComplete()
" func MayComplete()
"     if ()
"         return".\\"
"     endif
"     return '.'
" endfunc
" 
" Use cool tab-completion menu
set wildmenu
set wildignore+=*.o,*.obj,*~,.lo
set suffixes+=.in,.a

" Menu for omnifunc/autocomplete, etc
hi Pmenu cterm=none ctermfg=Green ctermbg=none
hi PmenuSel cterm=underline ctermfg=White ctermbg=none
hi PmenuSbar cterm=bold ctermfg=none ctermbg=DarkBlue
hi PmenuThumb cterm=bold ctermfg=none ctermbg=White

set pumheight=12

"}}}
" Navigation: Tabs {{{
" SHORTCUTS {{{
" Shortcut for Tab controls: Control-T - for some reason ths MUST be 'imap', and not 'inoremap'
imap  


" C-T n: new tab
noremap  n :tabnew
" C-T x: close tab
noremap  x :tabclose
" C-T o: close all other tabs
noremap  o :tabonly
" C-T f: edit the found file(s) in $path, in a new tab (like with :find)
noremap f :tabfind
" C-T m: move this tab (followed by a number, index of precedent)
noremap m :tabs:tabm
" C-T : got to tab specified
noremap  :tabnext
" next tab
noremap   :tabnext
" previous tab
noremap   :tabprevious
  
" Remember the last tab I was using...
let g:lasttab = 1   " default to the first tab, so it won't complain when there's only one.
autocmd TabLeave * let g:lasttab = tabpagenr()
noremap   :exe 'tabnext' (g:lasttab)
"}}}
" A nice, minimalistic tabline
hi TabLine cterm=underline ctermfg=LightBlue ctermbg=none
hi TabLineSel cterm=bold,underline ctermfg=White ctermbg=none
hi TabLineFill cterm=underline ctermfg=LightBlue ctermbg=none
set showtabline=1               "stal:  Display the tabbar if there are multiple tabs. Use :tab ball or invoke Vim with -p
" }}}
" Navigation: Windows {{{
"" SHORTCUTS"{{{
" Shortcut for Window controls: Control-W
" use  to cycle through split windows (and + to cycle backwards,
" where possible):
noremap   w
noremap   W


" Map C-W for easy switching (even in insert mode)
inoremap  


"}}}
set splitright                  "spr:   puts new vsplit windows to the right of the current
set splitbelow                  "sb:    puts new split windows to the bottom of the current

set winminheight=0              "wmh:   the minimal line height of any non-current window
set winminwidth=0               "wmw:   the minimal column width of any non-current window
" Window visuals {{{
hi VertSplit cterm=bold ctermfg=Grey ctermbg=none

" I like this better than all the reverse video of the default statusline.
hi StatusLine cterm=bold,underline ctermfg=White ctermbg=none
hi StatusLineNC cterm=underline ctermfg=DarkBlue ctermbg=none
hi User1 ctermfg=DarkRed
hi User2 ctermfg=DarkBlue
hi User3 ctermfg=DarkMagenta
hi User4 cterm=bold ctermfg=DarkGrey
hi User5 ctermfg=Brown
hi User6 ctermfg=DarkGreen
hi User7 ctermfg=DarkGreen
hi User8 cterm=bold ctermfg=DarkCyan
hi User9 cterm=bold ctermfg=DarkGrey ctermbg=Grey


"}}}

"  Window Status line structure {{{

" show - and = to indicate current window
" set fillchars+=stl:=,stlnc:_

" laststatus: show status line? Only if there are at least two windows.
set laststatus=2

" statusline: filename [type] (line:current/total) (column) (line:percent)[(changed)]
" set statusline=%-25.45F\ %-2.9y%=%4l/%-4L\ %3.3v\ %3.3p%%%a%r%m
" set statusline=[%n]\ %<%f%m%r\ %w\ %y\ \ <%{&fileformat}>%=[%o]\ %l,%c%V\/%L\ \ %P
"
set statusline=%!MyStatusLine()
func! MyStatusLine()
    let l:statusline = "[%2n] %-25.45F %=% %9y%6h %3m%r%w L%4l/%-4L:%3p%% C%-3v %-7a"
          

    return l:statusline
endfunc


" Nice window title
" set titlestring="%f\ %h%m%r%w\ -\ %{v:progname}\ -\ %{substitute(getcwd(),\ $HOME,\ '~',\ '')}\ [&filetype]"


" Nice statusbar"{{{
" set statusline=
" set statusline+=%2*%-3.3n%0*\                " buffer number
" set statusline+=%f\                          " file name
" set statusline+=%h%1*%m%r%w%0*               " flags
" set statusline+=\[%{strlen(&ft)?&ft:'none'}, " filetype
" set statusline+=%{&encoding},                " encoding
" set statusline+=%{&fileformat}]              " file format
" if filereadable(expand("$VIM/vimfiles/plugin/vimbuddy.vim"))
"     set statusline+=\ %{VimBuddy()}          " vim buddy
" endif
" set statusline+=%=                           " right align
" set statusline+=%2*0x%-8B\                   " current char
" set statusline+=%-14.(%l,%c%V%)\ %<%P        " offset
"}}}
" special statusbar for special windows {{{
if has("autocmd")
    au FileType qf
                \ if &buftype == "quickfix" |
                \     setlocal statusline=%2*%-3.3n%0* |
                \     setlocal statusline+=\ \[Compiler\ Messages\] |
                \     setlocal statusline+=%=%2*\ %<%P |
                \ endif

    fun! FixMiniBufExplorerTitle()
        if "-MiniBufExplorer-" == bufname("%")
            setlocal statusline=%2*%-3.3n%0*
            setlocal statusline+=\[Buffers\]
            setlocal statusline+=%=%2*\ %<%P
        endif
    endfun

    au BufWinEnter *
                \ let oldwinnr=winnr() |
                \ windo call FixMiniBufExplorerTitle() |
                \ exec oldwinnr . " wincmd w"
endif
" }}}
" }}}

 " }}}
" Navigation: general buffer handling {{{
" SHORTCUTS"{{{
" *** F1 provides a list of open files; see Function Key Shortcuts.
" Delete a buffer but keep layout
if has("eval")
    command! Kwbd enew|bw #
    nmap     !   :Kwbd
endif

" Type  follwed by a buffer number or name fragment to jump to it.
" Also replaces the annoying help button. Based on tip 821.
noremap  :ls:b


"}}}

set switchbuf=useopen           "swb:   Jumps to first window or tab that contains specified buffer instead of duplicating an open window
set hidden                      "hid:   allows opening a new buffer in place of an existing one without first saving the existing one


" File Switching use  &  to cycle through files {{{
"" SHORTCUTS
nnoremap  :next
nnoremap  :prev
" [+N by default is like j, and +P like k.]

"}}}
" }}}
" Compatibility and Space/Tabbing {{{

" Make backspace delete lots of things
set backspace=indent,eol,start

" Fix some backspace/delete compatibility issues
" map! ^? ^H
" map! ^H ^?

" Use extended regular expressions
set magic

" use indents of 4 spaces, and have them copied down lines:
" set shiftwidth=4
set softtabstop=4
set shiftround
"set expandtab		"et: inserts spaces instead of tabs
set smarttab
set autoindent
set smartindent

if &columns == 80
    " If we're on an 80-char wide term, don't display these screen hogs
    set nonumber
    set foldcolumn=0
    set softtabstop=2
"    set shiftwidth=2       " IMO, this setting should be per-file, in a modeline
    set noshowcmd
endif

"lcs:   displays tabs with :set list & displays when a line runs off-screen
 set listchars=tab:;_,eol:$,trail:_,precedes:<,extends:>

" esckeys: allow usage of cursor keys within insert mode 
set esckeys 

" }}}
" Performance Enhancement and Terseness {{{
set shortmess+=a                "shm:   be terse on the status line, e.g. 'readonly' becomes 'RO' 
set ttyfast                     "tf:    improves redrawing for newer computers
set lazyredraw			" Speed up macros
" }}}
" Paths & History (files, commands, searches) {{{
" have fifty lines of command-line (etc) history:
" set history=50

" remember all of these between sessions, but only 10 search terms; also
" remember info for 10 files, but never any on removable disks, don't remember
" marks in files, don't rehighlight old search patterns, and only save up to
" 100 lines of registers; including @10 in there should restrict input buffer
" but it causes an error for me:
" set viminfo=/10,'10,r/mnt/zip,r/mnt/floppy,f0,h,\"100
" set viminfo='100,f1,:100,/100   "vi:    For a nice, huuuuuge viminfo file

" Enable a nice big viminfo file
set viminfo='1000,f1,:1000,/1000
set history=500


" Searches the current directory as well as subdirectories with commands like :find, :grep, etc.
set path=.,**

" Include $HOME in cdpath
if has("file_in_path")
    let &cdpath=','.expand("$HOME").','.expand("$HOME").'/work'
endif



" }}}
" Spelling {{{

" use s to bring up spelling suggestions

set mousemodel=popup

hi SpellBad cterm=underline ctermbg=none ctermfg=Red
hi SpellCap cterm=underline ctermbg=none
hi SpellRare cterm=underline ctermbg=none
hi SpellLocal cterm=underline ctermbg=none

" correct my common typos without me even noticing them:
    abbreviate teh the
    abbreviate spolier spoiler
    abbreviate Comny Conmy
    abbreviate atmoic atomic

"}}}
" Highlight: Cursor Line and Column {{{
" Cursor Line highlight
set cursorline                  "cul:   highlights the current line
set cursorcolumn                "cuc:   highlights the current column

" I love the new CursorLine, but terminal underlining kicks legibility in the nuts.
" So what to do? Bold is (extremely) subtle, but it's better than nothing.
hi CursorLine   cterm=bold      ctermbg=none
hi CursorColumn cterm=bold      ctermbg=none


" }}}
" Modeline Handling {{{ 
" enable parsing of them
set modeline

" Append modeline after last line in buffer.
" Use substitute() (not printf()) to handle '%%s' modeline in LaTeX files.
function! AppendModeline()
  let save_cursor = getpos('.')
  let append = ' vim: set ts='.&tabstop.' sw='.&shiftwidth.' tw='.&textwidth.': '
  $put =substitute(&commentstring, '%s', append, '')
  call setpos('.', save_cursor)
endfunction

"" SHORTCUT
nnoremap  ml :call AppendModeline()

" reference: http://vim.wikia.com/wiki/Modeline_magic
"}}}
" Printing {{{

" Shows line numbers and adjusts the left margin not to be ridiculous
    set printoptions=number:y,left:5pc,syntax:y
    set printfont=Monaco:h8         " face-type (not size) ignored in PostScript output :-(
    set printencoding=utf-8

" }}}
" References {{{
" http://www.stripey.com/vim/vimrc.html
" http://eseth.org/filez/prefs/vimrc
" }}}




" modeline for .vimrc
" vim: foldmethod=marker foldcolumn=3 foldenable tw=120 shiftwidth=4 softtabstop=4 expandtab