Source

Dotfiles / .vimrc

Full commit
" THE NEXT 3 LINES MUST BE FIRST
filetype off
"call pathogen#runtime_append_all_bundles()
filetype plugin indent on
syntax on

set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

" Vundle plugins {{{
" REQUIRED: let Vundle manage Vundle
Bundle 'gmarik/vundle'
" ,f and ,b file and buffer finder
Bundle 'FuzzyFinder'
" #xxxxxx and #xxx get highlighted ,tc
Bundle 'colorizer'
" Readwrite files over web
Bundle 'netrw.vim'
" Some kind of 'epic' completion
Bundle 'neocomplcache'
" Visualized undo tree F12
Bundle 'Gundo'
" Script library used by some other modules
Bundle 'L9'
" Nice filesystem explorer. ,lf ,lb ,lg ,lr
Bundle 'LustyExplorer'
" Allows to ack current dir. Ack
Bundle 'ack.vim'
" Python PEP8 checker F5, Syntastic replaced this
"Bundle 'pep8'
" Good file explorer F11
Bundle 'The-NERD-tree'
" TaskList for finding NOTE, FIXME, etc
Bundle 'TaskList.vim'
" Python support
Bundle 'python.vim'
" Matches html tags with %
Bundle 'MatchTag'
" On the fly checking for python errors
Bundle 'pyflakes.vim'
" Epic looking statusbar
Bundle 'Lokaltog/vim-powerline.git'
" QuickTask - task syntax tool
Bundle 'aaronbieber/quicktask.git'
" Better tagbar w/ F10
Bundle 'majutsushi/tagbar.git'
" Zoom windows with <c-w>+o
Bundle 'vim-scripts/ZoomWin.git'
" Syntastic epic syntax checker on save(?)
Bundle 'scrooloose/syntastic.git'

" Colorscheme
Bundle 'xterm16.vim'
" Colorscheme
Bundle 'vibrantink'
" Colorscheme
Bundle 'desert256.vim'
" Colorscheme
Bundle '256-grayvim'
" Colorscheme
Bundle 'BusyBee'
" Badwolf colorscheme
Bundle 'sjl/badwolf.git'
" Hemisu colorscheme
Bundle 'noahfrederick/Hemisu.git'
" Some kind of epic colorscheme
Bundle 'altercation/vim-colors-solarized.git'
" PySMELL completer
Bundle 'Pydiction'

" }}}

"
" ~/.vimrc
"

" Main options {{{
if $TERM =~ "256"
  set list listchars=tab:\➜\ ,trail:·,nbsp:-
  set t_Co=256
  "colorscheme fruit
  "colorscheme molokai
  "colorscheme inkpot
  "colorscheme mustang
  colorscheme badwolf
else
  set t_Co=16
  colorscheme inkpot
endif

let g:pydiction_location = "/home/tanel/Projects/GateMe/gateme/gateme/complete-dict"
source /usr/ropevim.vim
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
" Use neocomplcache.
let g:neocomplcache_enable_at_startup = 1
" Use smartcase.
let g:neocomplcache_enable_smart_case = 1
" Use camel case completion.
let g:neocomplcache_enable_camel_case_completion = 1
" Use underbar completion.
let g:neocomplcache_enable_underbar_completion = 1
" Set minimum syntax keyword length.
let g:neocomplcache_min_syntax_length = 3
let g:neocomplcache_auto_completion_start_length = 4
let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*'

" Syntastic checks syntax with flake8/pyflakes/pylint
let g:syntastic_python_checker = 'flake8'
" Warn when complexity over 12 in flakes, gnore longline warnings on PEP8
let g:syntastic_python_checker_args = "--max-complexity 12 --ignore=E501"
" Check files on open and save
let g:syntastic_check_on_open=1
" Save quicktask on buffer unfocus
let g:quicktask_autosave = 1


set directory=~/.vim/swap
set colorcolumn=80                " Mark column 80 with red
set nocompatible                  " Use VIM improvements over more VI-compatible mode
set autoindent                    " Autoindent new lines
set expandtab                     " Use spaces instead of <TAB>
set incsearch                     " Show search matches while typing
set ignorecase                    " Ignore case in search
set smartcase                     " Override ignorecase if search contains Upper case characters
set nobackup                      " No backup of file before overwrite
set hlsearch                      " highlight search matches
set nowrap                        " Don't wrap lines
set number                        " Linenumbers???
set confirm                       " Confirm some actions
set ruler                         " Show cursor coordinates in bottom right
set showmode                      " Show current mode
set showcmd                       " Show command characters
set smartindent                   " Inserts newlines in C-like languages
set smarttab                      " Inserts some amount of tabs
set linebreak                     " Smart linebreaking, but we have 'nowrap', so it doesn't do anything
set title                         " Set window title
set vb t_vb=                      " Turn off all visualbells (and consequencely beeps)
set shiftwidth=2                  " Number of spaces used for each step of *autoindent*
set showtabline=1                 " Something about showing TAB pages... :S ???
set laststatus=2                  " Last window has status line *always*
set shortmess=a                   " Uses short status messages, etc. [Modified] -> [+]
set history=50                    " History of Cmd mode commands
set updatetime=5000               " If nothing is typed for <x> milliseconds, write to swap file.
set mouse=nvcr                    " Enable mouse in Normal, Visual, Command, Prompts
set clipboard=unnamed             " Enable using system clipboard
"set foldmethod=indent             " *Syntax highlighting* items specify folds.  *indent* could be useful for Python
set formatoptions=tcroqn1         " Some autowrapping, insert auto current_comment_leader on 'O' or 'o', more mumbojumbo
set backspace=indent,eol,start    " Allow backspacing over indents, linebreaks, start of insert
set wildmode=list:longest,full    " Mode to match strings with consequtive wildcards.
set undodir=~/.vim/undodir        " Storing undo info
set undofile
set undolevels=1000               " How many undos can I do
set undoreload=1000               " Something weird about buffers ???
set listchars=tab:»·,trail:·      " Characters to show instead of line trailers
set list                          " Show unprintable characters as ^ (previous command)
set hidden                        " Some kind of hidden mode, lustyexplorer wanted it



" }}}
" Folding stuffs {{{
if has ('folding')
  set foldenable
  set foldmethod=indent
  set foldcolumn=1
  set foldnestmax=1
endif
" }}}
" Keymaps {{{
" unmap annoying keys
nnoremap q: <Nop>
nnoremap q/ <Nop>
nnoremap q? <Nop>

" leader key
:let mapleader = ","

" FuzzyFinder
map <Leader>f :FufFile<cr>
map <Leader>b :FufBuffer<cr>

" diff
nnoremap <Leader>u :diffupdate<cr>
nnoremap <Leader>g :diffget<cr>
nnoremap <Leader>p :diffput<cr>

" comment/uncomment a visual block
vmap <Leader>c :call CommentLines()<CR>

" macro key
:nnoremap <F2> @q

map ; :
" code fold
map <space> za

" Tab indents code in visual mode
vmap <Tab> >gv
vmap <S-Tab> <gv

" Write file with sudo
cmap w!! %!sudo tee > /dev/null %

" Tab controls
map <Leader><Tab> :tabnew<CR>
map <Leader>o     :tabnext<CR>
map <Leader>a     :tabprevious<CR>

" RopeGoto controls
map <leader>j :RopeGotoDefinition<CR>
map <leader>r :RopeRename<CR>

" Set pastetoggle to F3
set pastetoggle=<F3>

" Open tablist
nnoremap <F10> :TagbarToggle<CR>

"Open NERDTree
nnoremap <F11> :NERDTreeToggle<CR>

"Open Gundo tree view
nnoremap <F12> :GundoToggle<CR>

" Toggle linenumber mode
nnoremap <C-n> :call NumberToggle()<cr>

" Remap window resize to Alt+hjkl
" NOTE: These do not work :(
" map <silent> <A-h> <C-w><
" map <silent> <A-j> <C-W>-
" map <silent> <A-k> <C-W>+
" map <silent> <A-l> <C-w>>

" Better resize from http://www.agillo.net/simple-vim-window-management/
nmap <left>  :3wincmd <<cr>
nmap <right> :3wincmd ><cr>
nmap <up>    :3wincmd +<cr>
nmap <down>  :3wincmd -<cr>


" }}}
" Autocommands {{{
if has('autocmd')
  let python_highlight_all = 1
  let python_highlight_space_errors = 1
  let python_fold = 1
  let lua_fold = 1
  let lua_version = 5
  let lua_subversion = 1

  " html
  au Filetype html,xml,xsl set spell

  " Enter relativenumber on Insert exit and Vice-versa
  autocmd InsertEnter * :set number
  autocmd InsertLeave * :set relativenumber

  " Remove trailing whitespace
  au BufWritePre * :call setline(1, map(getline(1, "$"), 'substitute(v:val, "\\s\\+$", "","")'))

  " set the title string
  au BufEnter * let &titlestring = "vim: " . substitute(expand("%:p"), $HOME, "~", '')
  au BufEnter * let &titleold    = substitute(getcwd(), $HOME, "~", '')

  " set a better status line
  au BufRead * call SetStatusLine()

  " restore cursor position
  au BufReadPost * call RestoreCursorPos()
  " Opens the fold where the cursor was restored to(?)
  au BufWinEnter * call OpenFoldOnRestore()

  " file types for nonstandard/additional config files
  au BufNewFile,BufRead *conkyrc*          set ft=conkyrc
  au BufNewFile,BufRead *muttrc*           set ft=muttrc
  au BufNewFile,BufRead *.rem              set ft=remind
  au BufNewFile,BufRead $SCREEN_CONF_DIR/* set ft=screen
  au BufNewFile,BufRead *.xcolors          set ft=xdefaults
  au BufNewFile,BufRead *.rss              set ft=xml

  " change how vim behaves when composing emails
  au BufNewFile,BufRead ~/.mutt/temp/mutt* set ft=mail | set textwidth=72 | set spell | set nohls

  au BufNewFile,BufRead ~/.mutt/temp/mutt* nmap  <F1>  gqap
  au BufNewFile,BufRead ~/.mutt/temp/mutt* nmap  <F2>  gqqj
  au BufNewFile,BufRead ~/.mutt/temp/mutt* nmap  <F3>  kgqj
  au BufNewFile,BufRead ~/.mutt/temp/mutt* map!  <F1>  <ESC>gqapi
  au BufNewFile,BufRead ~/.mutt/temp/mutt* map!  <F2>  <ESC>gqqji
  au BufNewFile,BufRead ~/.mutt/temp/mutt* map!  <F3>  <ESC>kgqji

  " set comment characters for common languages
  au FileType python,sh,bash,zsh,ruby,perl     let StartComment="#"  | let EndComment=""
  au FileType cpp,php,c,javascript             let StartComment="//" | let EndComment=""

  au FileType html    let StartComment="<!--" | let EndComment="-->"
  au FileType haskell let StartComment="--"   | let EndComment=""
  au FileType lua     let StartComment="--"   | let EndComment=""
  au FileType vim     let StartComment="\""   | let EndComment=""

  au FileType xdefaults    let StartComment="!"  | let EndComment=""

  " file type specific commands
  au FileType c      set formatoptions+=ro
  au FileType make   set noexpandtab shiftwidth=8
  au FileType python set expandtab shiftwidth=4 tabstop=4
  au FileType c      syn match matchName /\(#define\)\@<= .*/
  au FileType cpp    syn match matchName /\(#define\)\@<= .*/
  au FileType text   setlocal textwidth=72
  au FileType vim    set foldmethod=marker  " Fold .vimrc on markers
endif
 " }}}
" Functions {{{

function! SetStatusLine()
    let l:s1="%-3.3n\\ %f\\ %h%m%r%w"
    let l:s2="[%{strlen(&filetype)?&filetype:'?'},\\ %{&encoding},\\ %{&fileformat}]"
    let l:s3="%=\\ 0x%-8B\\ \\ %-14.(%l,%c%V%)\\ %<%P"
    execute "set statusline=" . l:s1 . l:s2 . l:s3
endfunction

function! RestoreCursorPos()
  if expand("<afile>:p:h") !=? $TEMP
    if line("'\"") > 1 && line("'\"") <= line("$")
      let line_num = line("'\"")
      let b:doopenfold = 1
      if (foldlevel(line_num) > foldlevel(line_num - 1))
        let line_num = line_num - 1
        let b:doopenfold = 2
      endif
      execute line_num
    endif
  endif
endfunction

function! OpenFoldOnRestore()
  if exists("b:doopenfold")
    execute "normal zv"
    if(b:doopenfold > 1)
      execute "+".1
    endif
    unlet b:doopenfold
  endif
endfunction

function CommentLines()
  try
    execute ":s@^".g:StartComment." @\@g"
    execute ":s@ ".g:EndComment."$@@g"
  catch
    execute ":s@^@".g:StartComment." @g"
    execute ":s@$@ ".g:EndComment."@g"
  endtry
endfunction

function! s:DiffWithSaved()
  let filetype=&ft
  diffthis
  vnew | r # | normal! 1Gdd
  diffthis
  exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
endfunction
com! DiffSaved call s:DiffWithSaved()

" Makes mappings toggleable
function MapToggle(key, opt)
  let cmd = ':set '.a:opt.'! \| set '.a:opt."?\<CR>"
  exec 'nnoremap '.a:key.' '.cmd
  exec 'inoremap '.a:key." \<C-O>".cmd
endfunction

command -nargs=+ MapToggle call MapToggle(<f-args>)

MapToggle <F4> foldenable
MapToggle <F5> number
MapToggle <F6> spell
MapToggle <F7> paste
MapToggle <F8> hlsearch
MapToggle <F9> wrap

" <C-n> toggles numbers
function! NumberToggle()
  if(&relativenumber == 1)
    set number
  else
    set relativenumber
  endif
endfunc

" }}}