forked from ClearCarbon/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
456 lines (366 loc) · 13.6 KB
/
vimrc
File metadata and controls
456 lines (366 loc) · 13.6 KB
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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Setup
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Not bothered about vi compatibility
" This must be first, because it changes other options as side effect
set nocompatible
" set term=ansi
" Language agnostic
" " Plugin 'mmai/wikilink' this is breaking open from location list
" Other languages
" " Plugin 'Neurogami/mirah-vim'
" " Plugin 'guns/vim-clojure-static'
" " Plugin 'guns/paredit'
" " Plugin 'bitc/vim-hdevtools'
filetype plugin indent on
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" more secure
set modelines=0
" copy the previous indentation on autoindenting
" set copyindent
" dont autofold on start or load
" set foldlevelstart=99
set nofoldenable
" shows all options in edit wild mode
set wildmode=list:longest
" increase command history and undo
set history=1000
set undolevels=1000
" show the $ at the end of word changes etc
set cpoptions+=$
set number
set relativenumber
" search highlights on, and dynamic searching
" set hlsearch
" These two options, when set together, will
" make /-style searches case-sensitive only
" if there is a capital letter in the search
" expression. *-style searches continue to
" be consistently case-sensitive.
set ignorecase
" set gdefault
set cursorline
set colorcolumn=80
" set ttyfast
" no old messy files
set nobackup
set noswapfile
set nowb
" allow hiding buffers with pending changes
set hidden
" defaults
set tabstop=2
set expandtab
set shiftwidth=2
set softtabstop=2
" use multiple of shiftwidth when indenting with '<' and '>'
set shiftround
" set clipboard=unnamed
" save undo history in file
set undofile
set undodir=~/.cache/vim/undo
" Look for the file in the current directory,
" then south until you reach home.
"set tags=tags;~/
" add the tag file generated by ctag-bundler
set tags+=gems.tags
" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = "\<Space>"
let g:mapleader = "\<Space>"
" When vimrc is edited, reload it
autocmd! bufwritepost vimrc,.vimrc source $MYVIMRC
" handle long lines
set nowrap
set textwidth=80
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Don't use Ex mode, use Q for formatting
map Q gq
" clear search buffer when hitting return
" this is mapped to ctrl l in sensible
" but is is a good key to use for something
" nnoremap <silent> <leader><space> :set nolist!<cr>
" dont use cursor keys!
nnoremap <up> <nop>
nnoremap <down> <nop>
"inoremap <up> <nop>
"inoremap <down> <nop>
"inoremap <left> <nop>
"inoremap <right> <nop>
" Use the arrows to something usefull
nnoremap <right> :bn<cr>
nnoremap <left> :bp<cr>
nnoremap <C-j> <C-W>j
nnoremap <C-k> <C-W>k
nnoremap <C-h> <C-W>h
nnoremap <C-l> <C-W>l
" makes j and k work the way you expect
nnoremap j gj
nnoremap k gk
" make ; do the same thing as :
nnoremap ; :
"set formatoptions=qrn1
" set colorcolumn=80
" augroup vimrc_autocmds
" autocmd BufEnter * highlight OverLength ctermbg=darkgrey guibg=#592929
" autocmd BufEnter * match OverLength /\%80v.*/
" augroup END
" insert a hash rocket with <c-l>
imap <C-r> <space>=><space>
" Edit or view files in same directory as current file
cnoremap %% <C-R>=expand('%:h').'/'<cr>
" avoid pressing F1
inoremap <F1> <ESC>
nnoremap <F1> <ESC>
vnoremap <F1> <ESC>
xmap \\ <Plug>Commentary<CR>
nmap \\ <CR><Plug>Commentary
nmap \\\ <Plug>CommentaryLine<CR>:normal k<CR>
nmap \\u <Plug>CommentaryUndo<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Leader mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Fast saving
nmap <leader>w :w!<cr>
" Close all the buffers
map <leader>ba :%bd!<cr>
" Regenerate ctags
map <leader>c :! ctags --tag-relative -R --exclude=.git --links=no --languages=-javascript,sql<cr>
map <leader>C :! tagundle<cr>
" map leader-W to strip white space
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<cr>
" map leader-H to convert to 1.9 hashs
nnoremap <leader>H :%s/:\(\w\+\)\(\s*\)=>\(\s*\)/\1: /gc<cr>
vnoremap <leader>H :s/:\(\w\+\)\(\s*\)=>\(\s*\)/\1: /gc<cr>
" map leader-G to convert to 1.8 hashs
nnoremap <leader>G :%s/\(\w\+\):\(\s\+\)/:\1 => /gc<cr>
vnoremap <leader>G :s/\(\w\+\):\(\s\+\)/:\1 => /gc<cr>
nnoremap <leader>B :BuffergatorOpen<cr>
" ri.vim remaps
let g:ri_no_mappings=1
nnoremap <leader>ri :call ri#OpenSearchPrompt(0)<cr> " horizontal split
nnoremap <leader>RI :call ri#OpenSearchPrompt(1)<cr> " vertical split
nnoremap <leader>RK :call ri#LookupNameUnderCursor()<cr> " keyword lookup
map <leader>gr :e config/routes.rb<cr>
map <leader>gg :e Gemfile<cr>
" Show the current routes in the split
function! ShowRoutes()
" Requires 'scratch' plugin
:topleft 100 :split __Routes__
" Make sure Vim doesn't write __Routes__ as a file
:set buftype=nofile
" Delete everything
:normal 1GdG
" Put routes output in buffer
:0r! bundle exec rake -s routes
" Size window to number of lines (1 plus rake output length)
:exec ":normal " . line("$") . "_ "
" Move cursor to bottom
:normal 1GG
" Delete empty trailing line
:normal dd
endfunction
map <leader>gR :call ShowRoutes()<cr>
map <leader>e :edit %%
" map <leader>v :view %%
" reselect the text that was just pasted
nnoremap <leader>v V`]
" Switch between the last two files
nnoremap <leader><leader> <c-^>
" Run this file
nmap <silent> <leader>T :w<cr>:TestNearest<CR>
nmap <silent> <leader>t :w<cr>:TestFile<CR>
" nmap <silent> <leader>a :TestSuite<CR>
" nmap <silent> <leader>l :TestLast<CR>
" nmap <silent> <leader>g :TestVisit<CR>
nnoremap <leader>p :set paste!<cr>
nnoremap <leader>q gqip
nmap <leader>m :make<cr>:copen<cr>
" Compatible with ranger 1.4.2 through 1.6.*
"
" Add ranger as a file chooser in vim
"
" If you add this code to the .vimrc, ranger can be started using the command
" ":RangeChooser" or the keybinding "<leader>r". Once you select one or more
" files, press enter and ranger will quit again and vim will open the selected
" files.
function! RangeChooser()
let temp = tempname()
" The option "--choosefiles" was added in ranger 1.5.1. Use the next line
" with ranger 1.4.2 through 1.5.0 instead.
"exec 'silent !ranger --choosefile=' . shellescape(temp)
exec 'silent !ranger --choosefiles=' . shellescape(temp)
if !filereadable(temp)
redraw!
" Nothing to read.
return
endif
let names = readfile(temp)
if empty(names)
redraw!
" Nothing to open.
return
endif
" Edit the first item.
exec 'edit ' . fnameescape(names[0])
" Add any remaning items to the arg list/buffer list.
for name in names[1:]
exec 'argadd ' . fnameescape(name)
endfor
redraw!
endfunction
command! -bar RangerChooser call RangeChooser()
nnoremap <leader>r :<C-U>RangerChooser<CR>
command! Docker let test#ruby#rspec#executable = 'docker-compose run '.fnamemodify(getcwd(), ':t').' bundle exec rspec'
command! DockerLegacy let test#ruby#rspec#executable = 'docker-compose run '.fnamemodify(getcwd(), ':t').' bundle exec spec'
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Unused mappings ATM
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" fold html tag
"nnoremap <leader>ft Vatzf
" double j for escape
"inoremap jj <ESC>
" use tab to move around brackets
"nnoremap <tab> %
"vnoremap <tab> %
" Close the current buffer
"map <leader>bd :bd<cr>
if has("autocmd")
autocmd QuickFixCmdPost *grep* cwindow
augroup vimrcEx
autocmd!
" what does this do?
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
augroup END
augroup vimrc-auto-mkdir
autocmd!
autocmd BufWritePre * call s:auto_mkdir(expand('<afile>:p:h'), v:cmdbang)
function! s:auto_mkdir(dir, force)
if !isdirectory(a:dir) && (a:force || input("'".a:dir."' does not exist. Create? [y/N]") =~? '^y\%[es]$')
call mkdir(iconv(a:dir, &encoding, &termencoding), 'p')
endif
endfunction
augroup END
augroup FTOptions
autocmd!
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Ruby
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd BufNewFile,BufRead Rakefile,*.rake,*.pill,Capfile,Gemfile,config.ru,Guardfile setfiletype ruby
autocmd BufNewFile,BufRead *.scss.erb setfiletype scss.eruby
autocmd BufNewFile,BufRead *.js.erb setfiletype javascript.eruby
autocmd BufNewFile,BufRead *.coffee.erb setfiletype coffeescript.eruby
autocmd BufNewFile,BufRead *.html.erb setfiletype html.eruby
" autocmd BufNewFile,BufRead *.ruby,*.html,*.css,*.js,*.scss,*.less setlocal ts=2 sts=2 sw=2 expandtab
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Other languages
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd BufNewFile,BufRead *.mustache set syntax=mustache
autocmd BufNewFile,BufRead *.ol setfiletype lisp
autocmd BufReadPost fugitive://* set bufhidden=delete
autocmd BufNewFile,BufRead *.md,*.markdown,README,*.txt set spell
autocmd BufNewFile,BufRead *.jst set syntax=eruby
autocmd BufNewFile,BufRead *.jst.tpl set syntax=jst
autocmd BufRead,BufNewFile *.wisp set ft=wisp
autocmd BufRead,BufNewFile *.es6 setfiletype javascript
autocmd FileType wisp call PareditInitBuffer()
" autocmd BufNewFile,BufRead *.go setlocal ts=2 sts=2 sw=2 noexpandtab
" autocmd BufNewFile,BufRead *.hs setlocal ts=2 sts=2 sw=2 expandtab
autocmd BufNewFile,BufRead *.cpp setlocal ts=2 sts=2 sw=2 noexpandtab
autocmd FileType markdown nmap <leader>m :%!kramdown --no-auto-ids<cr>
autocmd FileType markdown vmap <leader>m :!kramdown --no-auto-ids<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Omnifunc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd FileType ruby,eruby silent! setlocal omnifunc=rubycomplete#Complete
autocmd FileType javascript silent! setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html silent! setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType css,scss,less silent! setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType xml silent! setlocal omnifunc=xmlcomplete#CompleteTags
autocmd FileType javascript nmap <leader>j :%!js-beautify --type=js -j -p -q -B -s 2 -f -<cr>
autocmd FileType javascript vmap <leader>j :!js-beautify --type=js -j -p -q -B -s 2 -f -<cr>
autocmd FileType css,scss,less nmap <leader>j :%!js-beautify --type=css -j -q -p -B -s 2 -f -<cr>
autocmd FileType css,scss,less vmap <leader>j :!js-beautify --type=css -j -q -p -B -s 2 -f -<cr>
autocmd FileType html,eruby nmap <leader>j :%!js-beautify --type=html -j -p -q -B -s 2 -f -<cr>
autocmd FileType html,eruby vmap <leader>j :!js-beautify --type=html -j -p -q -B -s 2 -f -<cr>
autocmd FileType ruby nnoremap <leader>l :Errors<cr>
" autocmd FileType go nmap <leader>r <Plug>(go-run)
" autocmd FileType go nmap <leader>b <Plug>(go-build)
autocmd FileType go nmap <leader>t <Plug>(go-test)
" autocmd FileType go nmap <leader>c <Plug>(go-coverage)
autocmd FileType octave nmap <leader>t maggOpkg load all<esc>Gopause<esc>:w<cr>:!octave -qf %<cr>ddggdd:w<cr>`a
autocmd FileType haskell nnoremap <buffer> <leader>j :%!stylish-haskell<cr>
augroup END
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Display
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set background=dark
set encoding=utf-8
set t_Co=16
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Bundles config
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" map for ack
let g:ackprg="ack-grep -H --nocolor --nogroup --column"
nnoremap <leader>a :Ack
nnoremap <leader>s :GitGrep
nnoremap <leader>v :TagbarToggle<cr>
let g:syntastic_stl_format = '[%E{Err: %fe #%e}%B{, }%W{Warn: %fw #%w}]'
let g:syntastic_mode_map = { 'mode': 'passive',
\ 'active_filetypes': ['ruby', 'javascript', 'css', 'hmtl', 'scss', 'less', 'c', 'h', 'go', 'haskell'],
\ 'passive_filetypes': [] }
let g:syntastic_javascript_checkers = ['jshint']
let g:syntastic_ruby_checkers=['rubylint', 'rubocop', 'mri']
let g:syntastic_aggregate_errors=1
let g:syntastic_check_on_open=1
let g:syntastic_enable_signs=1
let g:syntastic_auto_jump=0
let g:syntastic_auto_loc_list=0
let g:vim_markdown_folding_disabled=1
let g:goyo_width=85
let g:buffergator_suppress_keymaps = 1
let g:slime_target = "tmux"
let g:airline_theme='solarized'
let g:airline_left_sep=''
let g:airline_right_sep=''
let g:airline_section_z=''
let g:airline#extensions#whitespace#enabled = 1
" this is for the switch plugin
nnoremap - :Switch<cr>
let g:paredit_leader = '\'
" Goyo
function! s:goyo_before()
silent !tmux set status off
set noshowmode
set noshowcmd
endfunction
function! s:goyo_after()
silent !tmux set status on
set showmode
set showcmd
endfunction
let g:goyo_callbacks = [function('s:goyo_before'), function('s:goyo_after')]
set wildignore+=*/tmp/*,*.so,*.swp,*.zip
let g:ctrlp_custom_ignore = {
\ 'dir': '\.git$\|\.hg$\|\.svn$\|vendor\/bundle$\|node_modules$',
\ 'file': '\.exe$\|\.so$\|\.dll$',
\ }
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Display after bundles
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:solarized_termtrans=1
let g:solarized_termcolors=16
" let g:solarized_contrast="high"
" let g:solarized_visibility="high"
colorscheme solarized
if filereadable(glob("~/.vimrc.local"))
source ~/.vimrc.local
endif