-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc.local
395 lines (341 loc) · 11.6 KB
/
vimrc.local
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
" vim:fdm=marker:
" Editor settings {{{
set hidden
set hlsearch
set nowrap
set list " show trailing spaces
" set cursorline
set nostartofline
" if v:version > 702
" set relativenumber
" set regexpengine=1
" endif
set scrolloff=3
set ttyfast
" set lazyredraw
" Uncomment the following to have Vim jump to the last position when
" reopening a file
" if has("autocmd")
" au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
" endif
" }}}
" Keyboard shortcuts {{{
nmap \ ,
nnoremap ' `
nnoremap ` '
inoremap jj <ESC>
noremap ,, <C-\><C-N>
noremap 0 ^
noremap 9 $
noremap! ,, <C-\><C-N>
snoremap ,, <C-\><C-N>
nnoremap <silent> <tab> :bn<cr>
nnoremap <silent> <s-tab> :bp<cr>
nnoremap <leader>w <C-W>
nnoremap <leader>= <C-W>=
nnoremap <leader>n :set number! number?<CR>
nnoremap <leader>rn :set rnu! rnu?<CR>
nnoremap <Leader>hl :set hlsearch! hlsearch?<CR>
nnoremap <Leader>ps :set paste! paste?<CR>
nnoremap <leader>iw :set invwrap wrap?<CR>
nnoremap <leader>ew :e <C-R>=expand('%:h').'/'<cr>
nnoremap <leader>es :sp <C-R>=expand('%:h').'/'<cr>
nnoremap <leader>ev :vsp <C-R>=expand('%:h').'/'<cr>
nnoremap <leader>et :tabe <C-R>=expand('%:h').'/'<cr>
nnoremap <leader>fc <ESC>/\v^[<=>]{7}( .*\|$)<CR>
nnoremap <leader>p obinding.pry<Esc>
nnoremap <leader>co oconsole.log();<Left><Left>
inoremap { {}<Left>
inoremap ' ''<Left>
inoremap " ""<Left>
inoremap ( ()<Left>
inoremap [ []<Left>
map <Down> gj
map <Up> gk
nmap <silent> <F4> :set invpaste<CR>:set paste?<CR>
imap <silent> <F4> <ESC>:set invpaste<CR>:set paste?<CR>
imap ,/ </<C-X><C-O>
nmap <Leader>rb :SlimuxShellRun bundle exec ruby -Itest <C-R>=expand("%:f")<CR><CR>
nmap <Leader>rl :SlimuxShellLast<CR>
nmap <Leader>rc :SlimuxShellConfigure<CR>
vmap <Enter> <Plug>(EasyAlign)
" nmap <leader>a <Plug>(EasyAlign)
" nnoremap <leader>u :GundoToggle<CR>
" After whitespace, insert the current directory into a command-line path
cnoremap <expr> <C-P> getcmdline()[getcmdpos()-2] ==# ' ' ? expand('%:p:h') : "\<C-P>"
" }}}
" Plugin settings {{{
let g:tagbar_autofocus=1
let g:tagbar_autoclose=1
let g:NERDTreeQuitOnOpen=1
let g:gitgutter_enabled=1
let g:gundo_close_on_revert=1
let g:ctrlp_user_command='ag %s -l --nocolor -g ""'
let g:ctrlp_cmd='CtrlPMixed'
let g:ycm_collect_identifiers_from_comments_and_strings=1
let g:buftabline_numbers=1
let g:buftabline_indicators=1
let g:user_emmet_settings = {
\ 'javascript.jsx' : {
\ 'extends': 'jsx'
\ },
\}
" }}}
" html auto completed {{{
"mes like *.xml, *.html, *.xhtml, ...
" These are the file extensions where this plugin is enabled.
"
let g:closetag_filenames = '*.html,*.xhtml,*.phtml'
" filenames like *.xml, *.xhtml, ...
" This will make the list of non-closing tags self-closing in the specified files.
"
let g:closetag_xhtml_filenames = '*.xhtml,*.jsx'
" filetypes like xml, html, xhtml, ...
" These are the file types where this plugin is enabled.
"
let g:closetag_filetypes = 'html,xhtml,phtml'
" filetypes like xml, xhtml, ...
" This will make the list of non-closing tags self-closing in the specified files.
"
let g:closetag_xhtml_filetypes = 'xhtml,jsx'
" integer value [0|1]
" This will make the list of non-closing tags case-sensitive (e.g. `<Link>` will be closed while `<link>` won't.)
"
let g:closetag_emptyTags_caseSensitive = 1
" dict
" Disables auto-close if not in a "valid" region (based on filetype)
"
let g:closetag_regions = {
\ 'typescript.tsx': 'jsxRegion,tsxRegion',
\ 'javascript.jsx': 'jsxRegion',
\ }
" Shortcut for closing tags, default is '>'
"
let g:closetag_shortcut = '>'
" Add > at current position without closing the current tag, default is ''
"
let g:closetag_close_shortcut = '<leader>>'
"}}}
autocmd FileType gitcommit setlocal spell
" Tmux {{{
" Bracketed Paste Mode
" Ref http://slashdot.jp/journal/506765/Bracketed-Paste-Mode
" - Use tmux 1.7 `paste-buffer -p` to paste
" - Use <F11> and tmux `send-keys "\e[201~"` for pastetoggle
if &term =~ "xterm" && exists('$TMUX')
let &t_ti = &t_ti . "\e[?2004h"
let &t_te = "\e[?2004l" . &t_te
let &pastetoggle = "\e[201~"
map <F11> <Esc>[201~
imap <F11> <Esc>[201~
function! XTermPasteBegin(ret)
set paste
return a:ret
endfunction
map <special> <expr> <Esc>[200~ XTermPasteBegin("i")
imap <special> <expr> <Esc>[200~ XTermPasteBegin("")
cmap <special> <Esc>[200~ <nop>
cmap <special> <Esc>[201~ <nop>
endif
function! TmuxNewWindow(...)
let options = a:0 ? a:1 : {}
let text = get(options, 'text', '')
let title = get(options, 'title', '')
let directory = get(options, 'directory', getcwd())
let method = get(options, 'method', 'new-window')
let size = get(options, 'size', '40')
let remember_pane = get(options, 'remember_pane', 0)
let pane = ''
if method == 'last'
if !exists('s:last_tmux_pane') || empty(s:last_tmux_pane)
echohl WarningMsg | echomsg "Can't find last tmux pane. Continue with 'horizontal-split'." | echohl None
let method = 'h'
else
let pane = s:last_tmux_pane
endif
elseif method == 'quit'
if !exists('s:last_tmux_pane') || empty(s:last_tmux_pane)
echohl WarningMsg | echomsg "Can't find last used pane." | echohl None
return
else
call system('tmux kill-pane -t ' . matchstr(s:last_tmux_pane, '%\d\+'))
unlet! s:last_tmux_pane
return
endif
endif
if empty(pane) && method != 'new-window'
" use splitted pane if available
let pane = matchstr(
\ system('tmux list-pane -F "#{window_id}#{pane_id}:#{pane_active}" | egrep 0$'),
\ '\zs@\d\+%\d\+\ze'
\ )
endif
if empty(pane)
if method == 'new-window'
let cmd = 'tmux new-window -a '
\ . (empty(title) ? '' : printf('-n %s', shellescape(title)))
\ . printf(' -c %s', shellescape(directory))
elseif method == 'v'
let cmd = 'tmux split-window -d -v '
\ . printf('-p %s -c %s ', size, shellescape(directory))
elseif method == 'h'
let cmd = 'tmux split-window -d -h '
\ . printf(' -c %s ', shellescape(directory))
endif
let pane = substitute(
\ system(cmd . ' -P -F "#{window_id}#{pane_id}"'), '\n$', '', ''
\ )
endif
if remember_pane
let s:last_tmux_pane = pane
endif
let window_id = matchstr(pane, '@\d\+')
let pane_id = matchstr(pane, '%\d\+')
if !empty(text)
let cmd = printf(
\ 'tmux set-buffer %s \; paste-buffer -t %s -d \; send-keys -t %s Enter',
\ shellescape(text),
\ pane_id,
\ pane_id
\ )
sleep 300m
call system('tmux select-window -t ' . window_id)
call system(cmd)
endif
endfunction
" }}}
" " Rails {{{
" function! s:rails_test_helpers()
" let type = rails#buffer().type_name()
" let relative = rails#buffer().relative()
" if type =~ '^test' || (type == 'javascript-coffee' && relative =~ '^test/')
" nmap <Leader>t [rtest]
" nnoremap <silent> [rtest]j :call <SID>rails_test_tmux('v')<CR>
" nnoremap <silent> [rtest]l :call <SID>rails_test_tmux('h')<CR>
" nnoremap <silent> [rtest]w :call <SID>rails_test_tmux('new-window')<CR>
" nnoremap <silent> [rtest]. :call <SID>rails_test_tmux('last')<CR>
" nnoremap <silent> [rtest]t :call <SID>rails_test_tmux('last')<CR>
" nnoremap <silent> [rtest]q :call <SID>rails_test_tmux('quit')<CR>
" end
" endfunction
" function! s:rails_test_tmux(method)
" let [it, path] = ['', '']
" let rails_type = rails#buffer().type_name()
" let rails_relative = rails#buffer().relative()
" if rails_type =~ '^test'
" let it = matchstr(
" \ getline(
" \ search('^\s*it\s\+\(\)', 'bcnW')
" \ ),
" \ 'it\s*[''"]\zs.*\ze[''"]'
" \ )
" let path = rails_relative
" elseif rails_type == 'javascript-coffee' && rails_relative =~ '^test/'
" " Currently, teaspoon can't filter specs without 'describe' title
" " https://github.com/modeset/teaspoon/issues/304
" let desc = matchstr(
" \ getline(
" \ search('^\s*describe\s*\(\)', 'bcnW')
" \ ),
" \ 'describe\s*[''"]\zs.*\ze[''"]'
" \ )
" let it = matchstr(
" \ getline(
" \ search('^\s*it\s\+\(\)', 'bcnW')
" \ ),
" \ 'it\s*[''"]\zs.*\ze[''"]'
" \ )
" let it = (empty(desc) || empty(it)) ?
" \ '' :
" \ join([desc, it], ' ')
" let path = rails_relative
" end
" if empty(it) || empty(path)
" let it = get(s:, 'rails_test_tmux_last_it', '')
" let path = get(s:, 'rails_test_tmux_last_path', '')
" end
" if empty(it) || empty(path)
" echohl WarningMsg | echomsg 'No `it` block found' | echohl None
" return
" end
" let s:rails_test_tmux_last_it = it
" let s:rails_test_tmux_last_path = path
" if rails_type == 'javascript-coffee'
" " https://github.com/modeset/teaspoon/wiki/Teaspoon-Configuration
" " TODO add back `--filter` if I can handle nested `describe` blocks
" " let test_command = printf('RAILS_RELATIVE_URL_ROOT= teaspoon %s --fail-fast -f pride --filter %s', path, shellescape(it))
" let test_command = printf('FAIL_FAST=true FORMATTERS=documentation rake teaspoon files=%s', path)
" let title = '☕️'
" " elseif rails_type == 'test-integration'
" " " TODO why can't just use ruby -Itest?
" " let test_command = printf('RAILS_RELATIVE_URL_ROOT= bundle exec rake test:integration TEST=%s', path)
" " let title = matchstr(rails_type, '\vtest-\zs.{4}')
" else
" let test_command = printf('be ruby -Itest %s --name /%s/', path, shellescape(escape(it, '()')))
" let type_short = matchstr(rails_type, '\vtest-\zs.{4}')
" if type_short == 'unit'
" let title = type_short
" elseif type_short == 'func'
" let title = type_short
" else
" let title = type_short
" endif
" endif
" call TmuxNewWindow({
" \ "text": test_command,
" \ "title": '∫ ' . title,
" \ "directory": get(b:, 'rails_root', getcwd()),
" \ "remember_pane": 1,
" \ "method": a:method
" \ })
" endfunction
" autocmd User Rails call s:rails_test_helpers()
" }}}
" GUI settings {{{
" set t_Co=256
" if globpath(&runtimepath, 'colors/solarized.vim', 1) !=# ''
" set background=dark
" " set background=light
" colorscheme solarized
" else
" colorscheme desert
" endif
" colorscheme molokai
" colorscheme jellybeans
" }}}
" Share VIM settings {{{
" if $TMUX =~ "pair"
" source ~/.vimrc.share
" endif
" }}}
" Disambiguate ,a & ,t from the Align plugin, making them fast again.
"
" This section is here to prevent AlignMaps from adding a bunch of mappings
" that interfere with the very-common ,a and ,t mappings. This will get run
" at every startup to remove the AlignMaps for the *next* vim startup.
"
" If you do want the AlignMaps mappings, remove this section, remove
" ~/.vim/bundle/Align, and re-run rake in maximum-awesome.
function! s:RemoveConflictingAlignMaps()
if exists("g:loaded_AlignMapsPlugin")
AlignMapsClean
endif
endfunction
command! -nargs=0 RemoveConflictingAlignMaps call s:RemoveConflictingAlignMaps()
silent! autocmd VimEnter * RemoveConflictingAlignMaps
function! s:init_qrpsqlpq()
nmap <buffer> <Leader>r [qrpsqlpq]
nnoremap <silent> <buffer> [qrpsqlpq]j :call qrpsqlpq#run('split')<CR>
nnoremap <silent> <buffer> [qrpsqlpq]l :call qrpsqlpq#run('vsplit')<CR>
nnoremap <silent> <buffer> [qrpsqlpq]r :call qrpsqlpq#run()<CR>
if !exists('b:rails_root')
call RailsDetect()
endif
if !exists('b:rails_root')
let b:qrpsqlpq_db_name = 'postgres'
endif
endfunction
if executable('psql')
let g:qrpsqlpq_expanded_format_max_lines = -1
autocmd FileType sql call s:init_qrpsqlpq()
endif