-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
419 lines (348 loc) · 10.2 KB
/
vimrc
File metadata and controls
419 lines (348 loc) · 10.2 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
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin Manager (vim-plug)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible
filetype off
" Auto-install vim-plug if missing
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
source ~/dotfiles/install/vim/plugins.vim
filetype plugin indent on
syntax on
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let mapleader=","
set autoread " detect when a file is changed externally
set path+=** " tab-completion for file-related tasks
set encoding=utf-8 nobomb
set t_Co=256
silent! colorscheme dracula
set colorcolumn=120
highlight ColorColumn ctermbg=0 guibg=lightgrey
" Local state directories
set backupdir=~/.vim/backups
set directory=~/.vim/swaps
set undodir=~/.vim/undo
set undofile " persistent undo
set nobackup
set nowritebackup
set noswapfile
" Status line / UI
set laststatus=2
set showmode
set showtabline=2
set ruler
set title
set shortmess=atI
set report=0
set visualbell
set ttyfast
set nolazyredraw
set mouse=a
" Splits
set splitbelow
set splitright
set winminheight=0
" Scrolling
set scrolloff=8
set sidescrolloff=8
" Buffers
set hidden
set history=1000
set autoindent
set smartindent
set backspace=indent,eol,start
set cursorline
set nowrap
set nostartofline
set nojoinspaces
set showmatch
set mat=2
" Tabs / indentation
set expandtab
set smarttab
set tabstop=4
set softtabstop=4
set shiftwidth=4
set shiftround
" Search
set hlsearch
set incsearch
set ignorecase
set smartcase
set gdefault
set magic
set wrapscan
" Diff
set diffopt=filler
set diffopt+=iwhite
" Folding
set foldenable
set foldmethod=syntax
set foldlevel=2
set foldnestmax=3
set foldcolumn=4
set foldminlines=0
" Formatting
set formatoptions=cronq2l1
" Wildmenu / completion
set wildmenu
set wildchar=<TAB>
set wildmode=list:longest
set wildignore+=*.jpg,*.jpeg,*.gif,*.png,*.psd,*.o,*.obj,*.min.js
set wildignore+=*/smarty/*,*/vendor/*,*/node_modules/*,*/.git/*,*/.hg/*,*/.svn/*
set wildignore+=*/.sass-cache/*,*/log/*,*/tmp/*,*/build/*,*/ckeditor/*,*_build/*
set wildignore+=*/coverage/*,*.pyc
set suffixes=.bak,~,.swp,.swo,.o,.d,.info,.aux,.log,.dvi,.pdf,.bin,.bbl,.blg
set suffixes+=.brf,.cb,.dmg,.exe,.ind,.idx,.ilg,.inx,.out,.toc,.pyc,.pyd,.dll
set ofu=syntaxcomplete#Complete
" Line numbers
set number
set relativenumber
" Lisp word lists
set lispwords+=defroutes
set lispwords+=defpartial,defpage
set lispwords+=defaction,deffilter,defview,defsection
set lispwords+=describe,it
" Whitespace visualization
set lcs=tab:›\ ,trail:·,eol:¬,nbsp:_
set fcs=fold:-
" Paste toggle
set pastetoggle=<F2>
set clipboard=unnamed
" GUI
if has('gui_running')
set guifont=Monaco:h12
set guioptions=egmrt
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Faster escape from insert mode
inoremap jk <esc>
" Quicksave
nnoremap <C-Z> :update<CR>
vnoremap <C-Z> <C-C>:update<CR>
inoremap <C-Z> <C-O>:update<CR>
" Paste toggle (also F2)
map <leader>p :set invpaste paste?<CR>
" netrw split
nnoremap <leader>pv :Vex<CR>
" Quick quit
noremap <leader>e :quit<CR>
noremap <leader>E :qa!<CR>
" Sudo write
noremap <leader>W :w !sudo tee %<CR>
command! W w
" Tabs
map <leader>n <esc>:tabprevious<CR>
map <leader>m <esc>:tabnext<CR>
nnoremap <leader>nt :tabnew<CR>
" Faster split resizing
if bufwinnr(1)
map + <C-W>+
map - <C-W>-
endif
" Scroll viewport 3 lines at a time
nnoremap <C-e> 3<C-e>
nnoremap <C-y> 3<C-y>
" Helpers for 2-space tabs / spaces
nmap \t :set ts=2 sts=2 sw=2 noet<cr>
nmap \s :set ts=2 sts=2 sw=2 et<cr>
" Better mark jump (line + col)
nnoremap ' `
" Hard-to-type characters
imap >> →
imap << ←
imap ^^ ↑
imap VV ↓
imap aa λ
" Toggle list (show tabs / trailing spaces)
nnoremap <silent> <leader>c :set nolist!<CR>
" Clear last search
map <silent> <leader>qs <Esc>:noh<CR>
" Indent / unindent block
nnoremap <leader>i] >i{<CR>
nnoremap <leader>i[ <i{<CR>
" Yank to EOL
nnoremap Y y$
" Insert blank line below without entering insert
map <leader><Enter> o<ESC>
" Search and replace word under cursor
nnoremap <leader>* :%s/\<<C-r><C-w>\>//<Left>
" Join lines, keep cursor put
nnoremap J mjJ`j
" Toggle fold under cursor
nnoremap <silent> <space> :exe 'silent! normal! '.((foldclosed('.')>0)? 'zMzx' : 'zc')<CR>
" Fix PageUp / PageDown
map <PageUp> <C-U>
map <PageDown> <C-D>
imap <PageUp> <C-O><C-U>
imap <PageDown> <C-O><C-D>
" Edit / source vimrc
nnoremap <leader>v :e ~/.vimrc<CR>
nnoremap <leader>V :tabnew ~/.vimrc<CR>
nnoremap <leader><CR> :so ~/.vimrc<CR>
" tmux-sessionizer
nnoremap <silent> <C-f> :silent !tmux neww tmux-sessionizer<CR>
" Vim on iPad
if &term == "xterm-ipad"
nnoremap <Tab> <Esc>
vnoremap <Tab> <Esc>gV
onoremap <Tab> <Esc>
inoremap <Tab> <Esc>`^
inoremap <Leader><Tab> <Tab>
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Move-to-window-or-create
function! WinMove(key)
let t:curwin = winnr()
exec "wincmd ".a:key
if (t:curwin == winnr())
if (match(a:key,'[jk]'))
wincmd v
else
wincmd s
endif
exec "wincmd ".a:key
endif
endfunction
" Swap lines up / down
function! s:swap_lines(n1, n2)
let line1 = getline(a:n1)
let line2 = getline(a:n2)
call setline(a:n1, line2)
call setline(a:n2, line1)
endfunction
function! s:swap_up()
let n = line('.')
if n == 1 | return | endif
call s:swap_lines(n, n - 1)
exec n - 1
endfunction
function! s:swap_down()
let n = line('.')
if n == line('$') | return | endif
call s:swap_lines(n, n + 1)
exec n + 1
endfunction
noremap <silent> <c-s-p> :call <SID>swap_down()<CR>
noremap <silent> <c-s-o> :call <SID>swap_up()<CR>
" Strip trailing whitespace
function! StripWhitespace()
let save_cursor = getpos(".")
let old_query = getreg('/')
:%s/\s\+$//e
call setpos('.', save_cursor)
call setreg('/', old_query)
endfunction
noremap <leader>ss :call StripWhitespace()<CR>
" Toggle relative / absolute line numbers
function! NumberToggle()
if(&relativenumber == 1)
set norelativenumber
set number
else
set relativenumber
endif
endfunc
nnoremap <leader>l :call NumberToggle()<cr>
" Absolute in insert / on focus loss, relative everywhere else
augroup numbertoggle
autocmd!
autocmd FocusLost * set norelativenumber
autocmd FocusGained * set relativenumber
autocmd InsertEnter * set norelativenumber
autocmd InsertLeave * set relativenumber
augroup END
" Omni-completion popup nav with C-j / C-k
function! OmniPopup(action)
if pumvisible()
if a:action == 'j'
return "\<C-N>"
elseif a:action == 'k'
return "\<C-P>"
endif
endif
return a:action
endfunction
inoremap <silent><C-j> <C-R>=OmniPopup('j')<CR>
inoremap <silent><C-k> <C-R>=OmniPopup('k')<CR>
" Restore cursor position on file open
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin Configuration
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" --- fzf.vim (replaces CtrlP) -------------------------------------------
nmap <silent> <leader>t :Files<CR>
nmap <silent> <leader>r :Buffers<CR>
nmap <silent> <leader>. :Tags<CR>
nmap <silent> <leader>/ :Rg<CR>
let g:fzf_layout = { 'down': '~30%' }
" --- ALE (replaces Syntastic) -------------------------------------------
let g:ale_linters = {
\ 'javascript': ['standard', 'eslint'],
\ 'python': ['flake8', 'pyright'],
\ 'go': ['gopls', 'golangci-lint'],
\}
let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\ 'javascript': ['prettier', 'eslint'],
\ 'python': ['black', 'isort'],
\}
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'never'
let g:ale_sign_error = '✗'
let g:ale_sign_warning = '⚠'
nnoremap <leader>af :ALEFix<CR>
nmap <silent> <C-n> <Plug>(ale_next_wrap)
nmap <silent> <C-m> <Plug>(ale_previous_wrap)
" --- NERDTree -----------------------------------------------------------
let NERDTreeShowHidden=1
let g:NERDTreeQuitOnOpen=0
nnoremap <F5> :NERDTreeToggle<CR>
nmap <silent> <leader>k :NERDTreeToggle<cr>
nmap <silent> <leader>y :NERDTreeFind<cr>
" --- Buffer navigation --------------------------------------------------
map <Leader>, <C-^>
map <Leader>] :bnext<CR>
map <Leader>[ :bprev<CR>
map <Leader>ls :buffers<CR>
map <leader>qq :cclose<CR>
" --- UltiSnips ----------------------------------------------------------
let g:UltiSnipsExpandTrigger="<c-l>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
" --- Airline ------------------------------------------------------------
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'
let g:airline#extensions#ale#enabled = 1
" --- vim-go -------------------------------------------------------------
let g:go_fmt_command = "goimports"
let g:go_fmt_autosave = 0
let g:go_list_type = "quickfix"
autocmd FileType go nmap <leader>gb <Plug>(go-build)
autocmd FileType go nmap <leader>gr <Plug>(go-run)
" --- gitgutter ----------------------------------------------------------
set updatetime=250
let g:gitgutter_map_keys = 0
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Filetype-specific
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
au BufRead,BufNewFile *.json set ft=json syntax=javascript
au BufRead,BufNewFile *.jade set ft=jade syntax=jade
au BufRead,BufNewFile Rakefile,Capfile,Gemfile,.autotest,.irbrc,*.treetop,*.tt set ft=ruby syntax=ruby
au BufNewFile,BufRead *.nu,*.nujson,Nukefile setf nu
au BufNewFile,BufReadPost *.coffee setl foldmethod=indent nofoldenable
au BufRead,BufNewFile .zsh_rc,.functions,.commonrc set ft=zsh