-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvimrc
executable file
·334 lines (281 loc) · 9.14 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
set nocompatible
syntax on
set encoding=utf-8
set tabstop=2
set smarttab
set shiftwidth=2
set autoindent
set expandtab
set hidden
set cursorline
set number
set scrolloff=3
set laststatus=2
set statusline=%<%f\ %h%w%m%r%y%=L:%l/%L\ (%p%%)\ C:%c
set t_Co=16
set background=dark
colorscheme neodark
let g:airline_theme='neodark'
let g:nord_cursor_line_number_background = 1
" don't leave backup files scattered about.
set updatecount=0
set nobackup
set nowritebackup
set noswapfile
set nowrap "no text wrapping
set selectmode=key "shifted arrows for selection
set foldcolumn=0 "little space on the left.
set softtabstop=2
set ai "auto indent
set hlsearch
set incsearch
set ignorecase
set smartcase
set foldlevel=1
set nofoldenable
command! W :w
" fast nav
map <leader>j 15j<CR>
map <leader>k 15k<CR>
" Tab completion
set wildmode=list:longest,list:full
set wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/*
" NERDTree Setup
map <leader>d :execute 'NERDTreeToggle ' . getcwd()<CR>
" ctrlp.vim
map <leader>f :CtrlP<CR>
map <leader>b :CtrlPBuffer<CR>
" gundo config
nnoremap <leader>r :GundoToggle<CR>
let g:gundo_preview_height = 30
" Map ,e and ,v to open files in the same directory as the current file
cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>e :edit %%
map <leader>v :view %%
" ways to clear the search highlighting
map <leader><space> :nohlsearch<CR>
" fast switching between two recent buffers
nnoremap <leader><leader> <C-^>
" Map a shortcut to close a buffer
map <leader>. :bd<CR>
" Shortcut for viewing open buffers
map <leader>m :BufExplorer<CR>
" use ,v to make a new vertical split, ,s for horiz, ,x to close a split
noremap <leader>v <c-w>v<c-w>l
noremap <leader>s <c-w>s<c-w>j
noremap <leader>x <c-w>c"
" use ctrl-h/j/k/l to switch between splits
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l
map <c-h> <c-w>h
" go hardcore on not using the arrow keys for nav
map <Left> :echo "no!"<cr>
map <Right> :echo "no!"<cr>
map <Up> :echo "no!"<cr>
map <Down> :echo "no!"<cr>
let clj_highlight_builtins = 1
au FileType make set noexpandtab
" json syntax
au BufRead,BufNewFile *.json set filetype=json
function s:setupWrapping()
set formatoptions+=aw
set textwidth=80
set spell
endfunction
" options for test and markdown files
au BufRead,BufNewFile *.{txt} call s:setupWrapping()
au BufRead,BufNewFile {Gemfile,Rakefile,Vagrantfile,Thorfile,config.ru,Guardfile} set ft=ruby
au FileType python set softtabstop=4 tabstop=4 shiftwidth=4 textwidth=79
au FileType go set softtabstop=2 tabstop=2 shiftwidth=2 textwidth=79
" Elixir file types
au BufRead,BufNewFile *.ex,*.exs set filetype=elixir
au BufRead,BufNewFile *.eex,*.heex,*.leex,*.sface,*.lexs set filetype=eelixir
au BufRead,BufNewFile mix.lock set filetype=elixir
" Super nice pipe alignment while defining cucumber tables
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize/|/l1
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
endif
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Running tests
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" In Place Running
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\|_test.py\)$') != -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! RunNearestTest()
let spec_line_number = line('.')
call RunTestFile(":" . spec_line_number)
endfunction
function! SetTestFile()
" Set the spec file that tests will be run for.
let t:grb_test_file=@%
endfunction
function! RunTests(filename)
" Write the file and run tests for the given filename
if expand("%") != ""
:w
end
if match(a:filename, '\.feature$') != -1
exec ":!script/features " . a:filename
else
" First choice: project-specific test script
if filereadable("script/test")
exec ":!script/test " . a:filename
" Fall back to the .test-commands pipe if available, assuming someone
" is reading the other side and running the commands
elseif filewritable(".test-commands")
let cmd = 'rspec --color --format progress --require "~/lib/vim_rspec_formatter" --format VimFormatter --out tmp/quickfix'
exec ":!echo " . cmd . " " . a:filename . " > .test-commands"
" Write an empty string to block until the command completes
sleep 100m " milliseconds
:!echo > .test-commands
redraw!
" Fall back to a blocking test run with Bundler
elseif filereadable("Gemfile")
exec ":!bundle exec rspec --color " . a:filename
" If we see python-looking tests, assume they should be run with Nose
elseif strlen(glob("test/**/*.py") . glob("tests/**/*.py"))
exec "!nosetests " . a:filename
" Fall back to a normal blocking test run
else
exec ":!rspec --color " . a:filename
end
end
endfunction
map <leader>u :call RunTestFile()<cr>
map <leader>U :call RunNearestTest()<cr>
map <leader>a :call RunTests('')<cr>
" Dispatch Running
function! DispatchRunTestFile(...)
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\|_test.py\)$') != -1
if in_test_file
call DispatchSetTestFile()
elseif !exists("t:dispatch_test_file")
return
end
call DispatchRunTests(t:dispatch_test_file . command_suffix)
endfunction
function! DispatchRunNearestTest()
let spec_line_number = line('.')
call DispatchRunTestFile(":" . spec_line_number)
endfunction
function! DispatchSetTestFile()
" Set the spec file that tests will be run for.
let t:dispatch_test_file=@%
endfunction
function! DispatchRunTests(filename)
" Write the file and run tests for the given filename
if expand("%") != ""
:w
end
if match(a:filename, '\.feature$') != -1
exec ":Focus cucumber " . a:filename
else
exec ":Focus rspec --color " . a:filename
end
exec ":Dispatch"
endfunction
map <leader>t :call DispatchRunTestFile()<cr>
map <leader>T :call DispatchRunNearestTest()<cr>
" whitespace killer http://sartak.org/2011/03/end-of-line-whitespace-in-vim.html
set list
set listchars=tab:\ \ ,trail:·
function! <SID>StripTrailingWhitespace()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
%s/\s\+$//e
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
nmap <silent> <Leader>w :call <SID>StripTrailingWhitespace()<CR>
if filereadable(expand("~/.vimrc.local"))
source ~/.vimrc.local
endif
let g:rails_projections = {
\ "config/projections.json": {
\ "command": "projections"
\ },
\ "spec/features/*_spec.rb": {
\ "command": "feature",
\ "template": "require 'spec_helper'\n\nfeature '%h' do\n\nend",
\ },
\ "features/*.feature" : {
\ "command" : "feature"
\ },
\ "features/step_definitions/*_steps.rb" : {
\ "command" : "steps"
\ },
\ "app/uploaders/*_uploader.rb" : {
\ "command" : "uploader"
\ },
\ "app/reports/*.rb" : {
\ "command" : "report"
\ },
\ "app/importers/*.rb" : {
\ "command" : "import"
\ },
\ "app/exporters/*.rb" : {
\ "command" : "export"
\ },
\ "app/jobs/*.rb" : {
\ "command" : "worker"
\ },
\ "app/workers/*.rb" : {
\ "command" : "worker"
\ },
\ "spec/factories/*.rb": {
\ "command": "factory",
\ "affinity": "collection",
\ "alternate": "app/models/%i.rb",
\ "related": "db/schema.rb#%s",
\ "test": "spec/models/%i_test.rb",
\ "template": "FactoryGirl.define do\n factory :%i do\n end\nend",
\ "keywords": "factory sequence"
\ },
\ "spec/factories.rb": {
\ "command": "factory"
\ }}
let g:rails_gem_projections = {
\ "active_model_serializers": {
\ "app/serializers/*_serializer.rb": {
\ "command": "serializer",
\ "affinity": "model",
\ "test": "spec/serializers/%s_spec.rb",
\ "related": "app/models/%s.rb",
\ "template": "class %SSerializer < ActiveModel::Serializer\nend"
\ }
\ }}
" Optional, configure as-you-type completions
set completeopt=menu,menuone,preview,noselect,noinsert
let g:mix_format_on_save = 1