set nocompatible

filetype plugin on
filetype indent on

set number
set shiftwidth=2
set tabstop=2

set nosi
set ai
set wrap

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
set history=700


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

" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = ","
let g:mapleader = ","

" Fast saving
nmap <leader>w :w!<cr>


" Edit fast vimrc
autocmd! bufwritepost .vimrc source ~/.vimrc

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""
" my adds
nnoremap Y y$
set nu
set showcmd
set showmode
set cursorline
set list
set listchars=tab:>.,trail:.,extends:#,nbsp:. " Highlight problematic whitespace
" Set 7 lines to the cursor - when moving vertically using j/k
set so=7

" Turn on the WiLd menu
set wildmenu

" Ignore compiled files
set wildignore=*.o,*~,*.pyc
" completition 
set wildmode=longest:full,full

"Always show current position
set ruler

" Height of the command bar
set cmdheight=1

" A buffer becomes hidden when it is abandoned
set hid

" Configure backspace so it acts as it should act
set backspace=eol,start,indent
"set whichwrap+=<,>,h,l

" Ignore case when searching
set ignorecase

" When searching try to be smart about cases 
set smartcase

" Highlight search results
set hlsearch

" Makes search act like search in modern browsers
set incsearch 

" Don't redraw while executing macros (good performance config)
set lazyredraw 

" For regular expressions turn magic on
set magic

" Show matching brackets when text indicator is over them
set showmatch 
" How many tenths of a second to blink when matching brackets
set mat=2

" No annoying sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500

" Add a bit extra margin to the left
"set foldcolumn=1

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Coloring
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

syntax enable 
set background=dark

hi Comment ctermfg=LightBlue

hi Search cterm=NONE ctermfg=black ctermbg=white

hi StatusLine cterm=NONE ctermfg=NONE ctermbg=black
hi StatusLine cterm=bold,reverse
hi StatusLineNC cterm=NONE ctermfg=NONE ctermbg=darkgrey
hi StatusLineNC cterm=bold,reverse
hi TabLineFill cterm=NONE ctermfg=NONE ctermbg=black
hi TabLineFill cterm=bold,reverse
hi TabLineSel cterm=NONE ctermfg=NONE ctermbg=black
hi TabLineSel cterm=bold,reverse
hi TabLine cterm=NONE ctermfg=NONE ctermbg=darkgrey
hi TabLine cterm=bold,reverse
hi VertSplit	cterm=NONE
hi VertSplit	cterm=bold,reverse

" Set utf8 as standard encoding and en_US as the standard language
set encoding=utf8

" Use Unix as the standard file type
set ffs=unix,dos,mac

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files, backups and undo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set backupdir=~/.vim/backups
set directory=~/.vim/swaps
set undodir=~/.vim/undo
set undofile


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Use spaces instead of tabs
set expandtab

" Be smart when using tabs ;)
set smarttab


" Linebreak on 500 characters
set lbr
set tw=500



""""""""""""""""""""""""""""""
" => Visual mode related
""""""""""""""""""""""""""""""
" Visual mode pressing * or # searches for the current selection
" Super useful! From an idea by Michael Naumann
vnoremap <silent> * :call VisualSelection('f', '')<CR>
vnoremap <silent> # :call VisualSelection('b', '')<CR>

set virtualedit=block


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around, tabs, windows and buffers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Treat long lines as break lines (useful when moving around in them)
" Get rid of these fuckin IMAP_JumpFunc which pisses me of
"
imap awsedrffty <plug>IMAP_JumpForward
nmap awsedrffty <plug>IMAP_JumpForward

map j gj
map k gk


" Disable highlight when <leader><cr> is pressed
map <silent> <leader>/ :noh<cr>

" Smart way to move between windows

"map <unique><C-j> <C-w>j
map <C-k> <C-w>k
map <C-h> <C-w>h
map <C-l> <C-w>l


" Close all the buffers
"map <leader>ba :1,1000 bd!<cr>

" Useful mappings for managing tabs
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove 
map <leader>t<leader> :tabnext 

" Opens a new tab with the current buffer's path
" Super useful when editing files in the same directory
nmap <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
nmap <leader>e :edit <c-r>=expand("%:p:h")<cr>/

" Switch CWD to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>:pwd<cr>

" Specify the behavior when switching between buffers 
try
  set switchbuf=useopen,usetab,newtab
  set stal=2
catch
endtry

" Return to last edit position when opening files (You want this!)
autocmd BufReadPost *
     \ if line("'\"") > 0 && line("'\"") <= line("$") |
     \   exe "normal! g`\"" |
     \ endif
set viminfo^=%
""""""""""""""""""""""""""""""
" => Status line
""""""""""""""""""""""""""""""
" Always show the status line
set laststatus=2

" Format the status line
set statusline=
set statusline=%<%f       " Filename
set statusline+=%w%h%m%r " Options
set statusline+=\ [%{getcwd()}] " current dir
set statusline+=%=[%{&ff}/%Y]\  " filetype
"set statusline+=\ [A=\%03.3b/H=\%02.2B] " ASCII / Hexadecimal value of char
set statusline+=%=%(%l,%c%V%)\ %p%%\  " Right aligned file nav info


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Misc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Toggle paste mode on and off
map <leader>pp :setlocal paste!<cr>


"Show the 80th column
set cc=81
highlight ColorColumn ctermbg=darkgrey ctermfg=red
set textwidth=80


""""""""""""""""""""""""""""""""""""""""""""""""""
" dont let arrows come in your way!
nnoremap <up> <Nop>
nnoremap <down> <Nop>
nnoremap <left> <Nop>
nnoremap <right> <Nop>
"nnoremap <BS> <Nop>
"nnoremap <Del> <Nop>

inoremap <up> <Nop>
inoremap <down> <Nop>
inoremap <left> <Nop>
inoremap <right> <Nop>
"inoremap <BS> <Nop>
"inoremap <Del> <Nop>

vnoremap <up> <Nop>
vnoremap <down> <Nop>
vnoremap <left> <Nop>
vnoremap <right> <Nop>
"vnoremap <BS> <Nop>
"vnoremap <Del> <Nop>
