-
Notifications
You must be signed in to change notification settings - Fork 2
/
.vimrc
450 lines (371 loc) · 15.4 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
" ---------------------------------------------------------------------------
" Vundle
" ---------------------------------------------------------------------------
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'mileszs/ack.vim'
Plugin 'bling/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'AndrewRadev/switch.vim'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'duff/vim-trailing-whitespace'
Plugin 'duff/vim-scratch'
Plugin 'duff/vim-commaobject'
Plugin 'elixir-editors/vim-elixir'
Plugin 'kana/vim-textobj-user'
Plugin 'duff/vim-textobj-elixir'
Plugin 'nelstrom/vim-textobj-rubyblock'
Plugin 'pangloss/vim-javascript'
Plugin 'scrooloose/nerdtree'
Plugin 'vim-ruby/vim-ruby'
Plugin 'xolox/vim-session'
Plugin 'xolox/vim-misc'
Plugin 'chriskempson/base16-vim'
Plugin 'kana/vim-textobj-entire'
Plugin 'junegunn/fzf.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-rails'
Plugin 'tpope/vim-rake'
Plugin 'tpope/vim-ragtag'
Plugin 'tpope/vim-repeat'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-unimpaired'
Plugin 'tpope/vim-endwise'
Plugin 'tpope/vim-commentary'
Plugin 'tpope/vim-rhubarb'
call vundle#end()
" ---------------------------------------------------------------------------
" General
" ---------------------------------------------------------------------------
set nocompatible
runtime macros/matchit.vim
filetype plugin indent on
let mapleader = ","
set history=1000 " lots of command line history
set autoread " reload files changed outside of Vim
set autowrite " some commands should cause an automatic write
set nrformats= " improves incrementing when there are leading 0's.
set linebreak " wrapping preserves words.
set number " show line numbers
" ----------------------------------------------------------------------------
" UI
" ----------------------------------------------------------------------------
set ruler " show the cursor position all the time
set backspace=start,indent,eol " allow backspacing over anything in insert mode
set wm=2 " wrap margin on the right
set scrolloff=2 " keep some context when scrolling
set nowrap " do not wrap lines
set antialias " of course
set synmaxcol=200 " limit syntax highlighting for long lines
" --------------------------------------------------
" Basic font, colors
" --------------------------------------------------
set background=dark
colorscheme base16-default-dark
syntax on
" ----------------------------------------------------------------------------
" Visual cues
" ----------------------------------------------------------------------------
set laststatus=2 " always show the status line
set visualbell " quiet
set noerrorbells " quiet
set showcmd " show size of visual selection
set wildmenu " show possible matches for command completions using tab
set wildmode=list:longest,full " full list using common string. Then full complete.
" ----------------------------------------------------------------------------
" Tabs
" ----------------------------------------------------------------------------
set tabstop=4
set softtabstop=2 " yep, two
set shiftwidth=2
set nosmarttab " no tabs, thanks.
set autoindent " automatically indent new lines
set expandtab " expand tabs to spaces
" ----------------------------------------------------------------------------
" Backups
" ----------------------------------------------------------------------------
set nobackup " do not keep backups after close
set nowritebackup " do not keep a backup while working
set noswapfile " don't keep swp files either
set backupdir=~/.vim/backups " store backups under ~/.vim/backup
set backupcopy=yes " keep attributes of original file
set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
set directory=~/.vim/tmp " where to keep swp files
" ----------------------------------------------------------------------------
" Searching
" ----------------------------------------------------------------------------
set ignorecase " make searches case insensitive
set smartcase " care about case sensitivity if there's a capital letter
set incsearch " do incremental searching
set nohlsearch " don't highlight searches
" ----------------------------------------------------------------------------
" NerdTree config
" ----------------------------------------------------------------------------
let NERDTreeWinSize=36 " how wide nerdtree ought to be
let NERDTreeMinimalUI=1 " hide the noise
let NERDTreeDirArrows=1 " prettier arrows
" ---------------------------------------------------------------------------
" Mappings
" ---------------------------------------------------------------------------
" --------------------------------------------------
" Edit vimrc
" --------------------------------------------------
nmap <leader>c :sp ~/.vimrc<CR><C-W>_
nmap <leader>C :source $MYVIMRC<CR>:source $MYGVIMRC<CR>:exe "echo 'vimrc & gvimrc reloaded'"<CR>
" --------------------------------------------------
" Show/hide nerdtree
" --------------------------------------------------
nnoremap <leader>d :NERDTreeClose<CR>
nnoremap <leader>D :NERDTree<CR>
" --------------------------------------------------
" Highlight the current buffer in the nerdtree
" --------------------------------------------------
nnoremap <leader>n :NERDTreeFind<CR>
" --------------------------------------------------
" Move between windows
" --------------------------------------------------
nnoremap <C-J> <C-W>j
nnoremap <C-K> <C-W>k
nnoremap <C-H> <C-W>h
nnoremap <C-L> <C-W>l
" --------------------------------------------------
" Make it easy to move to adjacent files in the dir
" --------------------------------------------------
nmap gj :NERDTreeFind<CR><C-j><Enter>
nmap gk :NERDTreeFind<CR><C-k><Enter>
" --------------------------------------------------
" Navigating search results
" --------------------------------------------------
nnoremap <leader>1 :cprevious <CR>
nnoremap <leader>2 :cnext <CR>
" --------------------------------------------------
" Space is much easier to press than %
" --------------------------------------------------
map <space> %
" --------------------------------------------------
" Speed up viewport scrolling
" --------------------------------------------------
nnoremap <C-e> 3<C-e>
nnoremap <C-y> 3<C-y>
" --------------------------------------------------
" Shortcut to make splits
" --------------------------------------------------
nnoremap <leader>s :sp<cr><C-w>j
nnoremap <leader>v :vsp<cr><C-w>l
" --------------------------------------------------
" Resize windows
" --------------------------------------------------
nmap <C-Left> <C-W><<C-W><
nmap <C-Right> <C-W>><C-W>>
nmap <C-Up> <C-W>+<C-W>+
nmap <C-Down> <C-W>-<C-W>-
" --------------------------------------------------
" Emacs bindings in command line mode
" --------------------------------------------------
cnoremap <c-a> <home>
cnoremap <c-e> <end>
" --------------------------------------------------
" Add the dir of the current file to the command
" --------------------------------------------------
cnoremap %% <C-R>=expand('%:h').'/'<cr>
" --------------------------------------------------
" Ctrlp plugin
" --------------------------------------------------
nnoremap <leader>f :CtrlP<CR>
nnoremap <leader>F :CtrlPClearCache<CR>:CtrlP<CR>
" --------------------------------------------------
" FZF plugin
" --------------------------------------------------
" nnoremap <leader>f :Files<CR>
" nnoremap <leader><leader>l :Files<CR>/lib/
" nnoremap <leader><leader>t :Files<CR>/test/
" nnoremap <leader><leader>c :Files<CR>/controllers/
" nnoremap <leader><leader>m :Files<CR>/models/
" --------------------------------------------------
" Session shortcuts
" --------------------------------------------------
nnoremap <leader>p :OpenSession<space>
" --------------------------------------------------
" Normal mode shortcuts
" --------------------------------------------------
nmap <leader><Enter> [<space>
nnoremap <leader><space> i<space><Esc>
" --------------------------------------------------
" Easier to get to the end of the line
" --------------------------------------------------
noremap gl g_
" --------------------------------------------------
" Easier to get to the first non-blank character of the line
" --------------------------------------------------
noremap gh ^
" --------------------------------------------------
" ack/ag/rg shortcuts
" --------------------------------------------------
nnoremap <leader>A :Ack<cword><CR>
nnoremap <leader>a :Ack<space>
vmap <leader>A "ry:Ack<space>"<C-r>r"<CR>
" --------------------------------------------------
" Open up in Github
" --------------------------------------------------
nnoremap <leader>g :Gbrowse<CR>
" --------------------------------------------------
" Ctags shortcuts
" --------------------------------------------------
nnoremap <C-Enter> <C-]>
nnoremap g<C-Enter> g]
" --------------------------------------------------
" Auto complete shortcut
" --------------------------------------------------
imap <S-space> <C-n>
" --------------------------------------------------
" Switch it up with the switch plugin
" --------------------------------------------------
nnoremap <S-space> :Switch<CR>
" --------------------------------------------------
" Hash syntax shortcut
" --------------------------------------------------
inoremap <C-l> <space>=><space>
" --------------------------------------------------
" Allow multiple pastes of the same content when pasting in visual mode.
" --------------------------------------------------
vnoremap p pgvy
" --------------------------------------------------
" Remove trailing whitespace
" --------------------------------------------------
nnoremap <leader>h :FixWhitespace<cr>
" --------------------------------------------------
" Save a few keystrokes
" --------------------------------------------------
nnoremap <Leader>q :q<CR>
nnoremap <Leader>w :w<CR>
nnoremap <Leader>x :x<CR>
" --------------------------------------------------
" I often use a Scratch buffer
" --------------------------------------------------
nnoremap <leader>S :Scratch<CR>
" --------------------------------------------------
" Visually select the text that was last edited/pasted
" --------------------------------------------------
nmap gV `[v`]
" Bubble lines
nmap ˚ [e
nmap ∆ ]e
vmap ˚ [egv
vmap ∆ ]egv
" --------------------------------------------------
" Switch between the last 2 files
" --------------------------------------------------
nnoremap go <c-^>
" --------------------------------------------------
" Start a :%s with the visual selection.
" --------------------------------------------------
vnoremap <C-r> "hy:%s/<C-r>h//gc<left><left><left>
" ---------------------------------------------------------------------------
" Misc stuff
" ---------------------------------------------------------------------------
" --------------------------------------------------
" Yank to the * register (system clipboard) to easily
" paste into other apps.
" --------------------------------------------------
set clipboard+=unnamed
" --------------------------------------------------
" Persistent undo
" --------------------------------------------------
set undofile
set undodir=~/.vim/.undo
" --------------------------------------------------
" Let me leave buffers even when they're changed.
" --------------------------------------------------
set hidden
" --------------------------------------------------
" Write all named, changed buffers when Vim loses focus
" --------------------------------------------------
au FocusLost * :wall
" --------------------------------------------------
" Insert mode completion options
" --------------------------------------------------
set completeopt=longest,menu,preview
set complete=.
" --------------------------------------------------
" Improve navigation of the popup menu for completion.
" --------------------------------------------------
inoremap <expr> <C-n> pumvisible() ? '<C-n>' : '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
" --------------------------------------------------
" Jump to last saved position of buffer when re-opening
" --------------------------------------------------
autocmd BufReadPost *
\ if !(bufname("%") =~ '\(COMMIT_EDITMSG\)') && line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" --------------------------------------------------
" No hlsearch, but highlight all matches while searching
" --------------------------------------------------
augroup vimrc-incsearch-highlight
autocmd!
autocmd CmdlineEnter [/\?] :set hlsearch
autocmd CmdlineLeave [/\?] :set nohlsearch
augroup END
" --------------------------------------------------
" Omnicomplete
" --------------------------------------------------
set ofu=syntaxcomplete#Complete
" --------------------------------------------------
" Open url on current line in browser
" --------------------------------------------------
function! HandleURI()
let s:uri = matchstr(getline("."), '[a-z]*:\/\/[^ >,;:]*')
echo s:uri
if s:uri != ""
exec "!open \"" . s:uri . "\""
else
echo "No URI found in line."
endif
endfunction
nmap <Leader>b :call HandleURI()<CR>
" --------------------------------------------------
" Vim-session customization
" --------------------------------------------------
let g:session_autosave = 'yes'
let g:session_lock_enabled = 0
let g:session_autosave_silent = 1
let g:session_autosave_periodic = 2
let g:session_autoload = 'no'
let g:session_persist_colors = 0
let g:session_persist_font = 0
set sessionoptions-=buffers
set sessionoptions-=help
set sessionoptions-=tabpages
" --------------------------------------------------
" Airline configuation
" --------------------------------------------------
let g:airline_powerline_fonts=1
let g:airline_extensions = []
let g:airline_section_b=''
let g:airline_section_y=''
let g:airline_section_z='%3v'
let g:airline_theme='cool'
let g:airline_skip_empty_sections = 1
" --------------------------------------------------
" Ignored wildcards
" --------------------------------------------------
set wildignore+=*/.git/*,*/tmp/*,*/deps/*,*/_build/*,*/vendor/*
" --------------------------------------------------
" CtrlP customization
" --------------------------------------------------
let g:ctrlp_match_window = 'bottom,order:btt,max:20'
let g:ctrlp_by_filename = 1
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_show_hidden = 1
" --------------------------------------------------
" FZF customization
" --------------------------------------------------
" set rtp+=/usr/local/opt/fzf
" --------------------------------------------------
" Use ripgrep for all the things
" --------------------------------------------------
let g:ackprg = 'rg --vimgrep'
set grepprg=rg\ --color=never
" let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'
let g:ctrlp_user_command = "rg %s --files --hidden -g '!.git'"