""""""""""""""""""""""""""""""""""""""""""""""""""
" ~/.vimrc
" $Id: vimrc 2 2005-03-29 07:22:59Z pfeifer $
" Hagen Paul Pfeifer - hagen@jauu.net
" http://www.jauu.net
"
""""""""""""""""""""""""""""""""""""""""""""""""""


""""""""""""""""""""""""""""""""""""""""""""""""""
" common

"background==daaarrrk!
set background=dark
"vim? vi? VIM!
set nocompatible
"there exist no modem-connection
set ttyfast
"linux terminal to interpret function keys currectly
"set term=linux
"no bells; if you want visual message type => set visualbell
set visualbell t_vb=
"show matching brackets
set showmatch
"...but shown only 2 tenth of a second
set matchtime=2
"always show statusline
set laststatus=2
"set timeoutlen=0
set timeout timeoutlen=3000 ttimeoutlen=100
"allow backspace everything
set backspace=indent,eol,start
"set tabstop to 4 characters
set tabstop=2
set shiftwidth=2
"always show ruler
set ruler
"write a viminfo file
set viminfo='20,\"50
"show parial pattern matches in real time
set incsearch
" I like highlighted search pattern
set hlsearch
"spaces preferred to tabs (see autocmd for exceptions)
set expandtab
"living on the edge, no backup
set nobackup
"use a scrollable menu for filename completions
set wildmenu
"ignore class and object files
set wildignore=*.class,*.o,*.bak,*.swp
"display folders ( sympathie with the devil )
set foldcolumn=1
"of course
syntax on
" set modelines and recognize the last 5 lines
set modeline
set modelines=10
" set minimum window height to 0
set wmh=0
"I need more information
set statusline=%<%f%=\ [%1*%M%*%n%R%H%Y]\ \ %-25(%3l,%c%03V\ \ %P\ (%L)%)%12o'%03b''%03B'
" I work with buffers, when I open a buffer that is recently open in a window,
" don't open this buffer twice: switch to the already open one! Nice for :make, :cn, ... ;-)
set switchbuf=useopen

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" TEST-SUITE


" Alpha State

set cursorline
autocmd BufNewFile *.[ch] r ~/.vim/c_template
" :help ft-c-omni
set tags+=~/.vim/systags
if version >= 700
  set spelllang=de
  set omnifunc=ccomplete#Complete
else
" spell check for the folloging files
  let spell_auto_type = "tex,mail,text,human"
  let spell_markup_ft = ",tex,mail,text,human,,"
  let spell_guess_language_ft = ""
endif


" Beta State

"report after N lines changed; default is two
set report=0
"maximum mumber of undos
set undolevels=1000
set autoindent
set smartindent
set indentkeys=0{,0},!^F,o,O,e,=then,=do,=else,=elif,=esac,=fi,=fin,=fil,=done
let c_space_errors=1
let c_ansi_typedefs=1
let c_ansi_constants=1

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" TEXT FORMATING

if has("autocmd")

  filetype on
    augroup filetype
    filetype plugin indent on
    autocmd BufNewFile,BufRead *.txt set filetype=human
  augroup END

  "vim jumps always to the last edited line, if possible
  "autocmd BufRead *,.* :normal '"
  autocmd BufReadPost *
    \ if line("'\"") > 0 && line("'\"") <= line("$") |
    \   exe "normal g`\"" |
    \ endif

  "in human-language files, automatically format everything at 78 chars:
  autocmd FileType mail,human
         \ set spelllang=de formatoptions+=t textwidth=78 nocindent dictionary=/usr/share/dict/words


  " mail macros
  augroup mail
      au!
      autocmd BufRead *html source $HOME/.vim/mail.vim
  augroup END


  "LaTeX to the fullest! ...dislike overlong lines:
  autocmd FileType tex set formatoptions+=t textwidth=80 nocindent
  autocmd FileType tex set makeprg=pdflatex\ %

  "for C-like programming, have automatic indentation:
  autocmd FileType slang set cindent tabstop=4 shiftwidth=4

  "Java Programms (Prof. Dr. Harald want exactly three blanks ... ;-)
  autocmd FileType java set tabstop=3 shiftwidth=3
  autocmd FileType java set makeprg="ant compile\ %"
  autocmd FileType java set errorformat=\"%f\"\\\,\ line\ %l.%c:%m\,\ %f:%l:%m

  "slrn is my newsreader
  autocmd BufRead .followup,.article,.letter set fo=tcq comments=n:>,n::,n:»,n:]

  "for actual 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,cpp set formatoptions+=ro dictionary=$HOME/.vim/c_dictionary
                       \ tabstop=4 shiftwidth=4 noexpandtab cindent comments=sl:/*,mb:**,elx:*/

  "for Perl programming, have things in braces indenting themselves:
  autocmd FileType perl set smartindent tabstop=3 shiftwidth=3

  "for CSS, also have things in braces indented:
  autocmd FileType css set smartindent

  "for HTML, generally format text, but if a long line has been created leave it
  "alone when editing:
  "autocmd FileType html set formatoptions+=tl
  augroup xhtml
      au!
      autocmd BufRead  *html source $HOME/.vim/html.vim
      autocmd BufWrite *html   ks|call LastMod()|'s
  augroup END

  " indent xml code
  augroup xml
      map ,mf !xmllint --format --recover - 2>/dev/null<CR>
  "    au!
  "    autocmd BufWrite *xml exe ":silent 1,$!xmllint --format --recover - 2>/dev/null"
  augroup END

  "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

  "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 automake set noexpandtab shiftwidth=8

endif " has("autocmd")


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" COLORIZATION ( scary-modus )

"common bg fg color
"highlight Normal        ctermfg=black ctermbg=white
"modus (insert,visual ...)
highlight modeMsg     cterm=bold ctermfg=white  ctermbg=blue
"active statusLine
highlight statusLine    cterm=bold ctermfg=yellow ctermbg=red
"inactive statusLine
highlight statusLineNC  cterm=bold ctermfg=black  ctermbg=white
"visual mode
highlight visual    cterm=bold ctermfg=yellow ctermbg=red
"cursor colors
highlight cursor        cterm=bold
"vertical line on split screen
highlight VertSplit     cterm=bold ctermfg=yellow ctermbg=yellow
"searchpattern
"highlight Search        cterm=bold ctermfg=yellow ctermbg=brown
"folding
highlight Folded                   ctermfg=white ctermbg=yellow

" highlight spell errors
highlight SpellErrors ctermfg=Red cterm=underline term=reverse

"java types, ...the solaris BG looks incredible yellow!
"highlight our functions
let java_highlight_functions=1

" the default colours suck a little bit (but otherwise really nice features)
if version >= 700
   hi PmenuSel ctermfg=red ctermbg=cyan
"  hi Pmenu ctermfg=yellow ctermbg=cyan
"  hi PmenuThumb ctermfg=yellow 
"  hi PmenuSbar ctermfg=magenta
endif

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MAPPINGS

"Function Key's Sector
"F2 -> F4  == misc
"search the current word under cursor in all files in working directory
map <F2> vawy:! grep -n -H <C-R>" .* *<CR>
map <F3> :Sexplore<CR>

"compile, translate, ...
map <F5> :make<CR>

"F9 -> F10 == spell checking with aspell
map <F9>  :w!<CR>:!aspell --lang=en -c %<CR>:e! %<CR>
map <F10> :w!<CR>:!aspell --lang=de -c %<CR>:e! %<CR>

"F11 -> F12 == resize window
map <F11>   <ESC>:resize -5 <CR>
map <F12>   <ESC>:resize +5 <CR>

"Misc Keys

"box it
"make fresh comments => spring, nuke, girl,... (see $HOME/.boxes)
vmap ,# :s/^/\| /<cr>'<O ,-----:: TITEL ::<esc>'>o `--------------<esc>:noh<cr>
" girl theme ;-)
vmap ,mb !boxes -d girl<CR>
nmap ,mb !!boxes -d girl<CR>
vmap ,xb !boxes -d girl -r<CR>
nmap ,xb !!boxes -d girl -r<CR>
" c comment
vmap ,mc !boxes -d c-cmt2<CR>
nmap ,mc !!boxes -d c-cmt2<CR>
vmap ,dc !boxes -d c-cmt2 -r<CR>
nmap ,dc !!boxes -d c-cmt2 -r<CR>
" make some wArEz AstyLE
vmap ,mw !warezstyle<CR>
nmap ,mw !!warezstyle<CR>
" my personal _offline_ dict (and faster too)
map  ,l :!clear ;grep --color=auto -i <cword> ~/.vim/dict-wordlist.txt<cr>
"some radomization on my linux box
map ,zu :r!dd if=/dev/random bs=14 count=1 \| hexdump \| cut -c 9-<esc>3k2dd
" Add C Modeline
"map ,mm mXGi/* vim: set ts=4 sw=4 tw=78 noet : */<ESC>p`X

"found on Bram Moolenaars page, nice thing! (with a little modification => :noh)
map <F6> mX:sp ~/.signatures<CR>ggd/^-- /<CR>Gp:wq<CR>'XGA<CR><Esc>:noh<CR>p`X

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" ABBREVIATIATIONS (very necessary ;-)

iab _TIME        <C-R>=strftime("%X")<CR>
iab _DATE        <C-R>=strftime("%a %b %d %T %Z %Y")<CR>
iab _DATES       <C-R>=strftime("%b %d %Y")<CR>
" ISO 8601 format
iab _DATEN       <C-R>=strftime("%F")<CR>
iab _DATEL       <C-R>=strftime("%a %b %d %Z %Y")<CR>
iab _EPOCH       <C-R>=strftime("%s")<CR>

"common c commands
ab #d #define
ab #i #include <.h><Esc>hhi<C-R>=DC()<CR>
ab #b /*********************************************
ab #e *********************************************/
ab #l /*------------------------------------------*/

"common typing mistakes
ab teh the
ab fro for

ab #m --<CR>Signed and/or encrypted mails preferd. Key-Id = 0x98350C22<CR>
   \Fingerprint = 490F 557B 6C48 6D7E 5706  2EA2 4A22 8D45 9835 0C22 <CR>
   \Key available under: www.jauu.net/download/gnupg_key

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" FUNCTIONS

fun DC()
  let c=nr2char(getchar())|return c=~'\s'?'':c
endfun

func D2H(nr)
  let n = a:nr
  let r = ""
  while n
    let r = '0123456789ABCDEF'[n % 16] . r
    let n = n / 16
  endwhile
  return r
endfunc

" ===================================================================
" ASCII Table - | decimal value - name/char |
" 
" |000 nul|001 soh|002 stx|003 etx|004 eot|005 enq|006 ack|007 bel|
" |008 bs |009 ht |010 nl |011 vt |012 np |013 cr |014 so |015 si |
" |016 dle|017 dc1|018 dc2|019 dc3|020 dc4|021 nak|022 syn|023 etb|
" |024 can|025 em |026 sub|027 esc|028 fs |029 gs |030 rs |031 us |
" |032 sp |033  ! |034  " |035  # |036  $ |037  % |038  & |039  ' |
" |040  ( |041  ) |042  * |043  + |044  , |045  - |046  . |047  / |
" |048  0 |049  1 |050  2 |051  3 |052  4 |053  5 |054  6 |055  7 |
" |056  8 |057  9 |058  : |059  ; |060  < |061  = |062  > |063  ? |
" |064  @ |065  A |066  B |067  C |068  D |069  E |070  F |071  G |
" |072  H |073  I |074  J |075  K |076  L |077  M |078  N |079  O |
" |080  P |081  Q |082  R |083  S |084  T |085  U |086  V |087  W |
" |088  X |089  Y |090  Z |091  [ |092  \ |093  ] |094  ^ |095  _ |
" |096  ` |097  a |098  b |099  c |100  d |101  e |102  f |103  g |
" |104  h |105  i |106  j |107  k |108  l |109  m |110  n |111  o |
" |112  p |113  q |114  r |115  s |116  t |117  u |118  v |119  w |
" |120  x |121  y |122  z |123  { |124  | |125  } |126  ~ |127 del|
" 
" ===================================================================
" ASCII Table - | hex value - name/char |
" 
" | 00 nul| 01 soh| 02 stx| 03 etx| 04 eot| 05 enq| 06 ack| 07 bel|
" | 08 bs | 09 ht | 0a nl | 0b vt | 0c np | 0d cr | 0e so | 0f si |
" | 10 dle| 11 dc1| 12 dc2| 13 dc3| 14 dc4| 15 nak| 16 syn| 17 etb|
" | 18 can| 19 em | 1a sub| 1b esc| 1c fs | 1d gs | 1e rs | 1f us |
" | 20 sp | 21  ! | 22  " | 23  # | 24  $ | 25  % | 26  & | 27  ' |
" | 28  ( | 29  ) | 2a  * | 2b  + | 2c  , | 2d  - | 2e  . | 2f  / |
" | 30  0 | 31  1 | 32  2 | 33  3 | 34  4 | 35  5 | 36  6 | 37  7 |
" | 38  8 | 39  9 | 3a  : | 3b  ; | 3c  < | 3d  = | 3e  > | 3f  ? |
" | 40  @ | 41  A | 42  B | 43  C | 44  D | 45  E | 46  F | 47  G |
" | 48  H | 49  I | 4a  J | 4b  K | 4c  L | 4d  M | 4e  N | 4f  O |
" | 50  P | 51  Q | 52  R | 53  S | 54  T | 55  U | 56  V | 57  W |
" | 58  X | 59  Y | 5a  Z | 5b  [ | 5c  \ | 5d  ] | 5e  ^ | 5f  _ |
" | 60  ` | 61  a | 62  b | 63  c | 64  d | 65  e | 66  f | 67  g |
" | 68  h | 69  i | 6a  j | 6b  k | 6c  l | 6d  m | 6e  n | 6f  o |
" | 70  p | 71  q | 72  r | 73  s | 74  t | 75  u | 76  v | 77  w |
" | 78  x | 79  y | 7a  z | 7b  { | 7c  | | 7d  } | 7e  ~ | 7f del|
" ===================================================================

" vim:set ts=2 tw=80: