-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathvimrc
More file actions
505 lines (450 loc) · 12.9 KB
/
Copy pathvimrc
File metadata and controls
505 lines (450 loc) · 12.9 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
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
" .vimrc
" Author: Pedro Franceschi <pedrohfranceschi@gmail.com>
" Source: http://github.com/pedrofranceschi/vimfiles
" ##### Plug setup {{{
set nocompatible " be iMproved, required
filetype off " required
" Disable vim-tmux-navigator default mappings (we'll create our own)
let g:tmux_navigator_no_mappings = 1
call plug#begin('~/.vim/plugged')
" "}}}
" ##### Bundles {{{
Plug 'sjl/badwolf'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'bling/vim-airline'
Plug 'b4winckler/vim-objc'
Plug 'msanders/snipmate.vim'
Plug 'tomtom/tcomment_vim'
Plug 'maxbrunsfeld/vim-yankstack'
Plug 'mileszs/ack.vim'
Plug 'kana/vim-textobj-user'
Plug 'nelstrom/vim-textobj-rubyblock'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-surround'
Plug 'Raimondi/delimitMate'
Plug 'nelstrom/vim-markdown-folding'
Plug 'tpope/vim-repeat'
Plug 'nono/vim-handlebars'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'pangloss/vim-javascript'
Plug 'milkypostman/vim-togglelist'
Plug 'scrooloose/nerdtree'
Plug 'michalliu/jsruntime.vim'
Plug 'michalliu/jsoncodecs.vim'
Plug 'michalliu/sourcebeautify.vim'
Plug 'jnwhiteh/vim-golang'
Plug 'teranex/jk-jumps.vim'
Plug 'tpope/vim-dispatch'
Plug 'haya14busa/incsearch.vim'
Plug 'tomasr/molokai'
Plug 'rodjek/vim-puppet'
Plug 'elixir-lang/vim-elixir'
Plug 'embear/vim-localvimrc'
Plug 'vim-airline/vim-airline-themes'
Plug 'editorconfig/editorconfig-vim'
Plug 'godlygeek/tabular'
Plug 'christoomey/vim-tmux-navigator'
Plug 'leafgarland/typescript-vim'
Plug 'Quramy/vim-js-pretty-template'
Plug 'keith/swift.vim'
Plug 'benmills/vimux'
Plug 'hashivim/vim-terraform'
Plug 'mxw/vim-jsx'
Plug 'tpope/vim-rhubarb'
Plug 'udalov/kotlin-vim'
Plug 'MaxMEllon/vim-jsx-pretty'
" }}}
" ##### Plug post-setup {{{
call plug#end()
filetype plugin indent on " required
" }}}
" ##### Basic options {{{
" Display incomplete commands.
set showcmd
" Display the mode you're in.
set showmode
" Intuitive backspacing.
set backspace=indent,eol,start
" Handle multiple buffers better.
set hidden
" Enable focus events for tmux integration
set ttimeout
set ttimeoutlen=50
if has('nvim') || has('gui_running')
set termguicolors
endif
" Enhanced command line completion.
set wildmenu
" Complete files like a shell.
set wildmode=list:longest
" Case-insensitive searching.
set ignorecase
" But case-sensitive if expression contains a capital letter.
set smartcase
" Show line numbers.
set number
" Show cursor position.
set ruler
" Highlight matches as you type.
set incsearch
" Don't highlight matches.
set nohlsearch
" Turn off line wrapping.
set nowrap
" Show 3 lines of context around the cursor.
set scrolloff=3
" Set the terminal's title
set title
" No beeping.
set visualbell
" Don't make a backup before overwriting a file.
set nobackup
" And again.
set nowritebackup
" Keep swap files in one location
set directory=$HOME/.vim/tmp//,.
" Global tab width.
set tabstop=2
" And again, related
set shiftwidth=2
" Spaces, please
set expandtab
" Files open expanded
set foldlevelstart=50
" Use decent folding
set foldmethod=indent
" Show the status line all the time
set laststatus=2
" Useful status information at bottom of screen
set statusline=[%n]\ %<%.99f\ %h%w%m%r%y\ %{exists('*CapsLockStatusline')?CapsLockStatusline():''}%=%-16(\ %l,%c-%v\ %)%P
" Always diff using vertical mode
set diffopt+=vertical
" Allows the mouse to be used
set mouse=a
" Automatically reads changed files
set autoread
" Enable syntax highlighting
syntax on
" Sets the colorscheme for terminal sessions too.
colorscheme molokai
" Disable Background Color Erase (BCE) so the terminal background isn't
" painted with vim's current bg color on exit — prevents green screen over SSH.
set t_ut=
autocmd BufEnter * colorscheme molokai
" Leader = ,
let mapleader = ","
" }}}
" ##### General mappings {{{
" ##### Tabs {{{
nnoremap <leader>t :tabnew<cr>
nnoremap <leader>e :tabedit
nnoremap <leader>c :tabclose<cr>
nnoremap <leader>n :tabnext<cr>
nnoremap <leader>p :tabprevious<cr>
" }}}
" ##### Buffers {{{
" Navigate to previous/next buffer
nnoremap <leader>[ :bprevious<cr>
nnoremap <leader>] :bnext<cr>
" List all buffers
nnoremap <leader>bl :ls<cr>
" }}}
" ##### Line movement {{{
" Go to start of line with H and to the end with $
noremap H ^
noremap L $
" Emacs bindings in command-line mode
cnoremap <C-A> <home>
cnoremap <C-E> <end>
" }}}
" ##### Split windows {{{
" Create windows
nnoremap <leader>v <C-w>v<C-w>l
nnoremap <leader>m <C-w>s<C-w>j
nnoremap <leader>d <C-w>q
" }}}
" ##### Folding {{{
" Toggles folding with space
nnoremap <Space> za
" Open all folds
nnoremap zO zR
" Close all folds
nnoremap zC zM
" Close current fold
nnoremap zc zc
" Close all folds except the current one
nnoremap zf mzzMzvzz
" }}}
" ##### Search {{{
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)
" }}}
" ##### Misc {{{
" Edit and load vimrc
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>
" Wrap current paragraph
noremap <leader>w gqap
" Toggles hlsearch
nnoremap <leader>hs :set hlsearch!<cr>
" Maps <C-C> to <esc>
noremap <C-C> <esc>
" Go full-screen
nnoremap <leader>fs :set lines=999 columns=9999<cr>
" Fix C-h on Neovim (read https://github.com/christoomey/vim-tmux-navigator#it-doesnt-work-in-neovim-specifically-c-h)
nnoremap <silent> <BS> :TmuxNavigateLeft<cr>
" Store original highlight settings
let s:vim_is_dimmed = 0
" Dim vim when navigating out to tmux pane (only dim text content)
function! s:DimVim()
if s:vim_is_dimmed
return
endif
let s:vim_is_dimmed = 1
syntax off
hi Normal ctermfg=244 ctermbg=236
hi NonText ctermfg=244 ctermbg=236
" Make airline statusline inactive
call setwinvar(winnr(), 'airline_active', 0)
call airline#update_statusline_inactive([winnr()])
endfunction
function! s:BrightenVim()
if !s:vim_is_dimmed
return
endif
let s:vim_is_dimmed = 0
syntax on
hi clear Normal
hi clear NonText
" Make airline statusline active again
call setwinvar(winnr(), 'airline_active', 1)
call airline#update_statusline()
endfunction
" Custom command to brighten (sent from tmux when entering vim pane)
command! B call s:BrightenVim()
" Reset terminal colors on exit so the pane doesn't stay dimmed/colored
autocmd VimLeave * hi Normal ctermbg=NONE ctermfg=NONE
" Detect when navigating back into vim or moving cursor
augroup TmuxNavigatorDim
autocmd!
autocmd WinEnter * call s:BrightenVim()
autocmd CursorMoved * call s:BrightenVim()
autocmd CursorMovedI * call s:BrightenVim()
autocmd BufEnter * call s:BrightenVim()
augroup END
" Wrap navigation commands to detect leaving vim
function! s:WrappedNavigate(command)
let l:oldwin = winnr()
execute a:command
" If window didn't change, we likely left vim to tmux
if winnr() == l:oldwin
call s:DimVim()
else
" If window changed within vim, brighten
call s:BrightenVim()
endif
endfunction
" These mappings brighten when coming back into vim
function! s:BrightenAndNavigate(command)
call s:BrightenVim()
execute a:command
endfunction
nnoremap <silent> <c-h> :<C-U>call <SID>WrappedNavigate('TmuxNavigateLeft')<cr>
nnoremap <silent> <c-j> :<C-U>call <SID>WrappedNavigate('TmuxNavigateDown')<cr>
nnoremap <silent> <c-k> :<C-U>call <SID>WrappedNavigate('TmuxNavigateUp')<cr>
nnoremap <silent> <c-l> :<C-U>call <SID>WrappedNavigate('TmuxNavigateRight')<cr>
" }}}
" }}}
" ##### Plugin settings {{{
" ##### Fugitive {{{
" (thanks to Steve Losh's vimrc)
nnoremap <leader>gd :Gdiff<cr>
nnoremap <leader>gs :G<cr>
nnoremap <leader>gw :Gwrite<cr>
nnoremap <leader>ga :Gadd<cr>
nnoremap <leader>gb :Git blame<cr>
nnoremap <leader>gci :Gcommit<cr>
nnoremap <leader>ge :Gedit<cr>
nnoremap <leader>gm :Gmove
nnoremap <leader>gr :Gread<cr>
nnoremap <leader>grm :Gremove<cr>
nnoremap <leader>gp :Git push
" }}}
" ##### NERDTree {{{
noremap <leader>ft :NERDTreeToggle<CR>
" Don't fuck up vim's default file browser
let g:NERDTreeHijackNetrw = 0
" }}}
" ##### Airline {{{
let g:airline_powerline_fonts = 1
let g:airline_theme = 'powerlineish'
let g:airline_section_warning = ''
let g:airline_inactive_collapse = 1
let g:airline#extensions#default#section_truncate_width = {
\ 'a': 60,
\ 'b': 80,
\ 'x': 100,
\ 'y': 100,
\ 'z': 60,
\ }
" }}}
" ##### CtrlP {{{
" Works not only in ancestor directories of my working directory.
let g:ctrlp_working_path_mode = 'a'
" Custom ignores
let g:ctrlp_custom_ignore = 'node_modules\|DS_Store|_build\'
" Refresh CtrlP buffers
nnoremap <leader>rr :ClearAllCtrlPCaches <CR>
" }}}
" ##### Yankstack {{{
" Don't use default mappings
let g:yankstack_map_keys = 0
" Set bindings
nmap <C-M> <Plug>yankstack_substitute_older_paste
nmap <C-N> <Plug>yankstack_substitute_newer_paste
" }}}
" ##### Ack {{{
noremap <C-F> :Ack!<space>
" }}}
" ##### togglelist {{{
let g:toggle_list_copen_command="Copen"
" }}}
" ##### localvimrc {{{
let g:localvimrc_persistent=1
" }}}
" ##### Tabularize {{{
nnoremap <leader>b= :Tabularize /=<CR>
vnoremap <leader>b= :Tabularize /=<CR>
nnoremap <leader>b: :Tabularize /:\zs<CR>
vnoremap <leader>b: :Tabularize /:\zs<CR>
nnoremap <leader>b<space> :Tabularize / <CR>
vnoremap <leader>b<space> :Tabularize / <CR>
" }}}
" ##### Vimux {{{
" nnoremap <leader>rc :VimuxPromptCommand<CR>
" nnoremap <leader>rr :VimuxRunLastCommand <CR>
" nnoremap <leader>rz :VimuxZoomRunner <CR>
" }}}
" }}}
" ##### Custom functions {{{
" ##### Number toggle {{{
function! NumberToggle()
if(&relativenumber == 1)
set number
else
set relativenumber
endif
endfunc
nnoremap <leader>ll :call NumberToggle()<cr>
"}}}
" ##### Ack motions {{{
" (from Steve Losh's vimrc)
" Motions to Ack for things. Works with pretty much everything, including:
"
" w, W, e, E, b, B, t*, f*, i*, a*, and custom text objects
"
" Awesome.
"
" Note: If the text covered by a motion contains a newline it won't work. Ack
" searches line-by-line.
nnoremap <silent> <leader>a :set opfunc=<SID>AckMotion<CR>g@
xnoremap <silent> <leader>a :<C-U>call <SID>AckMotion(visualmode())<CR>
xnoremap <silent> <bs> :<C-U>call <SID>AckMotion(visualmode())<CR>
function! s:CopyMotionForType(type)
if a:type ==# 'v'
silent execute "normal! `<" . a:type . "`>y"
elseif a:type ==# 'char'
silent execute "normal! `[v`]y"
endif
endfunction
function! s:AckMotion(type) abort
let reg_save = @@
call s:CopyMotionForType(a:type)
execute "normal! :Ack! --literal " . shellescape(@@) . "\<cr>"
let @@ = reg_save
endfunction
" }}}
" }}}
" ##### Filetype-specific {{{
" ##### Ruby {{{
" Specific shiftwidth for ruby files
autocmd FileType ruby set shiftwidth=2
autocmd FileType ruby set tabstop=2
" Convert tabs to spaces in Ruby files
autocmd FileType ruby set expandtab
" But not for erb files...
autocmd FileType eruby set shiftwidth=4
autocmd FileType eruby set tabstop=4
"
" Remaps textobj-rubyblock's bindings to vim's defaults
autocmd FileType ruby map aB ar
autocmd FileType ruby map iB ir
" }}}
" ##### Puppet {{{
" Specific shiftwidth for puppet files
autocmd BufRead,BufNewFile *.pp set filetype=puppet
autocmd BufRead,BufNewFile Puppetfile set filetype=ruby
" And custom tab sizes too
autocmd FileType puppet set shiftwidth=2
autocmd FileType puppet set tabstop=2
" }}}
" ##### Markdown {{{
" Sets markdown syntax for *.md files.
autocmd BufRead,BufNewFile *.md set filetype=markdown
" Wrap markdown files.
autocmd BufRead,BufNewFile *.md set wrap
autocmd BufEnter *.md colorscheme badwolf
" Set textwidth to 80 columns
autocmd FileType md set textwidth=80
" }}}
" ##### JavaScript {{{
" Sets javascript syntax for *.json files.
autocmd BufRead,BufNewFile *.json set filetype=javascript
" Sets html syntax for *.ejs files.
autocmd BufRead,BufNewFile *.ejs set filetype=html
" Sets typescript syntax for *.tsx files.
autocmd BufRead,BufNewFile *.tsx set filetype=typescript
" }}}
" ##### Vim {{{
" Make vimrcs open folded
autocmd FileType vim set foldlevel=0
autocmd FileType vim set foldmethod=marker
let g:jsx_ext_required = 0
" }}}
" ##### XML {{{
" Automatically format XML files
nnoremap <leader>xb :%s,>[ <tab>]*<,>\r<,g<cr> gg=G
" }}}
" ##### SQL {{{
" SQL to CSV
nnoremap <leader>csv ggV/^+-<cr>dGV?^+-<cr>dgg:g/^+-/d<cr>:%s/^<bar> \<bar> <bar>$//g<cr>:%s/ *<bar> */,/g<cr>
" }}}
" ##### LookML {{{
" Sets YAML syntax for *.lookml files.
autocmd BufRead,BufNewFile *.lookml set filetype=yaml
" }}}
" ##### LaTeX {{{
" Build .tex files automatically
" autocmd FileType tex nnoremap <leader>c :!pdflatex %<cr>
" autocmd FileType tex nnoremap <leader>c :!pdflatex %<cr>
autocmd BufWritePost *.tex !pdflatex %
" Set textwidth to 80 columns
autocmd FileType tex set textwidth=80
" }}}
" ##### Swift {{{
" Enable autocomplete using deoplete
autocmd FileType swift imap <buffer> <C-k> <Plug>(autocomplete_swift_jump_to_placeholder)
" }}}
" ##### Terraform {{{
" Enable autocomplete using deoplete
autocmd FileType terraform set shiftwidth=2
autocmd FileType terraform set tabstop=2
autocmd FileType terraform set expandtab
" }}}
" ##### Elixir {{{
" Enable autocomplete using deoplete
autocmd FileType elixir nnoremap <leader>rt :call VimuxRunCommand("script/mix test " . bufname("%"))<CR>
" }}}
" }}}