-
Notifications
You must be signed in to change notification settings - Fork 4
/
vimrc
465 lines (377 loc) · 14.2 KB
/
vimrc
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
457
458
459
460
461
462
463
464
465
set nocompatible " Must come first because it changes other options.
" Manage the runtime path with Pathogen.
silent! call pathogen#runtime_append_all_bundles()
silent! call pathogen#helptags()
" Shares the clipboard with OS X
set clipboard=unnamed
syntax enable " Turn on syntax highlighting.
filetype plugin indent on " Turn on file type detection.
set colorcolumn=100
let mapleader=","
nnoremap ; :
ca W w
runtime macros/matchit.vim " Load matchit.vim plugin.
set encoding=utf-8
set ttyfast " Optimize for fast terminal connections
set binary " Don't add empty newlines at the end of files
set noeol "
set showcmd " Display incomplete commands.
set showmode " Display the mode you're in.
set backspace=indent,eol,start " Intuitive backspacing.
set hidden " Handle multiple buffers better.
" Better Completion
set complete=.,b,u,]
set completeopt=menu,preview
set wildmenu " Enhanced command line completion.
set wildmode=longest,list:longest " Complete files like a shell.
set wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,*.jpg,*.jpeg,*.png,*.gif,*.log,*/vendor/*,db/sphinx,*/log/*,*/tmp/*,public/uploads,*/coverage/*,*/node_modules/*
set ignorecase " Case-insensitive searching.
set smartcase " But case-sensitive if expression contains a capital letter.
set incsearch " Highlight matches as you type.
set hlsearch " Highlight matches.
set gdefault " Add the g flag to search/replace by default
set number " Show absolute line numbers (cf. relativenumber).
set ruler " Show cursor position.
set cursorline " Highlight current line
set laststatus=2 " Always show a status line.
set nostartofline " Don’t reset cursor to start of line when moving around.
set wrap " Turn on line wrapping.
set scrolloff=3 " Show 3 lines of context around the cursor.
set shiftwidth=2 "
set tabstop=2 " Tabs and spaces.
set expandtab "
set title " Set the terminal's title
set visualbell " No beeping.
set nobackup " No backups.
set nowritebackup " No backups.
set noswapfile " No swap files; more hassle than they're worth.
set tildeop " Make tilde command behave like an operator.
set shortmess=atI " Avoid unnecessary hit-enter prompts.
set noequalalways " Resize windows as little as possible.
set autoread " Automatically re-read files changed outside Vim.
set t_Co=256 " 256 colors
set background=dark
colorscheme Tomorrow-Night-Eighties
let g:airline_theme="molokai"
let g:sql_type_default = "mysql"
set runtimepath^=~/.vim/bundle/ctrlp.vim
" Very magic regexes.
nnoremap / /\v
vnoremap / /\v
" OS X-like space bar to scroll.
nnoremap <Space> <C-F>
" <Leader><space> turns off search highlighting.
nnoremap <Leader><space> :noh<CR>
" Kill trailing White Space
nnoremap <Leader>kws :%s/\s\+$//<CR>
" Reloads vim config
noremap <silent> <leader>V :source ~/.vimrc<CR>:filetype detect<CR>:exe ":echo 'vimrc reloaded'"<CR>
" System clipboard interaction
" From
" https://github.com/henrik/dotfiles/blob/master/vim/config/mappings.vim
noremap <leader>y "*y
noremap <leader>p :set paste<CR>"*p<CR>:set nopaste<CR>
noremap <leader>P :set paste<CR>"*P<CR>:set nopaste<CR>
" Emacs bindings in command line mode
cnoremap <c-a> <home>
cnoremap <c-e> <end>
" Formatting, TextMate-style
nnoremap Q gqip
vnoremap Q gq
" Select (charwise) the contents of the current line, excluding indentation.
" Great for pasting Python lines into REPLs.
nnoremap vv ^vg_
" Keep search matches in the middle of the window.
nnoremap n nzzzv
nnoremap N Nzzzv
" Same when jumping around
nnoremap g; g;zz
nnoremap g, g,zz
" Directory of current file.
cnoremap %% <C-R>=expand("%:h")."/"<CR>
" Map § to # for typing convenience
set iminsert=1
set imsearch=-1
noremap § #
noremap! § #
lnoremap § #
" Make Y consistent with D and C (instead of yy)
noremap Y y$
" Visually select the text that was most recently edited/pasted.
nmap gV `[v`]
" Make * and # work with visual selection.
vnoremap <silent> * :call VisualSearch('f')<CR>
vnoremap <silent> # :call VisualSearch('b')<CR>
" indent, reselect
:vmap < <gv
:vmap > >gv
" Use cursor keys to navigate buffers.
map <Right> :bnext<CR>
map <Left> :bprev<CR>
imap <Right> <ESC>:bnext<CR>
imap <Left> <ESC>:bprev<CR>
map <Del> :bd<CR>
" Show tabs and trailing whitespace visually
" http://github.com/ciaranm/dotfiles-ciaranm/blob/master/vimrc
"
" See also here for a different solution:
" http://sartak.org/2011/03/end-of-line-whitespace-in-vim.html
if (&termencoding == "utf-8") || has("gui_running")
if v:version >= 700
if has("gui_running")
set list listchars=tab:»·,trail:·,extends:…,nbsp:‗
else
" xterm + terminus hates these
set list listchars=tab:»·,trail:·,extends:>,nbsp:_
endif
else
set list listchars=tab:»·,trail:·,extends:…
endif
else
if v:version >= 700
set list listchars=tab:>-,trail:.,extends:>,nbsp:_
else
set list listchars=tab:>-,trail:.,extends:>
endif
endif
"
" Plugins
"
" BufExplorer configuration
nmap <script> <silent> <unique> <Leader><Leader> :BufExplorer<CR>
let g:bufExplorerShowRelativePath=1
"let g:bufExplorerShowUnlisted=1
" Use The Silver Searcher https://github.com/ggreer/the_silver_searcher
if executable('ag')
" Use Ag over Grep
set grepprg=ag\ --nogroup\ --nocolor
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
let g:ackprg = 'ag --nogroup --nocolor --column'
endif
" ack.vim
nmap <silent> <unique> <Leader>a :Ack
nmap <silent> <unique> <Leader>as :AckFromSearch
nmap <silent> <unique> <Leader>af :AckFile
" CtrlP
let g:ctrlp_match_window = 'order:ttb,max:20'
" Tabularize
"if exists(':Tabularize')
" ^^^^^^^^^^^^ for some reason Tabularize hasn't loaded when Vim gets here
nmap <Leader>t= :Tabularize /=<CR>
vmap <Leader>t= :Tabularize /=<CR>
" key => value
nmap <Leader>t> :Tabularize /=><CR>
vmap <Leader>t> :Tabularize /=><CR>
" key: value
nmap <Leader>t: :Tabularize /:\zs<CR>
vmap <Leader>t: :Tabularize /:\zs<CR>
" Ruby symbols
nmap <Leader>ts :Tabularize /:/l1c0l0<CR>
vmap <Leader>ts :Tabularize /:/l1c0l0<CR>
" a few useful shortcuts - taken from https://github.com/lsdr/vim-folder/blob/master/_vimrc :)
command! Rehash source ~/.vimrc
command! Helptags helptags ~/.vim/doc
" syntastic
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 0
let g:syntastic_auto_loc_list = 0
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
" all the code below from https://github.com/garybernhardt/dotfiles/blob/master/.vimrc
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MULTIPURPOSE TAB KEY
" Indent if we're at the beginning of a line. Else, do completion.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
inoremap <s-tab> <c-n>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" OPEN FILES IN DIRECTORY OF CURRENT FILE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>e :edit %%
map <leader>v :view %%
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RENAME CURRENT FILE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'), 'file')
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
redraw!
endif
endfunction
map <leader>n :call RenameFile()<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MAPS TO JUMP TO SPECIFIC COMMAND-T TARGETS AND FILES
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <leader>t :CtrlP .<cr>
map <leader>T :CtrlPClearCache<CR>:CtrlP<CR>
map <leader>ga :CtrlP app/assets<cr>
map <leader>gga :CtrlP gulp/assets<cr>
map <leader>gc :CtrlP app/controllers<cr>
map <leader>gh :CtrlP app/helpers<cr>
map <leader>gm :CtrlP app/models<cr>
map <leader>gp :CtrlP app/presenters<cr>
map <leader>gS :CtrlP app/services<cr>
map <leader>gv :CtrlP app/views<cr>
map <leader>gC :CtrlP config<cr>
map <leader>gl :CtrlP lib<cr>
map <leader>gs :CtrlP spec<cr>
map <leader>ggf :topleft 100 :split Gemfile<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" PROMOTE VARIABLE TO RSPEC LET
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! PromoteToLet()
:normal! dd
" :exec '?^\s*it\>'
:normal! P
:.s/\(\w\+\) = \(.*\)$/let(:\1) { \2 }/
:normal ==
endfunction
:command! PromoteToLet :call PromoteToLet()
:map <leader>l :PromoteToLet<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RUNNING TESTS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! RunTests(filename)
" Write the file and run tests for the given filename
:w
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
if match(a:filename, '\.feature$') != -1
exec ":!script/features " . a:filename
else
if filereadable("script/test")
exec ":!script/test " . a:filename
elseif filereadable("Gemfile")
exec ":!bundle exec rspec --color " . a:filename
else
exec ":!rspec --color " . a:filename
end
end
endfunction
function! SetTestFile()
" Set the spec file that tests will be run for.
let t:grb_test_file=@%
endfunction
function! RunTestFile(...)
if a:0
let command_suffix = a:1
else
let command_suffix = ""
endif
" Run the tests for the previously-marked file.
let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\)$') != -1
if in_test_file
call SetTestFile()
elseif !exists("t:grb_test_file")
return
end
call RunTests(t:grb_test_file . command_suffix)
endfunction
function! RunTestFileNoRails()
let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\)$') != -1
if in_test_file
call SetTestFile()
:w
exec ":!rspec --color " . t:grb_test_file
end
endfunction
function! RunNearestTest()
let spec_line_number = line('.')
call RunTestFile(":" . spec_line_number . " -b")
endfunction
map <leader>s :call RunTestFile()<cr>
map <leader>S :call RunNearestTest()<cr>
map <leader>b :call RunTestFileNoRails()<cr>
map <leader>a :call RunTests('')<cr>
" map <leader>c :w\|:!script/features<cr>
" map <leader>w :w\|:!script/features --profile wip<cr>
" All functions bellow from https://github.com/vim-scripts/Specky
"
" When in ruby code or an rspec BDD file, try and search recursively through
" the filesystem (within the current working directory) to find the
" respectively matching file. (code to spec, spec to code.)
"
" This operates under the assumption that you've used chdir() to put vim into
" the top level directory of your project.
function! SpecSwitcher()
" If we aren't in a ruby or rspec file then we probably don't care
" too much about this function.
if &ft != 'ruby' && &ft != 'rspec'
call s:err( "Not currently in ruby or rspec mode." )
return
endif
" Ensure that we can always search recursively for files to open.
let l:orig_path = &path
set path=**
" Get the current buffer name, and determine if it is a spec file.
"
" /tmp/something/whatever/rubycode.rb ---> rubycode.rb
" A requisite of the specfiles is that they match to the class/code file,
" this emulates the eigenclass stuff, but doesn't require the same
" directory structures.
"
" rubycode.rb ---> rubycode_spec.rb
let l:filename = matchstr( bufname('%'), '[0-9A-Za-z_.-]*$' )
let l:is_spec_file = match( l:filename, '_spec.rb$' ) == -1 ? 0 : 1
if l:is_spec_file
let l:other_file = substitute( l:filename, '_spec\.rb$', '\.rb', '' )
else
let l:other_file = substitute( l:filename, '\.rb$', '_spec\.rb', '' )
endif
let l:bufnum = bufnr( l:other_file )
if l:bufnum == -1
" The file isn't currently open, so let's search for it.
execute 'find ' . l:other_file
else
" We've already got an open buffer with this file, just go to it.
execute 'buffer' . l:bufnum
endif
"execute 'set path=' . l:orig_path
endfunction
nnoremap <leader>. :call SpecSwitcher()<cr>
" Wrap the word under the cursor in quotes. If in ruby mode,
" cycle between quoting styles and symbols.
"
" variable -> "variable" -> 'variable' -> :variable
"
function! QuoteSwitcher()
let l:type = strpart( expand("<cWORD>"), 0, 1 )
let l:word = expand("<cword>")
if l:type == '"'
" Double quote to single
execute ":normal viWc'" . l:word . "'"
elseif l:type == "'"
if &ft == 'ruby' || &ft == 'rspec'
" Single quote to symbol
execute ':normal viWc:' . l:word
else
" Single quote to double
execute ':normal viWc"' . l:word . '"'
end
else
" Whatever to double quote
execute ':normal viWc"' . l:word . '"'
endif
" Move the cursor back into the cl:word
call cursor( 0, getpos('.')[2] - 1 )
endfunction
nnoremap <leader>qs :call QuoteSwitcher()<cr>