-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
596 lines (530 loc) · 16.8 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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
filetype off
" set rtp+=~/.vim/bundle/Vundle.vim
call plug#begin()
" call vundle#begin()
Plug 'dstein64/vim-startuptime'
Plug 'godlygeek/tabular'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb'
Plug 'tpope/vim-repeat'
Plug 'airblade/vim-gitgutter'
Plug 'timcharper/textile.vim'
Plug 'tpope/vim-haml'
Plug 'vim-ruby/vim-ruby'
Plug 'tpope/vim-eunuch'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'instant-markdown/vim-instant-markdown', {'for': 'markdown', 'do': 'yarn install'}
Plug 'tpope/vim-abolish'
Plug 'sheerun/vim-polyglot'
Plug 'Raimondi/delimitMate'
Plug 'tpope/vim-speeddating'
Plug 'tpope/vim-endwise'
Plug 'bling/vim-bufferline'
Plug 'plasticboy/vim-markdown'
Plug 'Konfekt/FastFold'
Plug 'ervandew/supertab'
Plug 'schickling/vim-bufonly'
Plug 'tpope/vim-surround'
Plug 'othree/html5.vim'
Plug 'tpope/vim-bundler'
Plug 'tomtom/tcomment_vim'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-vinegar'
Plug 'tpope/vim-dispatch'
Plug 'MarcWeber/vim-addon-mw-utils'
Plug 'tomtom/tlib_vim'
Plug 'tpope/vim-rake'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'AndrewRadev/splitjoin.vim'
Plug 'lervag/vimtex'
Plug 'AndrewRadev/vim-eco'
Plug 'mbbill/undotree'
Plug 'janko-m/vim-test'
Plug 'benmills/vimux'
Plug 'dense-analysis/ale'
Plug 'isRuslan/vim-es6'
Plug 'dhruvasagar/vim-railscasts-theme'
Plug 'slim-template/vim-slim'
Plug 'LnL7/vim-nix'
Plug 'neovim/nvim-lspconfig'
Plug 'haorenW1025/completion-nvim'
Plug '/usr/local/opt/fzf'
Plug 'liuchengxu/vim-clap'
Plug '~/.vim/bundle/IndexedSearch'
" call vundle#end()
call plug#end()
syntax enable
set shell=/bin/zsh
set t_Co=256
" haorenW1025/completion-nvim
autocmd BufEnter * lua require'completion'.on_attach()
let g:completion_enable_auto_popup = 0
set completeopt=menuone,noinsert,noselect
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ completion#trigger_completion()
" autosave buffers
set autowriteall
autocmd BufLeave,FocusLost * wall
set ignorecase
set smartcase
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set nobackup
set nowritebackup
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
setlocal spell spelllang=en_us
set spell
set number
set undofile
set undodir=~/.vim/undo
set gdefault
let mapleader = ","
"remove the search highlight
nnoremap <leader><space> :noh<cr>
"split window
nnoremap <leader>v <C-w>v<C-w>l
nnoremap <leader>w <C-w>s<C-w>l
"move between windows
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
"silly attempt to convert class name to underscore
nnoremap <leader>u :s/\(\u\)/_\L\1<cr>
set clipboard=unnamed
nnoremap j gj
nnoremap k gk
nnoremap ; :
" Don't use Ex mode, use Q for formatting
map Q gq
tnoremap <Esc> <C-\><C-n>:q!<CR>
let g:bufferline_echo = 0
let g:bufferline_fname_mod = ':gs?.*\/\ze.*\/??'
let g:airline#extensions#tabline#enabled = 0
" set statusline=%<%f%h%m%r%=%{strftime(\"%l:%M\")}\ %l,%c%V\ %P%{fugitive#statusline()}
colorscheme railscasts
"Git commands
noremap gs :Gstatus<CR>
noremap ggc :Gcommit<CR>
noremap gap :Git add -p<CR>
noremap gp :Git push<CR>
" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
"vnoremap p "_dp
"
"file jumping
noremap fb :b#<CR>
let g:jsx_ext_required = 0
let ruby_space_errors = 1
set list!
set list listchars=tab:»·,trail:·
" 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")) && !exists("syntax_on")
syntax on
set hlsearch
endif
let g:Tex_DefaultTargetFormat= "pdf"
let g:Tex_ViewRule_pdf = 'Preview.app'
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_html_tidy_ignore_errors = [ 'trimming empty' ]
let g:syntastic_loc_list_height = 5
let g:syntastic_auto_loc_list = 0
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 1
let g:syntastic_javascript_checkers = ['eslint']
let g:syntastic_error_symbol = '❌'
let g:syntastic_style_error_symbol = '⁉️'
let g:syntastic_warning_symbol = '⚠️'
let g:syntastic_style_warning_symbol = '💩'
highlight link SyntasticErrorSign SignColumn
highlight link SyntasticWarningSign SignColumn
highlight link SyntasticStyleErrorSign SignColumn
highlight link SyntasticStyleWarningSign SignColumn
let g:ctrlp_custom_ignore = 'node_modules\|DS_Store\|git\|build\|public'
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" 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
autocmd BufNewFile,BufRead *.ctl setf ruby
" 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")
set directory=~/.vim/swp
if has("folding")
nmap zuz <Plug>(FastFoldUpdate)
let g:fastfold_savehook = 1
let g:fastfold_fold_command_suffixes = ['x','X','a','A','o','O','c','C']
let g:fastfold_fold_movement_commands = [']z', '[z', 'zj', 'zk']
let g:markdown_folding = 1
let g:tex_fold_enabled = 1
let g:vimsyn_folding = 'af'
let g:xml_syntax_folding = 1
let g:javaScript_fold = 1
let g:sh_fold_enabled= 7
let g:ruby_fold = 1
let g:perl_fold = 1
let g:perl_fold_blocks = 1
let g:r_syntax_folding = 1
let g:rust_fold = 1
let g:php_folding = 1
set foldenable
set foldmethod=syntax
set foldlevel=0
set foldnestmax=2
highlight Folded ctermbg=black ctermfg=cyan
highlight FoldColumn ctermbg=black ctermfg=cyan
" automatically open folds at the starting cursor position
" autocmd BufReadPost .foldo!
autocmd FileType gitcommit setlocal nofoldenable
endif
"
" Softtabs, 2 spaces
set tabstop=2
set shiftwidth=2
set expandtab
" Always display the status line
set laststatus=2
" Hide search highlighting
map ,nh :nohls <CR>
" Opens an edit command with the path of the currently edited file filled in
" Normal mode: ,e
map ,e :e <C-R>=expand("%:p:h") . "/" <CR>
" Opens a tab edit command with the path of the currently edited file filled in
" Normal mode: ,t
map ,t :tabe <C-R>=expand("%:p:h") . "/" <CR>
" Inserts the path of the currently edited file into a command
" Command mode: Ctrl+P
map <C-P> <cmd>Telescope find_files<cr>
map <C-F> <cmd>Telescope live_grep<cr>
let g:livepreview_previewer = 'open -a Skim'
" Maps autocomplete to tab
" imap <Tab> <C-N>
" let g:UltiSnipsSnippetDirectories=["UltiSnips", "ywen.snippets"]
"
" let g:UltiSnipsExpandTrigger="<S-Tab>"
" let g:UltiSnipsJumpForwardTrigger="<c-b>"
" let g:UltiSnipsJumpBackwardTrigger="<c-z>"
" Duplicate a selection
" Visual mode: D
vmap D y'>p
" For Haml
au! BufRead,BufNewFile *.haml setfiletype haml
" No Help, please
nmap <F1> <Esc>
" Press ^F from insert mode to insert the current file name
imap <C-F> <C-R>=expand("%")<CR>
nmap <C-C> :b#<bar>bd#<CR>
" Display extra whitespace
" set list listchars=tab:»·,trail:·
let g:Conque_TERM = "xterm"
" Edit routes
command! Rroutes :e config/routes.rb
command! RTroutes :tabe config/routes.rb
" Local config
if filereadable(".vimrc.local")
source .vimrc.local
endif
" Use Ack instead of Grep when available
set grepprg=grep\ -nH\ $*
if executable("ack")
set grepprg=ack\ -H\ --nogroup\ --nocolor
endif
map <Leader>vra :vertical resize +5<CR>
map <Leader>vrs :vertical resize -5<CR>
" Color scheme
highlight NonText guibg=#060606
highlight Folded guibg=#0A0A0A
autocmd InsertEnter,InsertLeave * set cul!
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
" Numbers
set number
set numberwidth=5
" Tab completion options
" (only complete to the longest unambiguous match, and show a menu)
set complete=.,w,b,u,t
set completeopt=longest,menu
set wildmode=list:longest,list:full
" Mappings
" run one rspec example or describe block based on cursor position
" map <D-r> <ESC>:w<CR>:RunSpec<CR>
let NODE_ENV = "test"
let g:rspec_runner = "os_x_iterm2"
function! FloatingStrategy(cmd)
" Terminal Window
let width = float2nr(&columns - (&columns * 2 / 6))
let height = float2nr(&lines / 1.4)
let opts = {
\ 'relative': 'editor',
\ 'row': 2,
\ 'col': 4,
\ 'width': width,
\ 'height': height,
\ }
let buf = nvim_create_buf(v:false, v:true)
let s:float_term_win = nvim_open_win(buf, v:true, opts)
call termopen(a:cmd)
startinsert
endfunction
let g:test#preserve_screen = 0
let g:test#custom_strategies = {'floating': function('FloatingStrategy')}
let g:test#strategy = 'vimux'
let g:rspec_command = "bundle exec rspec"
let test#ruby#cucumber#executable = "bundle exec spinach"
let test#ruby#cucumber#options= '-b'
let test#javascript#mocha#executable = 'yarn test --reporter dot'
map <Leader>t :TestFile<CR>
map <Leader>s :TestNearest<CR>
map <Leader>l :TestLast<CR>
map <Leader>g :TestVisit<CR>
map <C-b> <ESC>:BufOnly<cr>
function! RailsScriptSearch(args)
let l:savegrepprg = &grepprg
let l:savegrepformat = &grepformat
try
set grepprg=script/find
set grepformat=%f:%l:%m
execute "grep " . a:args
finally
execute "set grepformat=" . l:savegrepformat
execute "set grepprg=" . l:savegrepprg
endtry
endfunction
" search with explicitly provided arguments
command! -n=? Rgrep :call RailsScriptSearch('<args>')
" search for the word under the cursor
map <leader>rg :silent call RailsScriptSearch(expand("'<cword>'"))<CR>:cc<CR>
" search for the method definition of the word under the cursor
map <leader>rd :silent call RailsScriptSearch(expand("'def <cword>'"))<CR>:cc<CR>
" TextMate cmd+T mode
"ruby
" autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
" autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
" autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
" autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
"improve autocomplete menu color
highlight Pmenu ctermbg=238 gui=bold guibg=#9aadd5 guifg=black
augroup mkd
autocmd BufRead *.mkd set ai formatoptions=tcroqn2 comments=n:>
augroup END
" set statusline=%<%f%h%m%r%=%{strftime(\"%l:%M\")}\ %l,%c%V\ %P%{fugitive#statusline()}
let g:ConqueTerm_Color = 1
let g:ConqueTerm_TERM = 'vt100'
let g:ConqueTerm_ReadUnfocused = 0
let g:ConqueTerm_CWInsert = 0
"rails.vim specific shortcut
noremap <leader>rm :Rmodel
noremap <leader>rc :Rcontroller
noremap <leader>rv :Rview
noremap <leader>rs :Rspec
noremap <leader>rl :Rlib
noremap <Leader>ot :vsplit<ENTER><C-w>l:A<ENTER>
"buffers
noremap <leader>bd :bd<CR>
let g:SimpleJsIndenter_BriefMode = 1
let g:ConqueTerm_ReadUnfocused = 1
let g:ConqueTerm_TERM = 'xterm'
"mouse support in terminal
set mouse=a
set mousehide
set noswapfile
"gist
let g:gist_clip_command = 'pbcopy'
let g:gist_detect_filetype = 1
let g:gist_open_browser_after_post = 1
function! NumberToggle()
if(&relativenumber == 1)
set norelativenumber
set number
else
set relativenumber
endif
endfunc
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
nmap tb :Tabularize/\|<cr>
nmap sj :SplitjoinSplit<cr>
nmap sk :SplitjoinJoin<cr>
let g:rails_projections = {
\ "features/*.feature": {
\ "command": "features",
\ "keywords": "features",
\ "test": [
\ "features/steps/{}.rb",
\ ],
\ },
\ "features/steps/*.rb": {
\ "command": "steps",
\ "keywords": "steps",
\ "test": [
\ "features/{}.feature",
\ ],
\ },
\ "app/controllers/api/v1/*_controller.rb": {
\ "command": "vapi",
\ "keywords": "vapi",
\ "test": [
\ "spec/controllers/api/v1/%s_spec.rb",
\ ],
\ }
\}
function! BufSel(pattern)
let bufcount = bufnr("$")
let currbufnr = 1
let nummatches = 0
let firstmatchingbufnr = 0
while currbufnr <= bufcount
if(bufexists(currbufnr))
let currbufname = bufname(currbufnr)
if(match(currbufname, a:pattern) > -1)
echo currbufnr . ": ". bufname(currbufnr)
let nummatches += 1
let firstmatchingbufnr = currbufnr
endif
endif
let currbufnr = currbufnr + 1
endwhile
if(nummatches == 1)
execute ":buffer ". firstmatchingbufnr
elseif(nummatches > 1)
let desiredbufnr = input("Enter buffer number: ")
if(strlen(desiredbufnr) != 0)
execute ":buffer ". desiredbufnr
endif
else
echo "No matching buffers"
endif
endfunction
"Bind the BufSel() function to a user-command
command! -nargs=1 Bs :call BufSel("<args>")
" FZF Floating Window {{{1
if exists('*nvim_create_buf')
let $FZF_DEFAULT_OPTS='--layout=reverse'
let g:fzf_layout = { 'window': 'call FloatingFZF()' }
function! FloatingFZF()
let buf = nvim_create_buf(v:false, v:true)
call setbufvar(buf, '&signcolumn', 'no')
let height = &lines / 2
let width = float2nr(&columns - (&columns * 2 / 4))
let col = float2nr((&columns - width) / 2)
let opts = {
\ 'relative': 'editor',
\ 'row': &lines / 5,
\ 'col': col,
\ 'width': width,
\ 'height': height
\ }
call nvim_open_win(buf, v:true, opts)
endfunction
endif
command! -nargs=+ -complete=file Rag call fzf#vim#ag_raw(<q-args>)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 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
map <Leader>r :call RenameFile()<cr>
hi! DiffAdd guibg=#003300
hi! DiffChange guibg=#003300
hi! DiffDelete guifg=#330000 guibg=#330000
hi! DiffText guibg=#990000
function! FloatingTerm()
" Terminal Window
let width = float2nr(&columns - (&columns * 2 / 6))
let col = float2nr(&columns * 0.2)
let height = float2nr(&lines / 1.4)
let opts = {
\ 'relative': 'editor',
\ 'row': 2,
\ 'col': col,
\ 'width': width,
\ 'height': height,
\ }
let buf = nvim_create_buf(v:false, v:true)
let s:float_term_win = nvim_open_win(buf, v:true, opts)
terminal
startinsert
endfunction
map <Leader>at :call FloatingTerm()<cr>
nmap <Leader>nf :NERDTreeFind<CR>
" autocmd BufEnter * if &modifiable | NERDTreeFind | wincmd p | endif
" autocmd VimEnter * wincmd p
" autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
"let g:airline_section_a = airline#section#create(['mode', 'iminsert'])
let g:airline_section_a = airline#section#create_left(['mode', 'crypt', 'paste', 'keymap', 'capslock', 'xkblayout', 'iminsert'])
let g:airline_section_x = airline#section#create([])
let g:airline_section_y = airline#section#create([])
let g:airline_section_z = airline#section#create(['%p%%', 'linenr', ':%v'])
let g:airline_mode_map = {
\ '__' : '--',
\ 'n' : 'N',
\ 'i' : 'I',
\ 'R' : 'R',
\ 'c' : 'C',
\ 'v' : 'V',
\ 'V' : 'V-L',
\ '' : 'V-B',
\ 's' : 'S',
\ 'S' : 'S-L',
\ '' : 'S-B',
\ 't' : 'T',
\ }
function! ToggleZoom(zoom)
if exists("t:restore_zoom") && (a:zoom == v:true || t:restore_zoom.win != winnr())
exec t:restore_zoom.cmd
unlet t:restore_zoom
elseif a:zoom
let t:restore_zoom = { 'win': winnr(), 'cmd': winrestcmd() }
exec "normal \<C-W>\|\<C-W>_"
endif
endfunction
augroup restorezoom
au WinEnter * silent! :call ToggleZoom(v:false)
augroup END
nnoremap <silent> <Leader>m :call ToggleZoom(v:true)<CR>