-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path.vimrc
More file actions
327 lines (286 loc) · 10.3 KB
/
.vimrc
File metadata and controls
327 lines (286 loc) · 10.3 KB
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
set nocompatible
call plug#begin('~/.vim/plugged')
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'junegunn/fzf', { 'do': './install --all' }
Plug 'junegunn/vim-easy-align' " horizontal aligning
Plug 'junegunn/seoul256.vim' " Color scheme
Plug 'Raimondi/delimitMate' " Adds auto pairing of ', [, etc.
Plug 'mattn/emmet-vim'
Plug 'mattn/gist-vim'
Plug 'twitvim/twitvim'
Plug 'therubymug/vim-pyte' " Theme
Plug 'will133/vim-dirdiff'
Plug 'tpope/vim-fugitive' " Git blame integration
Plug 'tpope/vim-surround'
Plug 'tpope/vim-abolish' " Smart case-sensitive search and replace
Plug 'tpope/vim-repeat'
Plug 'pangloss/vim-javascript'
Plug 'jelera/vim-javascript-syntax' " Support for ES6 keywords, operators, etc.
Plug 'sickill/vim-pasta' " Make hashs, arrays, etc aligned nicely when pasting
Plug 'christoomey/vim-system-copy'
Plug 'christoomey/vim-rfactory'
Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/vim-vsnip-integ'
Plug 'rafamadriz/friendly-snippets' " preconfigured snippets to work with vim-vsnip
Plug 'Julian/vim-textobj-brace' " edit inside of [] and {}
Plug 'kana/vim-textobj-indent'
Plug 'kana/vim-textobj-user' " create custom text-objects
Plug 'nelstrom/vim-textobj-rubyblock' " easily select ruby constructs
Plug 'HerringtonDarkholme/w3m.vim'
Plug 'prettier/vim-prettier', { 'do': 'yarn install --frozen-lockfile --production' }
Plug 'djoshea/vim-autoread'
call plug#end()
filetype plugin indent on
runtime macros/matchit.vim " Enable built-in matchit plugin
let mapleader = ","
map <leader>nt :execute 'NERDTreeToggle ' . getcwd()<CR>
map <leader>nd :NERDTree %<CR>
map <leader>ns :setlocal nospell<CR>
map <leader>ss :setlocal spell<CR>
map <leader>nl :set invnumber<CR>
map <leader>em <C-y>, " Emmit.vim modes
map <Leader>vi :tabe ~/.vimrc<CR>
map <Leader>np :set nopaste<CR>
map <Leader>vr :rightbelow vnew
map <Leader>vf :rightbelow vnew test/factories/
map <Leader>rf :rightbelow vnew spec/factories/
map <Leader>wd :set textwidth=78<CR>
map <Leader>ww ggVG<CR> " Visual block the whole page
map <Leader>wv ggVGgq<CR> " Format entire page with textwidth=78
map <Leader>rg :reg<CR>
map <Leader>cl :%s /\\\"//g<cr>:%s /"//g<cr>:call SqlFormat()<CR>
map <Leader>wq Vapgq<CR>
map <Leader>dt :w<cr>:call RunCurrentTest('ts dkrails rspec')<CR>
map <Leader>dl :w<cr>:call RunCurrentLineInTest('ts dkrails rspec')<CR>
map <Leader>st :w<cr>:call RunCurrentTest('ts bin/rspec')<CR>
map <Leader>sl :w<cr>:call RunCurrentLineInTest('ts bin/rspec')<CR>
map <Leader>rb :w<cr>:ts ruby %<CR>
map <Leader>rt :w<cr>:call RunCurrentTest('dkspec')<CR>
map <Leader>ra :ts be rake<CR>
map <Leader>rst :w<cr>:rst<CR>
map <Leader>rl :w<cr>:call RunCurrentLineInTest('dkspec')<CR>
map <Leader>rbp :w<cr>:execute '!rbprettier --write %'<CR>
map <Leader>rn :call RenameFile()<cr>
" Edit another file in the same directory as the current file
" uses expression to extract path from current file's path
map <Leader>ee :e <C-R>=expand("%:p:h") . '/'<CR>
map <Leader>se :split <C-R>=expand("%:p:h") . '/'<CR>
map <Leader>ve :vnew <C-R>=expand("%:p:h") . '/'<CR>
" Select just pasted text
nnoremap gp `[v`]`
" allow aliases when shelling out
set shell=bash
let $BASH_ENV = "~/.bash/aliases"
set rtp+=/usr/local/opt/fzf
set ssop-=options " do not store global and local values in a session"
" Indenting options
set comments +=fb:*,fb:[-],fb:[+],fb:>>,fb:[1],fb:[2],fb:[3],fb:[4],fb:[5],fb:[6],n::
set fo +=n2
set backspace=indent,eol,start " allow backspacing over everything in insert mode
set noswapfile
set nobackup " do not keep a backup file, use versions instead
set history=500 " keep 500 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
set complete+=kspell
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
set autoindent
set winheight=999 " new window always opens fully expanded
set ignorecase
set smartcase "overrides ignorecase if uppercase used
set hlsearch
syntax on
set autoread
set number
set scrolljump=5
set scrolloff=3
set nofoldenable " Say no to code folding...
" let $BASH_ENV = "~/.bash_profile"
let $FZF_DEFAULT_COMMAND = 'ag -g ""'
map <C-h> :nohl<cr>
map <C-s> <esc>:w<CR>
imap <C-s> <esc>:w<CR>
nnoremap Y y$ " Make 'Y' consistent with 'C' & 'D'
set wmh=0 " split don't have that xtra line
map <leader>w <c-w>w " Switch/toggle between split windows
map <leader>h <c-w>h<c-w><cr> " Go to left vertical split
map <leader>l <c-w>l<c-w><cr> " Go to right vertical split
map <S-j> <C-W>j<C-W>_ " Map up and down to horizontal split
map <S-k> <C-W>k<C-W>_
map <S-l> gt " remap the tab movement
map <S-h> gT
let g:lasttab = 1 " ---- Toggle between the last two active tabs
nmap <Leader>t :exe "tabn ".g:lasttab<CR>
au TabLeave * let g:lasttab = tabpagenr()
" ---- Show tab number on the tabline
if exists("+showtabline")
function! MyTabLine()
let s = ''
let t = tabpagenr()
let i = 1
while i <= tabpagenr('$')
let buflist = tabpagebuflist(i)
let winnr = tabpagewinnr(i)
let s .= '%' . i . 'T'
let s .= (i == t ? '%1*' : '%2*')
let s .= ' '
let s .= i . ')'
"let s .= winnr . '/' . tabpagewinnr(i,'$')
let s .= ' %*'
let s .= (i == t ? '%#TabLineSel#' : '%#TabLine#')
let file = bufname(buflist[winnr - 1])
let file = fnamemodify(file, ':p:t')
if file == ''
let file = '[No Name]'
endif
let s .= file
let i = i + 1
endwhile
let s .= '%T%#TabLineFill#%='
let s .= (tabpagenr('$') > 1 ? '%999XX' : 'X')
return s
endfunction
set stal=2
set tabline=%!MyTabLine()
endif
vmap <leader><Bar> :EasyAlign*<Bar><Enter> " Align GitHub-flavored Markdown tables
map Q gq
"""""""""
" vsnip setup
""""""""
" Expand
imap <expr> <C-j> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-j>'
smap <expr> <C-j> vsnip#expandable() ? '<Plug>(vsnip-expand)' : '<C-j>'
" If you want to use snippet for multiple filetypes, you can `g:vsnip_filetypes` for it.
let g:vsnip_filetypes = {}
let g:vsnip_filetypes.ruby = ['rails']
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Test-running stuff
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! Relpath(filename)
let cwd = getcwd()
let s = substitute(a:filename, l:cwd . "/" , "", "")
return s
endfunction
function! RunCurrentTest(rspec_type)
let in_test_file = match(expand("%"), '\(_spec.rb\|_test.rb\)$') != -1
if in_test_file
call SetTestFile()
if match(expand('%'), '_test\.rb$') != -1
call SetTestRunner("ts bin/rails test")
exec '!' . g:bjo_test_runner . ' ' . g:bjo_test_file
elseif match(expand('%'), '_spec\.rb$') != -1
call SetTestRunner(a:rspec_type)
exec '!' . g:bjo_test_runner . ' ' . g:bjo_test_file
else
call SetTestRunner(a:rspec_type)
exec '!' . g:bjo_test_runner . ' ' . g:bjo_test_file
endif
else
exec '!' . g:bjo_test_runner . ' ' . g:bjo_test_file
endif
endfunction
function! SetTestRunner(runner)
let g:bjo_test_runner=a:runner
endfunction
function! RunCurrentLineInTest(rspec_type)
let in_test_file = match(expand("%"), '\(_spec.rb\|_test.rb\)$') != -1
if in_test_file
call SetTestFileWithLine()
if match(expand('%'), '_test\.rb$') != -1
call SetTestRunner("ts bin/rails test")
else
call SetTestRunner(a:rspec_type)
endif
end
exec '!' . g:bjo_test_runner . ' ' . g:bjo_test_file . ':' . g:bjo_test_file_line
endfunction
function! SetTestFile()
" Leave off the base path for Docker usage
let g:bjo_test_file=@ . expand('%:.')
endfunction
function! SetTestFileWithLine()
" Leave off the base path for Docker usage
let g:bjo_test_file=@ . expand('%:.')
let g:bjo_test_file_line=line(".")
endfunction
function! OpenFactoryFile()
if filereadable("test/factories.rb")
execute ":sp test/factories.rb"
else
execute ":sp spec/factories.rb"
end
endfunction
function! s:IsMacOS()
let os = substitute(system('uname'), '\n', '', '')
return has("gui_mac") || os ==? 'Darwin'
endfunction
fun! SetTextFile()
let in_minimul_dir = match(expand("%"), 'www\/minimul\/data') != -1
if in_minimul_dir
setlocal textwidth=0
return
else
setlocal textwidth=78
end
endfun
fun! TrimWhitespace()
let l:save = winsaveview()
keeppatterns %s/\s\+$//e
call winrestview(l:save)
endfun
if s:IsMacOS()
" Paste from clipboard. Only works on Mac. On Linux use system-copy plugin
map <Leader>pp :set paste<CR>o<esc>"*]p:set nopaste<CR>:retab<CR>
" map <Leader>cp :w<CR>exec ':silent !cat % | pbcopy'<CR>
end
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RENAME CURRENT FILE (thanks Gary Bernhardt)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
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
"""""""""""""""""""""""""""""""""
autocmd BufRead,BufNewFile ~/www/minimul/data/*/* set syntax=html
" Inspect the variable on the current line (in Ruby)
autocmd FileType ruby nmap ,i ^"oy$Iputs "<esc>A: #{<esc>"opA"<esc>
autocmd FileType text call SetTextFile() " For all text files set 'textwidth' to 78 characters.
autocmd BufRead,BufNewFile *.md setlocal spell
autocmd BufRead,BufNewFile *.thor set filetype=ruby
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
function SqlFormat()
set noai
exec ':%!sqlformat --reindent --keywords upper --identifiers lower -'
endfunction
function SqlFormatter()
map <Leader>sf :call SqlFormat()<CR>
endfunction
autocmd FileType sql call SqlFormatter()
" Use Silver Searcher instead of grep
set grepprg=ag
"
" " Get rid of the delay when hitting esc!
set noesckeys
" (Hopefully) removes the delay when hitting esc in insert mode
set noesckeys
set ttimeout
set ttimeoutlen=1
" let g:seoul256_background = 256
colo seoul256
" colo pyte
highlight Search guifg=Black guibg=Red gui=bold
" Highlight the status line
highlight StatusLine ctermfg=blue ctermbg=yellow