-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvimrc
More file actions
382 lines (302 loc) · 11.5 KB
/
vimrc
File metadata and controls
382 lines (302 loc) · 11.5 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
syntax on
colorscheme idleFingers
" colorscheme PaperColor
packadd! matchit
let HOMEDIR = $HOME
set termguicolors
if !has("gui_running")
let &t_Cs = "\e[4:3m"
let &t_Ce = "\e[4:0m"
endif
set nocompatible
set modeline
set modelines=5
set noswapfile
set autowrite
" Default tab settings
set expandtab
" Indenting preferences
set smartindent
set autoindent
set ts=2 sw=2 " Default to 2 spaces per tab
" Enable mouse
if has("mouse_sgr")
set ttymouse=sgr
else
set ttymouse=xterm2
end
set mouse=a
filetype plugin indent on
set number
" Show relative line numbers
set relativenumber
set numberwidth=3
" Highlight search
set hlsearch
nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
" Show # of matches when searching
set shortmess-=S
" Stop blinking cursor
" set guicursor=a:blinkon0
" Always display status bar
set laststatus=2
set ruler
set incsearch
set ignorecase
set smartcase
set splitbelow
set splitright
set undolevels=8000
set nofoldenable " disable folding
" fugitive
set statusline=%<%f\ %h%m%r%{fugitive#statusline()}%=%-14.(%l,%c%V%)\ %P
" Auto complete
inoremap <C-Space> <C-x><C-o>
" By default, the /usr/share/vim/vimrc sets this but it doesn't seem to work
" with my setup. Therefore we add this setting here.
" http://stackoverflow.com/questions/10727392/vim-not-allowing-backspace
set backspace=2
" Ignore node_modules in projects because they're fracking annoying.
set wildignore+=node_modules/**,*.pyc
" Don't save options. Pathogen manipulates this
set sessionoptions-=options
set sessionoptions-=buffers
set sessionoptions-=blank
" Load files that have changed by default
set autoread
set rtp+=/opt/homebrew/opt/fzf
set rtp+=~/.fzf
" NOTE: For this to find the correct files, the silver searcher must be
" installed and the appropriate FZF environment variables should be set. See
" ~/.profile.
" Used with basic fzf plugin.
"map <Leader>t <Esc>:FZF --reverse<CR>
" Used with fzf.vim plugin
map <Leader>t <Esc>:Files<CR>
map <Leader>u <Esc>:Buffers<CR>
map <Leader>f <Esc>:RG<CR>
command! -bang -nargs=? -complete=dir Files call fzf#vim#files(<q-args>, fzf#vim#with_preview({'options': ['--layout=reverse']}), <bang>0)
command! -bar -bang -nargs=? -complete=buffer Buffers call fzf#vim#buffers(<q-args>, fzf#vim#with_preview({"options": ['--layout=reverse'], "placeholder": "{1}" }), <bang>0)
command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, fzf#vim#with_preview({"options": ['--layout=reverse']}), <bang>0)'
command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --colors='path:fg:0xFF,0xC6,0x6D' --colors='match:fg:black' --colors='match:bg:0x6c,0x99,0xbb' --colors='line:fg:white' --smart-case -- ".shellescape(<q-args>), 1, fzf#vim#with_preview({'options': ['--layout=reverse']}), <bang>0)'
command! -bang -nargs=* RG call fzf#vim#grep2("rg --column --line-number --no-heading --color=always --colors='path:fg:0xFF,0xC6,0x6D' --colors='match:fg:black' --colors='match:bg:0x6c,0x99,0xbb' --colors='line:fg:white' --smart-case -- ", <q-args>, fzf#vim#with_preview({'options': ['--layout=reverse']}), <bang>0)
" lcd to current file directory
" map <Leader>d <Esc>:lcd %:p:h<CR>
" Opens NERDTree at the file's current directory
map <Leader>n <Esc>:NERDTree %:p:h<CR>
" Map <leader>p to NERDtree and auto resize-splits
" (backslash)p
map <Leader>p :NERDTreeToggle<CR><C-W>=
" Copy file path to + register (system clipboard if enabled)
noremap <Leader>cf :execute 'OSCYank ' . expand('%')<CR>
" Copy to clipboard in normal mode
noremap <Leader>cc <Plug>OSCYankOperator
" Copy to clipboard in visual mode
vnoremap <Leader>cc <Plug>OSCYankVisual
" Quickfix bindings with <Leader>q
map <Leader>qc :cclose<CR>
map <Leader>qn :cn<CR>
map <Leader>qp :cp<CR>
" Select all
noremap <C-a> ggVG
" Ack commands
" Search for word at cursor
noremap <silent> <Leader>s :Rg <C-R><C-W><CR>
" Search for highlighted word
" Goyo
map <Leader>gg <Esc>:Goyo<CR>
map <Leader>gz <Esc>:Goyo 120x100%<CR>
map <Leader>gr <Esc>:Goyo 75%x100%<CR>
" vim-test
let test#strategy = "vimterminal"
let test#python#pytest#options = '-vv'
nmap <silent> <leader>rr :TestNearest<CR>
nmap <silent> <leader>rf :TestFile<CR>
nmap <silent> <leader>rl :TestLast<CR>
" vim-lsp settings
" Debugging
" let g:lsp_log_verbose = 1
" let g:lsp_log_file = expand('~/vim-lsp.log')
" let g:asyncomplete_log_file = expand('~/asyncomplete.log')
" This is annoying.
let g:lsp_document_highlight_enabled = 0
let g:lsp_diagnostics_echo_delay = 100
let g:lsp_diagnostics_highlights_delay = 100
let g:lsp_diagnostics_signs_delay = 100
let g:lsp_document_code_action_signs_delay = 100
let g:lsp_diagnostics_virtual_text_prefix = " ‣ "
let g:lsp_diagnostics_virtual_text_align = "after"
let g:lsp_diagnostics_virtual_text_wrap = "truncate"
let g:lsp_experimental_workspace_folders = 1
" Notes:
" * Use virtualenv pylsp instead of global one from vim-lsp-settings.
" pylsp must be installed in the project's virtualenv. Otherwise, it will
" not be able to go to definitions for 3rd part packages. This is opposite
" of how vim-lsp-settings wants to behave.
" * To set true/false, use 1/0. I think this works because in python
" 0 == False
"
" TODO: This only works for python projects with a virtualenv. Plain python
" dirs will cause vim to start with errors.
let g:lsp_settings = {
\ 'pylsp-all': {
\ 'cmd': ['./venv/bin/pylsp', '-v', '--log-file', HOMEDIR . '/pylsp.log'],
\ 'workspace_config': {
\ 'pylsp': {
\ 'configurationSource': ['flake8'],
\ 'plugins': {
\ 'pylsp_mypy': { 'enabled': 1, 'dmypy': 1, 'live_mode': 0 },
\ 'flake8': { 'enabled': 0, 'executable': './venv/bin/flake8' },
\ 'autopep8': { 'enabled': 0 },
\ 'mccabe': { 'enabled': 0 },
\ 'pycodestyle': { 'enabled': 0 },
\ 'pyflakes': { 'enabled': 0 },
\ 'ruff': {
\ 'enabled': 1,
\ 'formatEnabled': 1,
\ },
\ },
\ },
\ },
\ },
\}
function! s:on_lsp_buffer_enabled() abort
setlocal omnifunc=lsp#complete
setlocal signcolumn=yes
if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
nmap <buffer> gd <plug>(lsp-definition)
nmap <buffer> gs <plug>(lsp-document-symbol-search)
nmap <buffer> gS <plug>(lsp-workspace-symbol-search)
nmap <buffer> gr <plug>(lsp-references)
nmap <buffer> gi <plug>(lsp-implementation)
nmap <buffer> gt <plug>(lsp-type-definition)
nmap <buffer> <leader>rn <plug>(lsp-rename)
nmap <buffer> [g <plug>(lsp-previous-diagnostic)
nmap <buffer> ]g <plug>(lsp-next-diagnostic)
nmap <buffer> K <plug>(lsp-hover)
nmap <buffer> <leader>d <plug>(lsp-document-diagnostics)
nmap <buffer> <leader>a <plug>(lsp-code-action-float)
nmap <buffer> <leader>ls <plug>(lsp-status)
nmap <buffer> <leader>le <Esc>:call lsp#enable_diagnostics_for_buffer()<CR>
nmap <buffer> <leader>ld <Esc>:call lsp#disable_diagnostics_for_buffer()<CR>
let g:lsp_format_sync_timeout = 1000
autocmd! BufWritePre *.py,*.sh LspDocumentFormatSync
endfunction
augroup lsp_install
au!
" call s:on_lsp_buffer_enabled only for languages that has the server registered.
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
" Ultisnips
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-k>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
let NERDTreeSortOrder=[]
let NERDTreeShowBookmarks=1
let NERDTreeIgnore=['\~$', '__pycache__$[[dir]]', '\.pyc$']
" NERD_commenters
let NERDSpaceDelims=1
" Disable default mappings to allow "cc" bindings
let NERDCreateDefaultMappings=0
" Put back the only useful binding
noremap <Leader>c<space> <Plug>NERDCommenterToggle
let g:NERDCustomDelimiters = { 'sls': { 'left': '#' } }
let NERDDefaultAlign='left'
" html indenting
let g:html_indent_inctags = "video,source"
" Disable rails.vim abbreviations
let g:rails_no_abbreviations=0
" Python settings
" let python_highlight_all = 1
let g:black_virtualenv = "~/.virtualenv/black"
" python-mode
let g:pymode_options = 0 " Don't use default options
let g:pymode_indent = 1
let g:pymode_motion = 1
let g:pymode_doc = 0 " Hit 'K' for documentation
let g:pymode_breakpoint = 1 " use <leader>b to input breakpoint
let g:pymode_lint = 0 " Use ALE/vim-lsp
let g:pymode_lint_on_write = 0 " Use ALE/vim-lsp
let g:pymode_options_colorcolumn = 0
" let g:pymode_options_max_line_length = 89
let g:pymode_syntax = 1
let g:pymode_syntax_all = 1
let g:pymode_virtualenv = 1
let g:pymode_run = 0 " I don't need this binding. I run code separately
let g:polyglot_is_disabled = {'go': 1}
"let g:go_fmt_fail_silently = 1
let g:go_fmt_command = "goimports"
"let g:go_fmt_command = "gofmt"
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_operators = 1
let g:go_highlight_functions = 1
let g:go_highlight_types = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_generate_tags = 1
let g:go_metalinter_autosave = 0
let g:go_def_mode='gopls'
let g:go_info_mode='gopls'
" json-vim
let g:vim_json_syntax_conceal = 0
" ack.vim with the_silver_searcher
let g:ackprg = 'ag --nogroup --nocolor --column'
" vim-closetags
let g:closetag_filenames = '*.html.erb,*.html,*.xhtml,*.html,*.tmpl'
let g:closetag_filetypes = 'html,xhtml,gohtmltmpl'
" vim-ruby settings
let ruby_operators = 1
let ruby_pseudo_operators = 1
" vim-markdown settings
let g:vim_markdown_frontmatter = 1
let g:vim_markdown_toml_frontmatter = 1
let g:vim_markdown_json_frontmatter = 1
augroup MarkdownTitleHighlight
autocmd!
autocmd FileType markdown highlight Title guifg=#FFC66D
augroup END
augroup vimrc
au!
" vim's smartindent auto-removes indentation with #. This fixes it.
" See :help smartindent
autocmd BufRead *.py inoremap # X<c-h>#
" Remove all trailing whitespaces when saving a file
autocmd BufWritePre * :%s/\s\+$//e
" Filetypes
au BufNewFile,BufRead *.less set filetype=less
au BufNewFile,BufRead *.ejs set filetype=eruby
au BufNewFile,BufRead *.vcl set filetype=conf
au BufNewFile,BufRead *.vcl.erb set filetype=conf
au BufNewFile,BufRead *.es6 set filetype=javascript
" Tabbing rules
au BufRead *.yml set ts=2 sw=2 sts=2 expandtab
au BufRead *.yaml set ts=2 sw=2 sts=2 expandtab
au BufRead *.rb set ts=2 sw=2 sts=2 expandtab
au BufRead *.py set ts=4 sw=4 sts=4 expandtab formatoptions-=t formatoptions+=croql
au BufRead *.erb set ts=2 sw=2 sts=2 expandtab
au BufRead *.html set ts=2 sw=2 sts=2 expandtab
au BufRead *.css set ts=2 sw=2 sts=2 expandtab
au BufRead *.ru set filetype=ruby
au BufRead *.js set ts=2 sw=2 sts=2 expandtab
au BufRead *.json set ts=2 sw=2 sts=2 expandtab
au BufRead *.jst set ts=2 sw=2 sts=2 expandtab
au BufRead *.tpl set ts=2 sw=2 sts=2 expandtab
au BufRead *.coffee set ts=2 sw=2 sts=2 expandtab
au BufRead *.c set ts=4 sw=4 sts=4 expandtab
au BufRead *.php set ts=4 sw=4 sts=4 expandtab
au BufRead *.go set ts=4 sw=4 sts=4 noexpandtab formatoptions+=cr
au BufRead *.tmpl set ft=gohtmltmpl ts=2 sw=2 sts=2 expandtab
" Autowrap text in markdown files
au BufRead,BufNewFile *.md setlocal textwidth=80 ts=2 sw=2 sts=2 expandtab
au BufRead,BufNewFile *.mdc set ft=markdown
" Bats
au BufRead,BufNewFile *.bats set ft=sh
au BufNewFile,BufRead */patreon_py/*.py set textwidth=88
au BufNewFile,BufRead */patreon_py/*.ts set ts=4 sw=4 sts=4 expandtab textwidth=88
au BufNewFile,BufRead */patreon_py/*.js set ts=4 sw=4 sts=4 expandtab textwidth=88
au BufNewFile,BufRead */ansible/playbooks/group_vars/* set ft=yaml
" au VimLeave * :call SaveSession()
augroup END