piggybox /.vimrc

syntax on
set nocompatible
set history=400


"display trailing whitespace and tabs
highlight SpecialKey ctermfg=DarkGray
set list listchars=tab:\|_,trail:.

filetype plugin on
filetype indent on

"auto-change directory to current file
set autochdir

""Set to auto read when a file is changed from the outside
set autoread

let mapleader = ","

"fast editing vimrc
map s :source ~/.vimrc
map v :e! ~/.vimrc

"Fast saving
nmap w :w!

""color and font
colorscheme delek
set gfn=Monospace\ 11
set encoding=utf-8

"set cursorline
hi cursorline guibg=#333333 
hi CursorColumn guibg=#333333

autocmd BufEnter * :syntax sync fromstart

"omni menu color
hi Pmenu guibg=#333333
hi PmenuSel guibg=$555555 guifg=#ffffff

set encoding=utf-8

""pattern match color
hi MatchParen guifg=#000000 guibg=#D0D090

"Set 7 lines to the curors - when moving vertical..
set so=7
""show ruler
set ruler
"show line number
set nu
""dont redraw
set lz
"change buffer without saving
set hid

set backspace=eol,start,indent
"Bbackspace and cursor keys wrap to
set whichwrap+=<,>,h,l
set wrap

set magic
set mat=2

""highlight search results
set hlsearch
set incsearch

map ve :Vexplore
map te :VSTreeExplorer

"smart to move windows
map  j
map  k
map  h
map  l

"buffer close
map bc :Bclose

""smart tab
map  :tabnext
map  :tabprev
map tn :tabnew %
map tc :tabclose
map tm :tabmove

"Use tab for opened buffer
set switchbuf=usetab
set stal=2

""Moving fast to front, back and 2 sides ;)
imap  $a
imap  0i
imap  $a
imap  0i

"Move a line of text using alt
nmap  mz:m+`z
nmap  mz:m-2`z
vmap  :m'>+`mzgv`yo`z
vmap  :m'<-2`>my` 

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Buffer realted
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Fast open a buffer by search for a name
map  :sb 

"Open a dummy buffer for paste
map q :e ~/buffer

"Restore cursor to file position in previous editing session
set viminfo='10,\"100,:20,%,n~/.viminfo
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif

" Buffer - reverse everything ... :)
map  ggVGg?

" Don't close window, when deleting a buffer
command! Bclose call BufcloseCloseIt()

function! BufcloseCloseIt()
    let l:currentBufNum = bufnr("%")
    let l:alternateBufNum = bufnr("#")

    if buflisted(l:alternateBufNum)
        buffer #
    else
        bnext
    endif

    if bufnr("%") == l:currentBufNum
        new
    endif

    if buflisted(l:currentBufNum)
        execute("bdelete! ".l:currentBufNum)
    endif
endfunction

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Parenthesis/bracket expanding
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
vnoremap $1 `>a)`
vnoremap $2 `>a]`
vnoremap $3 `>a}`
vnoremap $$ `>a"`
vnoremap $q `>a'`
vnoremap $w `>a"`

"Map auto complete of (, ", ', [
inoremap $1 ():let leavechar=")"i
inoremap $2 []:let leavechar="]"i
inoremap $4 {o}:let leavechar="}"O
inoremap $3 {}:let leavechar="}"i
inoremap $q '':let leavechar="'"i
inoremap $w "":let leavechar='"'i
au BufNewFile,BufRead *.\(vim\)\@! inoremap " "":let leavechar='"'i
au BufNewFile,BufRead *.\(txt\)\@! inoremap ' '':let leavechar="'"i

imap  :exec "normal f" . leavechara
imap  :exec "normal f" . leavechara

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text options
" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set expandtab
set shiftwidth=4
"set foldmethod=indent
set softtabstop=4
set tabstop=4
"set backspace=4
set smarttab
set lbr
set tw=500
"smart indent
set si

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin configuration
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

""""""""""""""""""""""""""""""
" => Yank Ring
""""""""""""""""""""""""""""""
map y :YRShow

""""""""""""""""""""""""""""""
" => File explorer
""""""""""""""""""""""""""""""
"Split vertically
let g:explVertical=1

"Window size
let g:explWinSize=35

let g:explSplitLeft=1
let g:explSplitBelow=1

"Hide some files
let g:explHideFiles='^\.,.*\.class$,.*\.swp$,.*\.pyc$,.*\.swo$,\.DS_Store$'

"Hide the help thing..
let g:explDetailedHelp=0

""""""""""""""""""""""""""""""
" => Minibuffer
""""""""""""""""""""""""""""""
let g:miniBufExplModSelTarget = 0
let g:miniBufExplorerMoreThanOne = 0
let g:miniBufExplModSelTarget = 0
let g:miniBufExplUseSingleClick = 1
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplVSplit = 0
let g:miniBufExplSplitBelow=0

"WindowZ
map  :WMToggle

let g:bufExplorerSortBy = "name"


""""""""""""""""""""""""""""""
" => Tag list (ctags) 
""""""""""""""""""""""""""""""
"let Tlist_Ctags_Cmd = "/"
"let Tlist_Sort_Type = "name"
let Tlist_Show_Menu = 1
let Tlist_Use_Right_Window = 1
let Tlist_Auto_Open = 0 
let Tlist_Exit_OnlyWindow = 1
let Tlist_Use_SingleClick = 1
let Tlist_File_Fold_Auto_Close = 1
map t :Tlist

" Buffer explorer
map b :BufExplorer

" Rproject
map r :Rproject

" File explorer
map f :NERDTree

" Haskell syntax highlight
"let hs_highlight_boolean = 1
let hs_highlight_types = 1
let hs_highlight_more_types = 1
let hs_highlight_debug = 1
let hs_highlight_delimiters = 1


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Cope
" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" "Turn off search highlight
 map   :noh


 "Remove the Windows ^M
 noremap m mmHmt:%s///ge'tzt'm

 "Paste toggle - when pasting something in, don't indent.
 set pastetoggle=

 "Remove indenting on empty lines
 map  :%s/\s*$//g:noh''

 "Super paste
 inoremap  :set pastemui+mv'uV'v=:set nopaste

""Nice statusbar
set laststatus=2
set statusline=
set statusline+=%2*%-3.3n%0*\ " buffer number
set statusline+=%f\ " file name
set statusline+=%h%1*%m%r%w%0* " flag
set statusline+=[
if v:version >= 600
    set statusline+=%{strlen(&ft)?&ft:'none'}, " filetype
    set statusline+=%{&encoding}, " encoding
endif
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+=0x%-8B\ " current char
set statusline+=%-14.(%l,%c%V%)\ %<%P " offset

"HAML syntax color
au BufNewFile,BufRead *.haml set ft=ruby
"Nginx config syntax color
au BufRead,BufNewFile /etc/nginx/*.conf set ft=nginx