-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
417 lines (332 loc) · 10.6 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
call pathogen#runtime_append_all_bundles()
set guifont=monaco:h13
set nocompatible
set backspace=indent,eol,start " allow backspacing over everything in insert mode
set history=50 " keep 50 lines of command line history
set hidden " you can change buffers without saving
set nobackup
set nowrap " Don't wrap text
set scrolloff=2 " Keep 2 lines top/bottom visible for scope
set shiftwidth=2
set tabstop=2
set expandtab
set showcmd " display incomplete commands
set incsearch " do incremental searching
set smartcase " case sensitive only if search contains uppercase
set ignorecase " Needs to be present for smartcase to work as intended
set wildmenu " :e tab completion file browsing
set wildmode=list:longest,full " List all matches on first TAB, complete/cycle on second TAB
set cf " Enable error files & error jumping.
set listchars=tab:>-,trail:.,eol:$
set vb " turns off visual bell
set splitbelow " Open new horizontal split windows below current
set splitright " Open new vertical split windows to the right
set laststatus=2 " Always show status line
set ruler " show the cursor position in the status line
set cursorline " Highlight current line
set cursorcolumn " Highlight current column
set number " turn on line numbers
set formatoptions=rq " Automatically insert comment leader on return, and let gq format comments
set autoread " Don't prompt to reread the file if it is unchanged in the editor but modified externally.
" fuck scrollbars
set guioptions-=L
set guioptions-=r
set cc=120
" use cool invisible characters
"set listchars=tab:▸\ ,eol:¬
set listchars=tab:➟\ ,eol:⤦
" use cool invisible characters
" set listchars=tab:▸\ ,eol:¬
" set listchars=tab:➟\ ,eol:⤦
" Store temporary files in a central spot
set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/tmp
set directory=~/.vim-tmp,~/.tmp,~/tmp,/tmp
colorscheme slate2
if !exists("autocommands_loaded")
let autocommands_loaded = 1
let project_path = getcwd()
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
if has("gui_running")
colorscheme ir_black
set cc=80 " show a wrap column
set go-=T " keep MacVim toolbar hidden
set guioptions-=rL " fuck scrollbars
set fuoptions=maxvert,maxhorz " fullscreen maximizes vertically AND horizontally
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
"Reload vimrc on write. Nice if it was opened within a tab/window of the same
"vim instance
autocmd! bufwritepost .vimrc source %
" kill trailing spaces when exiting file
"autocmd BufWritePre * :%s/\s\+$//e
autocmd! bufwritepost *.rb silent call UpdateTags()
autocmd! VimLeave * :!rm ~/.yankring_history_v2.txt
"Always change to directory of current file
"autocmd BufEnter * lcd %:p:h
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
let Tlist_Ctags_Cmd = "/opt/local/bin/ctags"
let Tlist_WinWidth = 50
"==================="
" Keyboard Mappings "
"==================="
let mapleader=","
" Don't use Ex mode, use Q for formatting
"map Q gq
" Split Edit / Reload Vim Config
map <leader>v :tabnew $MYVIMRC<CR>
map <leader>V :source $MYVIMRC<CR>
" Switch between windows
map <C-J> <C-W>j
map <C-K> <C-W>k
map <C-H> <C-W>h
map <C-L> <C-W>l
" swap windows
map <leader>ww <C-W>x
" Toggle display of characters for whitespace
map <silent> <leader>s :set nolist!<CR>
"Execute current file
"map <leader>r :! %:p<CR>
"Write then Execute current file
map <leader>x :w<CR>:! %:p<CR>
"Copy path to clipboard
nmap <leader>cp :call CopyPathToClipboard()<CR>
" Run tests
nmap <leader>tt :call TestCommand()<CR>
nmap <leader>sc :call SpecCommand()<CR>
nmap <leader>tc :call TestContext()<CR>
nmap <leader>tf :call TestFile()<CR>
"nnoremap <leader>t :call RunAllTests('')<cr>:redraw<cr>:call JumpToError()<cr>
"nnoremap <leader>T :call RunAllTests('')<cr>
map <leader>nt :NERDTreeToggle<CR>
map <leader>nf :NERDTreeFind<CR>
map <leader>tl :Tlist<CR>
map <leader>fa :call VimGrep()<CR>
map <leader>ft :FufTag<CR>
map <leader>ff :CommandT<CR>
" TABS: Firefox style, open tabs with command-<tab number>
map <silent> <D-1> :tabn 1<CR>
map <silent> <D-2> :tabn 2<CR>
map <silent> <D-3> :tabn 3<CR>
map <silent> <D-4> :tabn 4<CR>
map <silent> <D-5> :tabn 5<CR>
map <silent> <D-6> :tabn 6<CR>
map <silent> <D-7> :tabn 7<CR>
map <silent> <D-8> :tabn 8<CR>
map <silent> <D-9> :tabn 9<CR>
" bind command-] to shift right
nmap <D-]> >>
vmap <D-]> >>
imap <D-]> <C-O>>>
" use jj for esc
imap jj <Esc>
" bind command-[ to shift left
nmap <D-[> <<
vmap <D-[> <<
imap <D-[> <C-O><<
" bind command-/ to toggle comment (requires tComment)
nmap <D-/> <C-_><C-_>
vmap <D-/> <C-_><C-_>
imap <D-/> <C-O><C-_><C-_>
command! W w !sudo tee % > /dev/null
"use function! to overwrite when resourcing the vimrc
function! CopyPathToClipboard()
let @* = expand('%')
echo "Copied to clipboard: ".@*
endfunction
function! TestCommand()
let @* = "rspec ".expand('%').":".line(".")
echo "Copied to clipboard: ".@*
endfunction
function! TestCommand()
let @* = "ruby -Ttest ".expand('%')
echo "Copied to clipboard: ".@*
endfunction
function! TestContext()
if executable("rspec")
let command = "!rspec ".expand('%:p').":".line(".")
else
let command = "!spec ".expand('%:p').":".line(".")
endif
:execute command
endfunction
function! TestFile()
if executable("rspec")
!rspec %
else
!spec %
endif
endfunction
function! WriteRun()
w | ! %:p
endfunction
function! RunTests(target, args)
silent ! echo
exec 'silent ! echo -e "\033[1;36mRunning tests in ' . a:target . '\033[0m"'
silent w
exec "make " . a:target . " " . a:args
endfunction
function! ClassToFilename(class_name)
let understored_class_name = substitute(a:class_name, '\(.\)\(\u\)', '\1_\U\2', 'g')
let file_name = substitute(understored_class_name, '\(\u\)', '\L\1', 'g')
return file_name
endfunction
function! ModuleTestPath()
let file_path = @%
let components = split(file_path, '/')
let path_without_extension = substitute(file_path, '\.rb$', '', '')
let test_path = 'tests/unit/' . path_without_extension
return test_path
endfunction
function! NameOfCurrentClass()
let save_cursor = getpos(".")
normal $<cr>
"call RubyDec('class', -1)
let line = getline('.')
call setpos('.', save_cursor)
let match_result = matchlist(line, ' *class \+\(\w\+\)')
let class_name = ClassToFilename(match_result[1])
return class_name
endfunction
function! TestFileForCurrentClass()
let class_name = NameOfCurrentClass()
let test_file_name = ModuleTestPath() . '/test_' . class_name . '.rb'
return test_file_name
endfunction
function! TestModuleForCurrentFile()
let test_path = ModuleTestPath()
let test_module = substitute(test_path, '/', '.', 'g')
return test_module
endfunction
function! RunTestsForFile(args)
if @% =~ 'test_'
call RunTests('%', a:args)
else
let test_file_name = TestModuleForCurrentFile()
call RunTests(test_file_name, a:args)
endif
endfunction
function! RunAllTests(args)
silent ! echo
silent ! echo -e "\033[1;36mRunning all unit tests\033[0m"
silent w
exec "make!" . a:args
endfunction
function! JumpToError()
if getqflist() != []
for error in getqflist()
if error['valid']
break
endif
endfor
let error_message = substitute(error['text'], '^ *', '', 'g')
silent cc!
exec ":sbuffer " . error['bufnr']
call RedBar()
echo error_message
else
call GreenBar()
echo "All tests passed"
endif
endfunction
function! RedBar()
hi RedBar ctermfg=white ctermbg=red guibg=red
echohl RedBar
echon repeat(" ",&columns - 1)
echohl
endfunction
function! GreenBar()
hi GreenBar ctermfg=white ctermbg=green guibg=green
echohl GreenBar
echon repeat(" ",&columns - 1)
echohl
endfunction
function! VimGrep()
let pattern = input("Search Pattern: ")
let filePattern = input("File Pattern: ")
let cmd = ':noautocmd vimgrep /'.pattern.'/gj ./**/'.filePattern
"let cmd = ':grep -Er "'.pattern.'" app api lib public script spec'
exe cmd
cw
endfunction
command! -nargs=* -complete=command DiffCheck call DiffCheck(<f-args>)
function! DiffCheck(...)
setlocal errorformat=%f
let tmpfile = tempname()
let g:startspec = a:0 == 1 ? a:1 : ""
let g:endspec = a:0 == 1 ? "HEAD" : ""
let g:startspec = a:0 == 2 ? a:1 : g:startspec
let g:endspec = a:0 == 2 ? a:2 : g:endspec
let refspec = g:startspec." ".g:endspec
exe ":!git diff --name-only ".refspec."> ".tmpfile
exe ":cf " . tmpfile
cw
endfunction
command! -complete=command Gd call GitDiff()
function! GitDiff()
exec ":Gdiff ".g:startspec
endfunction
command! -complete=command Gdp call GitDiffPrev()
function! GitDiffPrev()
wincmd k
close
cp
call GitDiff()
botright cw 10
endfunction
command! -complete=command Gdn call GitDiffNext()
function! GitDiffNext()
wincmd k
close
cn
call GitDiff()
botright cw 10
endfunction
let g:enableTags = 0
command! -complete=command EnableTags call EnableTags()
function! EnableTags()
let g:enableTags = 1
endfunction
function! UpdateTags()
if g:enableTags == 1
:execute ':!ctags -f '.g:project_path.'/tags -R '.g:project_path.'/ *.rb &'
":Rtags "Possilbe alternative but dependend on Rails plugin and being rails project.
endif
endfunction
function! TabMessage(cmd)
redir => message
silent ! a:cmd
redir END
tabnew
silent put=message
set nomodified
endfunction
" Create custom command for Function
command! -nargs=+ -complete=command TabMessage call TabMessage(<q-args>)
so ~/.vim/ruby-refactoring.vim