-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvimrc
356 lines (276 loc) · 9.1 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
" Using this vimrc:
"
" Install vim plug: https://github.com/junegunn/vim-plug#usage
" run: mkdir ~/.vim/backup
" run: mkdir ~/.vim/tmp
" copy this code to ~/.vimrc
" open this file in vim
" run :PlugInstall
call plug#begin('~/.vim/plugged')
" sensible defaults
Plug 'tpope/vim-sensible'
" project-wide find and replace
Plug 'Olical/vim-enmasse'
" rust syntax highlighting, auto-formatting etc
Plug 'rust-lang/rust.vim'
" using to pull current git branch into status bar
Plug 'tpope/vim-fugitive'
" useful for tab completing
Plug 'ervandew/supertab'
" not sure if I use this
Plug 'tpope/vim-bundler'
" useful for quickly commenting code
Plug 'tpope/vim-commentary'
" useful for auto-ending ruby methods/classes/blocks
Plug 'tpope/vim-endwise'
" not sure if I use this one
Plug 'tpope/vim-eunuch'
" search the codebase with rg (ripgrep)
Plug 'jremmen/vim-ripgrep'
" Visualizes recent changes so you can undo with confidence
Plug 'sjl/gundo.vim'
" Adds a column on the left indicating which lines have changed
Plug 'airblade/vim-gitgutter'
" Remembers where your cursor was in each file and takes you there
Plug 'dietsche/vim-lastplace'
" Syntax highlighting for terraform .tf files
Plug 'hashivim/vim-terraform'
" Syntax highlighting for javascript files
Plug 'pangloss/vim-javascript'
" Syntax highlighting for jsx files
Plug 'mxw/vim-jsx'
" Syntax highlighting for toml config files
Plug 'cespare/vim-toml'
" Syntax highlighting for elm files
Plug 'ElmCast/elm-vim'
" Syntax highlighting for TypeScript files
Plug 'leafgarland/typescript-vim'
" Syntax highlighting for .tsx files
Plug 'peitalin/vim-jsx-typescript'
" Fuzzy file finder to open files
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
" Insert Co-Authored-By lines into commit messages
Plug 'maxjacobson/vim-fzf-coauthorship'
Plug 'maxjacobson/vim-plug-periodic-status'
" Asynchronous Lint Engine, for invoking things like rubocop, eslint, and
" prettier automatically
Plug 'dense-analysis/ale'
" Syntax-highlighting for .github/CODEOWNERS files
Plug 'rhysd/vim-syntax-codeowners'
Plug 'pbrisbin/vim-mkdir'
Plug 'preservim/tagbar'
Plug 'ludovicchabant/vim-gutentags'
call plug#end()
" press jk to exit insert mode
inoremap jk <ESC>
inoremap JK <ESC>
let mapleader = ","
" help it do the syntax recognition right
syntax on
filetype on
au BufNewFile,BufRead *.jbuilder set filetype=ruby
au BufNewFile,BufRead Brewfile set filetype=ruby
au BufNewFile,BufRead .Brewfile set filetype=ruby
autocmd BufRead,BufNewFile .env* set ft=dotenv
" N.B. this assumes you're using a nice modern terminal emulator like
" Alacritty or iTerm 2
"
" (This won't work with macOS's Terminal.app)
set termguicolors
colorscheme smyck
" smart backspacing
set backspace=indent,eol,start
" smart indents
filetype plugin indent on
set tabstop=2
set softtabstop=2
set shiftwidth=2
set expandtab
set autoindent
set smartindent
au BufRead,BufNewFile *.rb set shiftwidth=2
au BufRead,BufNewFile *.rb set softtabstop=2
au BufRead,BufNewFile *.rb set tabstop=2
au BufRead,BufNewFile *.py set shiftwidth=4
au BufRead,BufNewFile *.py set softtabstop=4
au BufRead,BufNewFile *.py set tabstop=4
au BufRead,BufNewFile *.fish set shiftwidth=4
au BufRead,BufNewFile *.fish set softtabstop=4
au BufRead,BufNewFile *.fish set tabstop=4
au BufRead,BufNewFile *.tsx set shiftwidth=2
au BufRead,BufNewFile *.tsx set softtabstop=2
au BufRead,BufNewFile *.tsx set tabstop=2
set number " show line numbers
set showcmd " shows commands (try `55 j` for example and look in the bottom right)
set ignorecase " ignores case when search
set hlsearch " highlights search
" this chunk makes it so lines wrap nicely without chopping words in half
set wrap
set linebreak
set nolist
set textwidth=0
set wrapmargin=0
set list
set listchars=tab:\ \ ,trail:.,extends:#,nbsp:.
"Treat long lines as break lines (useful when moving around in them)
map j gj
map k gk
"clear search with <Leader>/
nmap <silent> <Leader>/ :nohlsearch<CR>
" jump to the list of files with <Leader>e
nmap <silent> <Leader>e :Explore<CR>jj
nnoremap <c-\> :Explore<CR>
"move backup files all into one place
set backup
set backupdir=~/.vim/backup,.
set directory=~/.vim/tmp,.
nnoremap gu :GundoToggle<CR>
function! LinterStatus() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? 'OK' : printf(
\ '%dW %dE',
\ all_non_errors,
\ all_errors
\)
endfunction
" status line
set laststatus=2
"%f = file path
"%l:%c = line and column
"%m file modified flag ([+] when there are unsaved changes)
set statusline=%F\ %l:%c\ %m\ %{LinterStatus()}
" editing
set nowrap
" splitting
set splitright
set splitbelow
" folding
set foldmethod=indent
set nofoldenable
set foldlevel=1
set foldnestmax=10
" Tab mappings.
" via https://github.com/edgibbs/.vim/blob/master/vimrc#L55-L64
map <leader>tt :tabnew<cr>
map <leader>te :tabedit
map <leader>tc :tabclose<cr>
map <leader>to :tabonly<cr>
map <leader>tn :tabnext<cr>
map <leader>tp :tabprevious<cr>
map <leader>tf :tabfirst<cr>
map <leader>tl :tablast<cr>
map <leader>tm :tabmove
" hide the giant banner at the top of netrw
let g:netrw_banner=0
" when selecting a file from netrw, how large to make the new window
" (hint: press o or v to open the file in a split)
let g:netrw_winsize=85
" via toranb dotfiles
nnoremap <Leader>fr :call VisualFindAndReplace()<CR>
xnoremap <Leader>fr :call VisualFindAndReplaceWithSelection()<CR>
function! VisualFindAndReplace()
:OverCommandLine%s/
:w
endfunction
function! VisualFindAndReplaceWithSelection() range
:'<,'>OverCommandLine s/
:w
endfunction
" use system clipboard
" N.B. if you switch to neovim, you should change this to
" set clipboard=unnamed,unnamedplus
set clipboard=unnamed
set hidden
" Don't accidentally enter Ex mode
" http://www.bestofvim.com/tip/leave-ex-mode-good/
nnoremap Q <nop>
" While I'm at it, disable K to lookup man pages
" I never use it on purpose...
nnoremap K <nop>
" help make sure quickfix text is readable
highlight Search cterm=NONE ctermfg=white ctermbg=red
let g:lastplace_ignore = "gitcommit,gitrebase,conf"
let g:rustfmt_autosave = 1
let g:terraform_fmt_on_save = "1"
let g:elm_format_autosave = 1
" Invokes fzf.vim's fuzzy file picker
:map <c-p> :Files<cr>
" Customize fzf colors to match your color scheme
" - fzf#wrap translates this to a set of `--color` options
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
let g:fzf_buffers_jump = 1
let g:fzf_layout = { 'down': '50%' }
set mouse=a
nmap <silent> <C-g> :Coauthorship<CR>
" Adding for the sake of making :Rg use smartcase, may have other side-effects
set smartcase
" Help make sure syntax highlighting doesn't get confused halfway thru long
" files
"
" Via https://thoughtbot.com/blog/modern-typescript-and-react-development-in-vim
autocmd BufEnter *.{js,jsx,ts,tsx} :syntax sync fromstart
autocmd BufLeave *.{js,jsx,ts,tsx} :syntax sync clear
" use actual tabs over spaces when editing ~/.gitconfig
autocmd FileType gitconfig setlocal noexpandtab
let g:ale_linters_explicit = 1
let g:ale_linters= {
\ 'bash': ['shellcheck'],
\ 'eruby': ['erblint'],
\ 'fish': ['fish', 'fish_indent'],
\ 'ruby': ['rubocop', 'sorbet', 'standardrb'],
\ 'javascript': ['eslint', 'stylelint'],
\ 'typescript': ['eslint'],
\ 'jsx': ['stylelint', 'eslint'],
\ 'scss': ['stylelint'],
\ 'sh': ['shellcheck'],
\}
let g:ale_fixers = {
\ 'css': ['prettier'],
\ 'fish': ['fish_indent'],
\ 'ruby': ['rubocop', 'standardrb', 'prettier'],
\ 'javascript': ['prettier'],
\ 'jsx': ['prettier'],
\ 'json': ['prettier'],
\ 'markdown': ['prettier'],
\ 'scss': ['prettier'],
\ 'typescript': ['prettier'],
\ 'typescriptreact': ['prettier'],
\}
let g:ale_ruby_rubocop_executable = "bin/rubocop"
let g:ale_ruby_standardrb_executable = "bin/standardrb"
let g:ale_eruby_erblint_executable = "bin/erb_lint"
let g:ale_fix_on_save = 1
" Highlight curent line number
" These colors come from my preferred color scheme, Smyck
" https://color.smyck.org
" Tip via https://hachyderm.io/@VimLinks/111223586086176442
set cursorline
hi! link CursorLine Normal
hi my_bg guifg=#b0b0b0 guibg=#292929
hi my_bg_cursor guifg=#fbb1f9 guibg=#292929
hi! link LineNr my_bg
hi! link CursorLineNr my_bg_cursor
" Store tags file out of the way so I don't need to add it to .gitignore in
" every project
let g:gutentags_ctags_tagfile = ".git/tags"
" only generate tags for non-gitignore files
let g:gutentags_file_list_command = "fd --type file --hidden --exclude .git"
" configure vim to look at the tags file generated by gutentags (.git/tags)
" instead of the one at the default location (./tags)
let g:gutentags_ctags_auto_set_tags = 1