-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
303 lines (245 loc) · 8.18 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
""" BASIC OPTIONS
set nocompatible
set hidden
set number
set ruler
set expandtab
set tabstop=2
set shiftwidth=2
set autoindent
set smartindent
set noswapfile
set nowrap
set wildmode=list:longest
set laststatus=2
set backspace=indent,eol,start
""" LEADER SETUP
let mapleader=','
""" SET THE COLORSCHEME
if !has('gui_running')
set t_Co=256
set noesckeys
runtime! bundle/guicolorscheme.vim/plugin/guicolorscheme.vim
GuiColorScheme gmolokai
endif
""" LOAD UP ADDITIONAL PLUGINS
filetype off
silent! call pathogen#runtime_append_all_bundles()
silent! call pathogen#helptags()
runtime ftplugin/man.vim
""" AUTO SYNTAX HIGHLIGHT
syntax enable
filetype indent on
filetype plugin on
compiler ruby
""" ENABLE PARENTHESIS COLORS
au Syntax ruby,javascript RainbowParenthesesLoadRound
au Syntax ruby,javascript RainbowParenthesesLoadSquare
au Syntax ruby,javascript RainbowParenthesesLoadBraces
au VimEnter * RainbowParenthesesToggle
""" SPLIT OPTIONS
set splitright
set splitbelow
""" HIGHLIGHT SEARCHES
set incsearch
""" SET THE CODE FOLDING OPTIONS
set foldmethod=syntax
set foldlevel=3
set foldminlines=1
autocmd InsertEnter * if !exists('w:last_fdm') | let w:last_fdm=&foldmethod | setlocal foldmethod=manual | endif
autocmd InsertLeave,WinLeave * if exists('w:last_fdm') | let &l:foldmethod=w:last_fdm | unlet w:last_fdm | endif
""" SYNTAX FOLD XML
let g:xml_syntax_folding=1
autocmd FileType xml setlocal foldmethod=syntax
""" FIX HTML INDENT
let g:html_indent_inctags="html,body,head,tbody,script,p,li"
""" DISABLE JSON QUOTE CONCEALING
let g:vim_json_syntax_conceal = 0
""" SET SOME FILETYPES BASED ON NAME
autocmd BufNewFile,BufRead Gemfile set filetype=ruby
autocmd BufNewFile,BufRead Guardfile set filetype=ruby
autocmd BufNewFile,BufRead *.es6 set filetype=javascript
""" SET SPELL CHECKING
autocmd FileType cucumber,markdown setlocal spell spelllang=en_gb
""" RUNNING TESTS
autocmd FileType ruby,eruby,haml,cucumber,yaml map <silent> <buffer> <leader>t :call SaveAndRunSpecs(expand('%:p'))<CR>
autocmd FileType ruby,eruby,haml,cucumber,yaml map <silent> <buffer> <leader>T :call SaveAndRunSpecs(expand('%:p'), line('.'))<CR>
function! SaveAndRunSpecs(...)
exec 'w'
let run_single_spec = exists('a:2')
let is_spec_file = IsSpecFile(a:1)
let infered_spec_file = is_spec_file ? a:1 : InferSpecFile(a:1)
if is_spec_file && run_single_spec
let g:spec_file_to_run = infered_spec_file
let g:spec_line_to_run = infered_spec_file . ':' . a:2
call ExecuteSpecCommand(g:spec_line_to_run)
elseif exists('g:spec_line_to_run') && run_single_spec
call ExecuteSpecCommand(g:spec_line_to_run)
elseif filereadable(infered_spec_file)
let g:spec_file_to_run = infered_spec_file
call ExecuteSpecCommand(g:spec_file_to_run)
elseif exists('g:spec_file_to_run')
call ExecuteSpecCommand(g:spec_file_to_run)
else
return
endif
endfunction
function! IsSpecFile(path)
return a:path =~ '\(_spec\.rb\|\.feature\)' ? 1 : 0
endfunction
function! ExecuteSpecCommand(path)
let binary = a:path =~ '_spec\.rb' ? 'rspec' : 'cucumber'
let options = has('gui_running') ? ' --no-color ' : ' --color '
exec '!bundle exec ' . binary . options . a:path
endfunction
""" INFER A SPEC FILENAME FROM A SOURCE FILENAME
function! InferSpecFile(path)
let spec = substitute(a:path, '\.rb', '_spec.rb', '')
if a:path =~ '\/app\/'
return substitute(spec, '\/app\/', '/spec/', '')
elseif a:path =~ '\/lib\/'
let non_lib_spec = substitute(spec, '\/lib\/', '/spec/', '')
let inc_lib_spec = substitute(spec, '\/lib\/', '/spec/lib/', '')
if filereadable(non_lib_spec)
return non_lib_spec
elseif filereadable(inc_lib_spec)
return inc_lib_spec
else
echoerr 'Unable to infer path for spec file'
endif
endif
endfunction
""" INFER A SOURCE FILENAME FROM A SPEC FILENAME
function! InferSourceFile(path)
if a:path =~ '\/spec\/'
let source = substitute(a:path, '_spec\.rb$', '.rb', '')
let app_path = substitute(source, '\/spec\(\/app\)\?\/', '/app/', '')
let lib_path = substitute(source, '\/spec\(\/lib\)\?\/', '/lib/', '')
if filereadable(app_path)
return app_path
elseif filereadable(lib_path)
return lib_path
else
echoerr 'Unable to infer path for source file'
endif
endif
endfunction
""" JUMP TO SPEC FROM SOURCE AND VICE-VERSA
autocmd FileType ruby,eruby,haml,cucumber,yaml map <silent> <buffer> <leader>j :call JumpToReciprocal(expand('%:p'))<CR>
function! JumpToReciprocal(path)
let reciprocal = IsSpecFile(a:path) ? InferSourceFile(a:path) : InferSpecFile(a:path)
if filereadable(reciprocal)
call fuf#openFile(reciprocal, 3, 1)
endif
endfunction
""" SET AND UNSET SPEC FOCUS
autocmd FileType ruby map <silent> <buffer> <leader>sf :call ToggleSpecFocus()<CR>
function! ToggleSpecFocus()
let rexp = ', :focus => true do'
let line = getline('.')
if line =~ rexp . '$'
call setline('.', substitute(line, rexp, ' do', ''))
else
call setline('.', substitute(line, ' do$', rexp, ''))
end
endfunction
""" SET WHITESPACE HIGHLIGHT
highlight PoxyTabs ctermbg=cyan guibg=cyan
autocmd Syntax * syn match PoxyTabs /\t/ containedin=ALL
autocmd ColorScheme * highlight PoxyTabs ctermbg=cyan guibg=cyan
autocmd FileType diff,help,man syntax clear PoxyTabs
highlight PoxySpaces ctermbg=red guibg=red
autocmd Syntax * syn match PoxySpaces /\s\+$/ containedin=ALL
autocmd ColorScheme * highlight PoxySpaces ctermbg=red guibg=red
autocmd FileType diff,help,man syntax clear PoxySpaces
""" CUSTOM LEADER MAPS
map <silent> <leader>l :set list!<CR>
map <silent> <leader>n :set number<CR>
map <silent> <leader>N :set relativenumber<CR>
""" CUSTOM FORMAT FUNCTION
map <silent> <leader>f :call FormatFile()<CR>
function! FormatFile()
norm myHmz
exec 'retab'
exec '%s/\s*$//ge'
norm gg=G
norm `zzt`y
redraw!
endfunction
""" AUTO CREATE DIRECTORIES ON SAVE
autocmd BufWritePre * if expand("<afile>")!~#'^\w\+:/' && !isdirectory(expand("%:h")) | execute "silent! !mkdir -p ".shellescape(expand('%:h'), 1) | redraw! | endif
""" OTHER REMAPS
map <silent> <leader>Q :%s/\"/\'/g<CR>
map <silent> <leader>q :%s/\"/\'/gc<CR>
""" COMMAND ALIASES
command -nargs=* -complete=file -bang MoveTo call Rename(<q-args>, '<bang>')
cabbrev mv <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'MoveTo' : 'mv')<CR>
""" CONFIGURE FUZZYFINDER AND COMMAND-T
let g:fuf_coveragefile_exclude = '\v\~$|\.(o|exe|dll|bak|orig|swp)$|(^|[/\\])(\.hg|\.git|\.bzr|node_modules|__pycache__)($|[/\\])'
set wildignore+=*.o,*.obj,**/node_modules/**,**/dist/**
map <silent> <leader>e :call CmdTOpenCurrent()<CR>
map <silent> <leader>v :call CmdTOpenVsplit()<CR>
map <silent> <leader>h :call CmdTOpenHsplit()<CR>
function! CmdTOpenCurrent()
exec 'CtrlP'
endfunction
function! CmdTOpenVsplit()
exec 'vnew'
exec 'CtrlP'
endfunction
function! CmdTOpenHsplit()
exec 'new'
exec 'CtrlP'
endfunction
function! FufOpenCurrent()
let g:fuf_keyOpen='<CR>'
let g:fuf_keyOpenVsplit=''
let g:fuf_keyOpenSplit=''
exec 'FufRenewCache'
exec 'FufCoverageFile'
endfunction
function! FufOpenVsplit()
let g:fuf_keyOpen=''
let g:fuf_keyOpenVsplit='<CR>'
let g:fuf_keyOpenSplit=''
exec 'FufRenewCache'
exec 'FufCoverageFile'
endfunction
function! FufOpenHsplit()
let g:fuf_keyOpen=''
let g:fuf_keyOpenVsplit=''
let g:fuf_keyOpenSplit='<CR>'
exec 'FufRenewCache'
exec 'FufCoverageFile'
endfunction
if has('gui_running')
set guioptions=-t
colorscheme gmolokai
if has('gui_win32')
autocmd GUIEnter * :simalt ~x
set guifont=Consolas:h10
set backspace=2
end
if has('gui_macvim')
set guifont=Consolas:h13
autocmd GUIEnter * set fullscreen
set columns=9999
endif
if has('x11')
vmap <C-c> "+yi
vmap <C-x> "+c
vmap <C-v> c<ESC>"+p
imap <C-v> <C-r><C-o>+
set columns=9999 lines=9999
endif
endif
""" OVERLENGTH LINES 80 CHARS
highlight OverLength guibg=#5f6061
match OverLength /\%<81v.\%>80v/
""" SESSION SAVE AND RESTORE
map <silent> <leader>ss :mksession! .session<CR>
map <silent> <leader>rs :source .session<CR>
""" WHATS THAT SYNTAX GROUP
map <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>