/
vimrc
360 lines (290 loc) · 11 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
" General
set nocompatible
set hidden " allow unsaved background buffers
set history=1000
set autoread " reload files (no local changes only)
set modeline " make sure modeline support is enabled
filetype plugin indent on " load filetype plugin
set isk+=_,$,@,%,#,- " non word dividers
" UTF-8 default encoding
set enc=utf-8
" ----------------------------------------------------------------------------
" Platform detection
" ----------------------------------------------------------------------------
let s:platform = system("uname")
let s:on_linux = s:platform =~? "linux"
let s:on_mac = has('macunix') || s:platform =~? "Darwin"
" ----------------------------------------------------------------------------
" Tabularize
" ----------------------------------------------------------------------------
if exists(":Tabularize")
nmap <Leader>a=> :Tabularize /=><CR>
vmap <Leader>a=> :Tabularize /=><CR>
nmap <Leader>a= :Tabularize /=<CR>
vmap <Leader>a= :Tabularize /=<CR>
nmap <Leader>a: :Tabularize /:\zs<CR>
vmap <Leader>a: :Tabularize /:\zs<CR>
endif
" ----------------------------------------------------------------------------
" GUI
" ----------------------------------------------------------------------------
if has("gui_running")
if has("gui_macvim")
set guifont=Fira\ Code:h12
set linespace=1
else
set guifont=DejaVu\ Sans\ Mono\ 9
endif
" Hide the toolbar
set go-=T
" Hide the scrollbar
set go-=r
" Default window size
if &lines < 50
set lines=50
endif
if &columns < 80
set columns=80
endif
else
" Enable true color support
if has("termguicolors")
set termguicolors
" Set escapes manually, so they work in tmux (see ':h xterm-true-color')
let &t_8f = "[38;2;%lu;%lu;%lum"
let &t_8b = "[48;2;%lu;%lu;%lum"
endif
" Highlight current line in console mode
set cursorline
endif
" ----------------------------------------------------------------------------
" Color scheme
" ----------------------------------------------------------------------------
set background=dark
color base16-oceanicnext
" ----------------------------------------------------------------------------
" UI
" ----------------------------------------------------------------------------
set ruler " show the cursor position all the time
set nolazyredraw " turn off lazy redraw
set relativenumber " relative line numbers
set ch=1 " command line height
set backspace=2 " allow backspacing over everything in insert mode
set whichwrap+=<,>,h,l,[,] " backspace and cursor keys wrap to
set shortmess=filtIoOA " shorten messages
set report=0 " tell us about changes
set nostartofline " don't jump to the start of line when scrolling
set wildmenu " turn on wild menu
set wildmode=list:longest,full
set infercase
set completeopt=longest,menu,menuone
set wildignore+=*.o,*.obj,*.pyc,*.DS_STORE,*.sqlite3
" ----------------------------------------------------------------------------
" Visual Cues
" ----------------------------------------------------------------------------
set showmatch " brackets/braces that is
set mat=5 " duration to show matching brace (1/10 sec)
set laststatus=2 " always show the status line
set nohlsearch " don't highlight searches
set novisualbell " don't blink
set noerrorbells " shut the fuck up
" ----------------------------------------------------------------------------
" Text Formatting
" ----------------------------------------------------------------------------
set autoindent " automatic indent new lines
set smartindent " be smart about it
set nowrap " do not wrap lines
set softtabstop=2 " yep, two
set shiftwidth=2 " ..
set shiftround " ... + > = .... (4) instead of ..... (5)
set tabstop=4
set expandtab " expand tabs to spaces
set nosmarttab " fuck tabs
set formatoptions+=n " support for numbered/bullet lists
set formatoptions-=t " never wrap code
set textwidth=80 " wrap at 80 chars by default
set virtualedit=block " allow virtual edit in visual block ..
" Wrap text sometimes
autocmd BufRead *.{md,markdown,txt} set formatoptions+=t
" Handlebars is HTML
autocmd BufRead *.{hjs,handlebars} set ft=html
" Use hard tabs when absolutely necessary
autocmd FileType make set noexpandtab
" Syntax highlighting
syntax on
" Highlight trailing whitespace
set list listchars=trail:.,tab:>.
" Search & Replace
set ignorecase
set smartcase
set incsearch
" ----------------------------------------------------------------------------
" Navigation
" ----------------------------------------------------------------------------
" Tab navigation
map <D-S-]> gt
map <D-S-[> gT
map <D-S-1> 1gt
map <D-S-2> 2gt
map <D-S-3> 3gt
map <D-S-4> 4gt
map <D-S-5> 5gt
map <D-S-6> 6gt
map <D-S-7> 7gt
map <D-S-8> 8gt
map <D-S-9> 9gt
map <D-S-0> :tablast<CR>
" Split-screen navigation
map <C-J> <C-W>j
map <C-K> <C-W>k
map <C-H> <C-W>h
map <C-L> <C-W>l
set wmh=0 " Allow splits to be zero-height
" , is easier to reach than backspace
let mapleader=","
" ----------------------------------------------------------------------------
" Help
" ----------------------------------------------------------------------------
autocmd FileType help noremap <buffer> q :helpclose<CR>
autocmd FileType typescript nnoremap <silent><buffer> K :ALEHover<CR>
" ----------------------------------------------------------------------------
" Lightline
" ----------------------------------------------------------------------------
let g:lightline = {
\ 'colorscheme': 'base16',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'gitbranch': 'fugitive#head'
\ },
\ }
function! LightlineReload()
runtime autoload/lightline/colorscheme/base16.vim
call lightline#init()
call lightline#colorscheme()
call lightline#update()
endfunction
" ----------------------------------------------------------------------------
" fzf.vim
" ----------------------------------------------------------------------------
nmap <leader>f :GFiles<CR>
nmap <leader>r :Tags<CR>
nmap <leader>b :Buffers<CR>
" ----------------------------------------------------------------------------
" .vimrc editing
" ----------------------------------------------------------------------------
" Automatically reload .vimrc after save
autocmd! BufWritePost .vimrc source % | call LightlineReload()
nmap <leader>v :e $MYVIMRC<CR>
" ----------------------------------------------------------------------------
" ALE
" ----------------------------------------------------------------------------
let g:ale_fixers = {
\ 'css': ['prettier'],
\ 'javascript': ['prettier', 'eslint'],
\ 'typescript': ['prettier', 'eslint'],
\ 'typescriptreact': ['prettier', 'eslint'],
\ }
let g:ale_fix_on_save = 1
let g:ale_sign_error = '❌'
let g:ale_sign_warning = '⚠️'
let g:ale_sign_info = '💬'
" eslint_d configuration
let g:ale_javascript_eslint_executable = 'eslint_d'
let g:ale_javascript_eslint_use_global = 1
" Remove this line if you adopt another completion plugin, like Deoplete
let g:ale_completion_enabled = 1
nnoremap <silent> <C-]> :ALEGoToDefinition<CR>
nnoremap <silent> gd :ALEGoToDefinition<CR>
nnoremap <silent> gr :ALEFindReferences -relative<CR>
nnoremap <silent> dm :ALEDetail<CR>
nmap <silent> ]w <Plug>(ale_next_wrap)
nmap <silent> [w <Plug>(ale_previous_wrap)
" ----------------------------------------------------------------------------
" Git (Fugitive)
" ----------------------------------------------------------------------------
" Auto-clean fugitive buffers
autocmd BufReadPost fugitive://* set bufhidden=delete
nnoremap <leader>gd :Gdiff<cr>
nnoremap <leader>gD :diffoff!<cr><c-w>h:bd<cr>
" ----------------------------------------------------------------------------
" Gist
" ----------------------------------------------------------------------------
let g:gist_detect_filetype = 1
if s:on_mac
let g:gist_clip_command = 'pbcopy'
elseif s:on_linux
let g:gist_clip_command = 'xclip -selection clipboard'
endif
" ----------------------------------------------------------------------------
" Golang
" ----------------------------------------------------------------------------
autocmd FileType go setlocal nolist noexpandtab ts=4 sw=4 sts=0 tw=0
" ----------------------------------------------------------------------------
" TypeScript
" ----------------------------------------------------------------------------
autocmd FileType typescript setlocal commentstring=//\ %s
autocmd FileType typescriptreact setlocal commentstring=//\ %s
" ----------------------------------------------------------------------------
" Relative :edit shortcuts
" ----------------------------------------------------------------------------
" Scratch toggle (scratch.vim)
function! ToggleScratch()
if expand('%') == g:ScratchBufferName
quit
else
Sscratch
endif
endfunction
map <leader>s :call ToggleScratch()<CR>
" ---------------------------------------------------------------------------
" Haskell
" ---------------------------------------------------------------------------
" use ghc functionality for haskell files
au Bufenter *.hs compiler ghc
" Configure browser for haskell_doc.vim
let g:haddock_browser = "open"
let g:haddock_browser_callformat = "%s %s"
" ---------------------------------------------------------------------------
" Strip all trailing whitespace in file
" ---------------------------------------------------------------------------
function! StripWhitespace()
exec ':%s/ \+$//gc'
endfunction
map <leader>w :call StripWhitespace()<CR>
" The Silver Searcher
if executable('ag')
" Use ag over grep
set grepprg=ag\ --nogroup\ --nocolor
endif
" Backup
set backupdir=~/.vim/backup
set directory=~/.vim/swap//
set backup
" ---------------------------------------------------------------------------
" Rename current file (hat tip @garybernhardt)
" ---------------------------------------------------------------------------
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'), 'file')
if new_name != '' && new_name != old_name
exec ':Move ' . new_name
endif
endfunction
map <leader>n :call RenameFile()<cr>
" ---------------------------------------------------------------------------
" Multipurpose tab key: (hat tip @garybernhardt, again)
" Indent if we're at the beginning of a line. Else, do completion.
" ---------------------------------------------------------------------------
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
inoremap <s-tab> <c-n>