Source

Dotfiles / .vimrc

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
" 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 'hdima/vim-scripts', {'rtp': 'tree/master/syntax/python/'}
" Matches html tags with %
Bundle 'MatchTag'
" Epic looking statusbar
Bundle 'Lokaltog/vim-powerline.git'
" Better(hopefully not broken like quicktask.vim) TODO list
" Bundle 'https://github.com/mivok/vimtodo.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(?) <Makes vim slow :(>
Bundle 'scrooloose/syntastic.git'
" TAB completion to insert mode autocompletes
Bundle 'ervandew/supertab.git'
" Cool HTML/CSS constructor - not needed much :(
" Bundle 'ZenCoding.vim'
" Cool fuzzy finder, <c-p> is epic
Bundle 'ctrlp.vim'
" Good commenter
Bundle 'tComment'

" 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'
" Nice colorscheme
Bundle 'blackboard.vim'
" Nice colorscheme
Bundle 'darkspectrum'


" }}}

"
" ~/.vimrc
"

" Main options {{{
if $TERM =~ "256"
  set list listchars=tab:\➜\ ,trail:·,nbsp:-
  set t_Co=256
  " Try to force a dark background, some themes may overwrite this
  set background=dark

  "colorscheme fruit
  "colorscheme molokai
  "colorscheme inkpot
  "colorscheme mustang
  "colorscheme badwolf
  "colorscheme BusyBee
  colorscheme hemisu
  "colorscheme vibrantink
  "colorscheme desert256
  "colorscheme 256-grayvim
  "colorscheme solarized
  "colorscheme blackboard
  "colorscheme darkspectrum

  " Set universal Folded colors for all themes, since most
  " fudge it up and make it unreadable
  if &background=="light"
    hi Folded          ctermfg=67  ctermbg=233
  else
    hi Folded          ctermfg=245  ctermbg=249
  endif
  " Make the line numbers always readable
  hi LineNr            ctermfg=67  ctermbg=0

else
  set t_Co=16
  colorscheme inkpot
endif

source /usr/ropevim.vim
autocmd FileType css,scss 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 = 'pyflakes'

" flake8 - Warn when complexity over 12 in flakes, ignore longline warnings on PEP8
let g:syntastic_python_checker_args = "--max-complexity 10 --ignore=E501"
" Check files on open and save
let g:syntastic_check_on_open=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 wrap                          " Wrap lines(vs. nowrap)
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 = ","

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

" comment/uncomment a visual block
vmap <Leader>c gc<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>

" 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>

" Window swapping
nmap <silent> <leader>mw :call MarkWindowSwap()<CR>
nmap <silent> <leader>pw :call DoWindowSwap()<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=""

  " Don't show whitespace in rEST?
  au FileType rst                              set nolist

  " file type specific commands
  au FileType c                            set formatoptions+=ro
  au FileType make                         set noexpandtab shiftwidth=8
  au FileType python,javascript,htmldjango 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

  " Show Tagbar for Python, Javascript
  au FileType python,javascript  TagbarOpen
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()

function! MarkWindowSwap()
    let g:markedWinNum = winnr()
endfunction

" Allows to change buffers
" source: http://stackoverflow.com/questions/2586984/how-can-i-swap-positions-of-two-open-files-in-splits-in-vim
function! DoWindowSwap()
    "Mark destination
    let curNum = winnr()
    let curBuf = bufnr( "%" )
    exe g:markedWinNum . "wincmd w"
    "Switch to source and shuffle dest->source
    let markedBuf = bufnr( "%" )
    "Hide and open so that we aren't prompted and keep history
    exe 'hide buf' curBuf
    "Switch to dest and shuffle source->dest
    exe curNum . "wincmd w"
    "Hide and open so that we aren't prompted and keep history
    exe 'hide buf' markedBuf
endfunction


" 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

" }}}