forked from lucashungaro/vimfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
431 lines (351 loc) · 13.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
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.
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,vendor/**,db/sphinx,log/**,tmp/**,public/uploads,coverage/**
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=light
" colorscheme morning
set background=dark
colorscheme badwolf
let g:sql_type_default = "mysql"
" Very magic regexes.
nnoremap / /\v
vnoremap / /\v
" OS X-like space bar to scroll.
" nnoremap <Space> <C-F>
" nnoremap <S-Space> <C-B>
" <Leader><space> turns off search highlighting.
nnoremap <Leader><space> :noh<CR>
" Kill trailing White Space
nnoremap <Leader>kws :%s/\s\+$//<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>
" http://vim.devth.com/put-paste-above-below
" http://stackoverflow.com/questions/1346737/how-to-paste-in-a-new-line-with-vim
nmap <leader>po o<Esc>p==
nmap <leader>pO O<Esc>p==
" 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
" ack.vim
nmap <silent> <unique> <Leader>a :Ack
nmap <silent> <unique> <Leader>as :AckFromSearch
nmap <silent> <unique> <Leader>af :AckFile
" Tabularize
"if exists(':Tabularize')
" ^^^^^^^^^^^^ for some reason Tabularize hasn't loaded when Vim gets here
" key = value
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 /=><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>
" key, value
nmap <Leader>t, :Tabularize /,<CR>
vmap <Leader>t, :Tabularize /,<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
" 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>
map <leader>gg :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 --drb " . a:filename
else
exec ":!rspec --color --drb " . 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('spec')<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>
nnoremap <leader>dq :%s/'\([^"\|^']*\)'/"\1"/<cr>
let g:ctrlp_custom_ignore = "vendor"
" let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_working_path_mode = 0
set runtimepath^=~/.vim/bundle/ctrlp.vim
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MAPS TO JUMP TO SPECIFIC CtrlP TARGETS AND FILES
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" map <leader>t :CtrlP .<cr>
" map <leader>T :CtrlP .<cr>
" map <leader>ga :CtrlP app/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>gv :CtrlP app/views<cr>
" map <leader>gC :CtrlP config<cr>
" map <leader>gl :CtrlP lib<cr>
" map <leader>gs :CtrlP spec<cr>
" NERDCommenter
let NERDDefaultNesting = 0
let NERDSpaceDelims = 1
let NERDRemoveExtraSpaces = 1
" nmap gg=G gg=G``<CR>
map <Leader>ctall :!ctags --extra=+f -R *<CR><CR>
map <Leader>ct :!ctags --extra=+f -R app/<CR><CR>