-
Notifications
You must be signed in to change notification settings - Fork 67
/
vimrc
308 lines (288 loc) · 11.5 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
" Spacebar is a much better leader than \ or ,
let mapleader = "\<Space>"
""""" PLUGINS """""
call plug#begin()
" ESSENTIALS
Plug 'andymass/vim-matchup' " enhanced % (NOTE: must come before vim-sensible)
Plug 'tpope/vim-sensible' " Sensible defaults
Plug 'rstacruz/vim-opinion' " More sensible defaults
Plug 'ervandew/supertab' " Tab complete everything
Plug 'ctrlpvim/ctrlp.vim' " Fuzzy-matching go-to file
nnoremap <C-b> :CtrlPBuffer<CR>
map <C-t> :CtrlPBufTag<CR>
" Make ctrlp faster
let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard']
if has('python') || has('python3')
" Faster and more accurate fuzzy-matching
Plug 'felikz/ctrlp-py-matcher'
let g:ctrlp_match_func = { 'match': 'pymatcher#PyMatch' }
endif
" rg-powered search with in-place editing
Plug 'dyng/ctrlsf.vim'
let g:ctrlsf_ackprg = 'rg'
let g:ctrlsf_auto_focus = {'at': 'start'} " Automatically focus search results
nmap <C-f>f :CtrlSF ''<Left>
nmap <C-f>n <Plug>CtrlSFCwordPath
nnoremap <C-f>t :CtrlSFToggle<CR>
Plug 'tpope/vim-rsi' " unix keybindings in insert mode
Plug 'tpope/vim-repeat' " make more actions repeatable with .
Plug 'tpope/vim-surround' " motions for handling surrounding characters
Plug 'tpope/vim-unimpaired' " useful bracket maps and option toggling
" Toggle comment with space-/
Plug 'tpope/vim-commentary' " for code comments
nmap <leader>/ <Plug>CommentaryLine
vmap <leader>/ <Plug>Commentary
" Buffers
Plug 'moll/vim-bbye' " delete buffer without closing window
nnoremap X :Bdelete<CR>
Plug 'vim-scripts/BufOnly.vim' " delete all but current buffer
Plug 'scrooloose/nerdtree', {'on': ['NERDTreeToggle', 'NERDTreeFind']}
nnoremap <leader>d :NERDTreeToggle<CR>
nnoremap <leader>D :NERDTreeFind<CR>
let NERDTreeIgnore = ['\.pyc', '__pycache__', '.egg-info[[dir]]', 'pip-wheel-metadata[[dir]]']
Plug 'w0rp/ale' " Async linting
nmap <silent> [s <Plug>(ale_previous_wrap)
nmap <silent> ]s <Plug>(ale_next_wrap)
nmap <leader>= <Plug>(ale_fix)
let g:ale_pattern_options = {
\ '.*\.md$': {'ale_enabled': 0},
\ '.*\.markdown$': {'ale_enabled': 0},
\ '.*\.rst$': {'ale_enabled': 0},
\ '.*\.txt$': {'ale_enabled': 0},
\ '.*\.tex$': {'ale_enabled': 0},
\}
nmap <leader>- :ALEToggleBuffer<cr>
let g:ale_fix_on_save = 1
" nnoremap <leader>+ :let g:ale_fix_on_save = !g:ale_fix_on_save<cr>
nnoremap <leader>+ :call ToggleFixOnSave()<cr>
function! ToggleFixOnSave()
let g:ale_fix_on_save = !g:ale_fix_on_save
echo g:ale_fix_on_save == 1 ? "ale_fix_on_save enabled" : "ale_fix_on_save disabled"
endfunction
" Quickly open the loclist to see syntax errors
nmap <leader>' :lopen<CR>
let g:ale_maximum_file_size = 500000 " Don't lint large files (> 500KB), it can slow things down
let g:ale_linters = {}
let g:ale_linters.javascript = ['eslint', 'tsserver']
let g:ale_linters.typescript = ['eslint', 'tsserver']
let g:ale_linters.python = ['flake8', 'mypy', 'pyls']
let g:ale_linters.html = []
let g:ale_fixers = {}
let g:ale_fixers.javascript = ['prettier']
let g:ale_fixers.typescript = ['prettier']
let g:ale_fixers.python = ['black']
let g:ale_fixers.css = ['prettier']
let g:ale_completion_enabled = 1
" Prevent completion from autoinserting. See :help ale-completion-completopt-bug
set completeopt=menu,menuone,noselect,noinsert
" Disable pycodestyle in pyls; let flake8 do that
let g:ale_python_pyls_config = {'pyls': {'plugins': {'pycodestyle': {'enabled': v:false}}}}
nmap gd <Plug>(ale_go_to_definition)
" NICE TO HAVE
Plug 'AndrewRadev/splitjoin.vim' " Language-specific split/join with gS and gJ
let g:splitjoin_python_brackets_on_separate_lines = 1
let g:splitjoin_trailing_comma = 1
Plug 'vim-airline/vim-airline' | Plug 'vim-airline/vim-airline-themes'
let g:airline_left_sep=''
let g:airline_right_sep=''
let g:airline_theme='tomorrow'
" Explicitly specify which extensions to use
let g:airline_extensions = ['branch', 'ctrlp', 'tabline', 'ale', 'whitespace']
Plug 'christoomey/vim-tmux-navigator'
Plug 'jszakmeister/vim-togglecursor' " change cursor shape when entering insert mode
" Snippets
if version >= 704 && has('python') || has('python3') | Plug 'SirVer/ultisnips' | endif
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-k>"
Plug 'honza/vim-snippets'
Plug 'fcpg/vim-spotlightify' " Highlight and show number of matches when searching
Plug 'wellle/targets.vim' " because cin), etc. is awesome
Plug 'tpope/vim-dispatch' " So we can run tests asynchronously
Plug 'janko-m/vim-test' " For running tests
let test#python#runner = 'pytest'
nmap <silent> <leader>tt :TestNearest<CR>
nmap <silent> <leader>tT :TestNearest --snapshot-update<CR>
nmap <silent> <leader>tf :TestFile<CR>
nmap <silent> <leader>tF :TestFile --snapshot-update<CR>
nmap <silent> <leader>tl :TestLast<CR>
nmap <silent> <leader>tL :TestLast --snapshot-update<CR>
let test#strategy = "dispatch"
" -s for ipdb support; disable cacheprovider so we don't break 'py.test --lf'
let test#python#pytest#options = '-s -p no:cacheprovider'
Plug 'mattn/emmet-vim' " Write HTML fast
" When in javascript, expand to 'className' (for jsx support)
let g:user_emmet_settings = {
\ 'javascript': {'extends': 'jsx'},
\ 'javascript.jsx': {'extends': 'jsx'}
\ }
Plug 'jiangmiao/auto-pairs' " autoclose parens, quotes, etc.
autocmd FileType python let b:AutoPairs = AutoPairsDefine({'f"': '"', "f'": "'"})
Plug 'mtth/scratch.vim'
let g:scratch_no_mappings = 1
let g:scratch_height = 20
let g:scratch_filetype = 'markdown'
let g:scratch_persistence_file = '.scratch'
" Open scratch buffer with space-tab (automatically set syntax to markdown)
nnoremap <silent> <leader><tab> :Scratch<cr>
Plug 'tpope/vim-sleuth' " Detect indent settings
Plug 'machakann/vim-highlightedyank' " Highlight yank
if !exists('##TextYankPost') | map y <Plug>(highlightedyank) | endif
" GIT
Plug 'airblade/vim-gitgutter'
" Set gitgutter's bindings manually to avoid clashes
let g:gitgutter_map_keys = 0
nmap <leader>gh <Plug>(GitGutterStageHunk)
nmap <leader>gH <Plug>(GitGutterUndoHunk)
nmap [h <Plug>(GitGutterPrevHunk)
nmap ]h <Plug>(GitGutterNextHunk)
set updatetime=200 " faster updates
Plug 'tpope/vim-fugitive' " git integration
Plug 'tpope/vim-rhubarb' " For :Gbrowse
map <leader>gs :Git<CR>
map <leader>gb :Git blame<CR>
" Open current file on Github
map <leader>gB :GBrowse<CR>
" Open currently selected lines on Github
vmap <leader>gB :GBrowse<CR>
map <leader>gr :GRead<CR>
map <leader>gw :GWrite<CR>
Plug 'mattn/webapi-vim' | Plug 'mattn/gist-vim', {'on': 'Gist'}
" Make gists private by default
let g:gist_post_private = 1
" Browse to gist after posting it
let g:gist_open_browser_after_post = 1
" Use gr to replace text without blowing away clipboard
Plug 'vim-scripts/ReplaceWithRegister'
Plug 'majutsushi/tagbar', {'on': 'Tagbar'}
" Open tagbar
map <leader>\ :Tagbar<CR>
let g:tagbar_autofocus = 1
" COLOR
Plug 'NLKNguyen/papercolor-theme'
Plug 'sloria/vim-hybrid' " hybrid with easier-to-read line numbers
" LANGUAGE-SPECIFIC
Plug 'sheerun/vim-polyglot' " syntax files for most languages
let g:polyglot_disabled = ['python', 'latex', 'typescript'] " Use python-syntax and vimtex
let g:jsx_ext_required = 0
let g:markdown_fenced_languages = ['javascript', 'python', 'clojure', 'ruby']
Plug 'leafgarland/typescript-vim'
Plug 'jparise/vim-graphql'
Plug 'lervag/vimtex'
let g:tex_flavor = 'latex'
" --- Python ---
Plug 'vim-python/python-syntax' " Improved python syntax
let g:python_highlight_all = 1
Plug 'Vimjas/vim-python-pep8-indent' " Proper python indenting
" --- Javascript ---
Plug 'heavenshell/vim-jsdoc' " For making JS docstrings
map <C-c>j <Plug>(jsdoc)
" --- CSS ---
Plug 'chrisbra/Colorizer' " Highlight CSS colors
let g:colorizer_auto_filetype='css,html'
call plug#end()
filetype plugin indent on
""" end plugins """
""" BASE CUSTOMIZATIONS """
" NOTE: Many base customizations come from vim-sensible and vim-opinion
set encoding=utf-8
set relativenumber
set autoread " reload files when changed on disk, i.e. via `git checkout`
set clipboard^=unnamedplus,unnamed " Make "yanks" work with system clipboard
set exrc secure " Project-specific vimrcs
" Indents
set autoindent
set expandtab " expand tabs by default (overloadable per file type later)
set tabstop=4 softtabstop=4 shiftwidth=4
set shiftround " use multiple of shiftwidth when indenting with '<' and '>'
" No bells
set noerrorbells visualbell t_vb=
""" VISUAL SETTINGS """
if &term =~ '256color' | set t_ut= | endif
set background=dark | colorscheme hybrid-sl
" Show trailing whitespace
set list listchars=tab:▸\ ,trail:▫
set cursorline " have a line indicate cursor location
set previewheight=25 " Larger preview height
" Set minimum window size to 79x5.
set winwidth=79 winheight=5 winminheight=5
" Patterns to ignore for expand(), ctrlp, etc.
set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz,*.swp,*~,._*,*.pyc,*__pycache__*,*.egg-info
" " Persistent undo (can use undos after exiting and restarting)
" if exists("+undofile")
" if isdirectory($HOME . '/.vim/undo') == 0
" :silent !mkdir -p ~/.vim/undo > /dev/null 2>&1
" endif
" set undodir=./.vim-undo/ undodir+=~/.vim/undo/ undofile
" endif
""" SHORTCUTS """
" Quickly edit vimrc
nmap <leader>, :e $MYVIMRC<CR>
" Reload vimrc
noremap <silent> <leader>V :source $MYVIMRC<cr>
" Search and replace, using : as a separator instead of /
noremap <leader>sr :%s:::cg<Left><Left><Left><Left>
" Switch between files
nnoremap <leader>b :e#<CR>
" Remove trailing whitespace with Backspace
nnoremap <BS> :%s/\s\+$//<cr>:let @/=''<CR>
" select last pasted text
nnoremap gp `[v`]
" Easy syntax switching
nnoremap <leader>Tp :set ft=python<CR>
nnoremap <leader>Tj :set ft=javascript<CR>
nnoremap <leader>Tm :set ft=markdown<CR>
nnoremap <leader>Ty :set ft=yaml<CR>
" Quickly write/quit
nnoremap <leader>w :w<CR>
nnoremap <leader>q :q<CR>
" Quickly open netrw
nnoremap <leader>e :e.<CR>
" Quick split
nnoremap <Leader>v <C-w>v<C-w>w
" Quick select whole file
map <leader>a ggVG
" Quickly save session
nnoremap <leader>S :mksession! .session<CR>
" Make D delete to end of line
nnoremap D d$
" Make Y yank to end of line
nnoremap Y y$
" Go to beginning/end of line
noremap <leader>h ^
noremap <leader>l $
" Execute macro
nnoremap Q @q
" Move vertically over wrapped lines
nmap j gj
nmap k gk
" Set cwd to current file
nnoremap <leader>cd :lcd %:p:h<CR>
" Split lines (opposite of J)
nnoremap S i<CR><Esc>
nnoremap <leader>N "=strftime("%F")<CR>P
inoremap <C-r>n <C-R>=strftime("%F")<CR>
augroup configgroup
autocmd!
" Make sure Vim returns to the same line when you reopen a file.
autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | execute 'normal! g`"zvzz' | endif
" Automatically adjust quickfix window depending on how much text there is
autocmd FileType qf call AdjustWindowHeight(3, 20)
function! AdjustWindowHeight(minheight, maxheight)
exe max([min([line("$"), a:maxheight]), a:minheight]) . "wincmd _"
endfunction
""" Languages
" prose (hard wrap and autoformat paragraphs)
autocmd BufRead,BufNewFile jrnl*.txt,editor*.txt set filetype=markdown
autocmd BufRead,BufNewFile *.mdx set filetype=markdown
autocmd BufRead,BufNewFile *.js.flow set filetype=javascript
autocmd BufRead,BufNewFile jrnl*.txt,editor*.txt,*.md,*.rst setlocal nolist wrap linebreak formatoptions+=ntl textwidth=72 wrapmargin=0
autocmd BufRead,BufNewFile .eslintrc set filetype=json
autocmd BufRead,BufNewFile .babelrc set filetype=json5
" commit messages
autocmd Filetype gitcommit setlocal nolist textwidth=72
augroup END
" GUI settings, e.g. MacVim
" set guifont=Ubuntu\ Mono:h14
set guifont=Hack:h12
" Hide scrollbars and menu
set guioptions-=T guioptions-=R guioptions-=r guioptions-=m guioptions-=l guioptions-=L