-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.vimrc
352 lines (275 loc) · 9.26 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
function! SourceIfExists(file)
if filereadable(expand(a:file))
exe 'source' a:file
endif
endfunction
call SourceIfExists("/usr/facebook/ops/rc/master.vimrc")
call SourceIfExists("/usr/share/vim/google/google.vim")
let g:ale_completion_enabled = 1
let mapleader = ","
" Load modules.
set nocompatible
packloadall
"----------------------------
" Recommended vim settings
" Allow switching between unsaved buffers
set hidden
" Fix slow highlighting
set re=0
" Better completion
set wildmenu
set wildmode=list:longest
" Show partial commands in the last line of the screen
set showcmd
" Highlight searches
set hlsearch
"----------------------------
" Encouraged/Usability settings
set ruler
set confirm
set backspace=indent,eol,start
" Fast scrolling
set ttyfast
set lazyredraw
" undo between instances
"
" Let's save undo info!
if !isdirectory($HOME."/.vim")
call mkdir($HOME."/.vim", "", 0770)
endif
if !isdirectory($HOME."/.vim/undo")
call mkdir($HOME."/.vim/undo", "", 0700)
endif
set undodir=~/.vim/undo/
set undofile
if !isdirectory($HOME."/.vim/backup")
call mkdir($HOME."/.vim/backup", "", 0700)
endif
set backupdir=~/.vim/backup/
filetype plugin on
filetype plugin indent on
" Indentation settings
set expandtab " Make sure that every file uses real tabs, not spaces
set shiftround " Round indent to multiple of 'shiftwidth'
" Set the tab width
let s:tabwidth=2
exec 'set tabstop=' .s:tabwidth
exec 'set shiftwidth=' .s:tabwidth
exec 'set softtabstop='.s:tabwidth
syntax on
syntax enable
syntax sync minlines=200
set ffs=unix
set ff=unix
set splitbelow
set splitright
set textwidth=80
" Searching/Moving
set mouse=nv
" Resizing in tmux
if exists('$TMUX') && !has("nvim")
if has("mouse_sgr")
set ttymouse=sgr
else
set ttymouse=xterm2
end
endif
set gdefault
set incsearch
set showmatch
set hlsearch
set nomodeline
set ignorecase
set smartcase
if has('unix')
if has('mac')
" Nothing
else
set clipboard=unnamedplus
endif
endif
" Training
nnoremap <up> <nop>
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
vnoremap <up> <nop>
vnoremap <down> <nop>
vnoremap <left> <nop>
vnoremap <right> <nop>
" Who uses F1?
inoremap <F1> <ESC>
nnoremap <F1> <ESC>
vnoremap <F1> <ESC>
" Settings from vim-sensible
set complete-=i
set smarttab
set nrformats-=octal
set ttimeout
set ttimeoutlen=100
set laststatus=2
if !empty(&viminfo)
set viminfo^=!
endif
set sessionoptions-=options
" Colors
if has('gui_running')
set guioptions-=T " no toolbar
set guifont=Consolas
endif
" Allow color schemes to do bright colors without forcing bold.
if &t_Co == 8 && $TERM !~# '^linux\|^Eterm'
set t_Co=256
endif
set background=dark
set termguicolors
let g:solarized_italic = 1
colorscheme solarized
" Comments should be in italics
highlight Comment gui=italic
set completeopt-=preview
" Relative numbers, with current line number at cursor
set relativenumber
set number
highlight clear CursorLineNR
highlight CursorLineNR term=bold cterm=bold ctermfg=012 gui=bold
" Show error signs in the number row to avoid resizing on error.
" Also could use 'yes' to always show the column.
set signcolumn=number
" Run plugins faster than the default of 4000ms after typing stops.
set updatetime=1000
let g:tex_indent_items=0
let g:tex_flavor='latex'
"" Various Personal Remappings
" I'll launch with "vim -E" if I want Ex mode
nnoremap Q <nop>
" Space inserts a space
nmap <Space> i <Esc>r
"Ctrl-c closes buffer but not window
nnoremap <C-c> :bp\|bd # <CR>
"Ctrl-x closes window
nnoremap <C-x> :q <CR>
"Use <C-L> to clear the highlighting of :set hlsearch.
if maparg('<C-L>', 'n') ==# ''
nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
endif
inoremap <C-U> <C-G>u<C-U>
" Leader t and Leader T for time strings
" T is UNIX time
nnoremap <Leader>t "=strftime("%FT%T%z")<CR>P
"inoremap <Leader>t <C-R>=strftime("%FT%T%z")<CR>
nnoremap <Leader>T "=strftime("%s")<CR>P
"inoremap <Leader>T <C-R>=strftime("%s")<CR>
" Slight modification to TOhtml so that the solarized colorscheme
" is used in the generated html CSS
let g:cterm_color = {
\ 0: "#073642", 1: "#dc322f", 2: "#859900", 3: "#b58900",
\ 4: "#268bd2", 5: "#d33682", 6: "#2aa198", 7: "#eee8d5",
\ 8: "#002b36", 9: "#cb4b16", 10: "#586e75", 11: "#657b83",
\ 12: "#839496", 13: "#6c71c4", 14: "#93a1a1", 15: "#fdf6e3"
\ }
let g:ale_fixers = {
\ 'javascript': ['eslint'],
\ 'typescript': ['eslint'],
\ 'typescriptreact': ['eslint'],
\ 'python': ['ruff', 'ruff_format'],
\ 'html': [],
\ 'xml': ['xmllint'],
\ 'c': ['clang-format'],
\ 'cpp': ['clang-format'],
\ 'toml': ['dprint'],
\ 'json': ['pretter'],
\ 'jsonl': ['pretter'],
\}
let g:ale_linters = {
\ 'javascript': ['eslint'],
\ 'typescript': ['eslint', 'tsserver'],
\ 'typescriptreact': ['eslint', 'tsserver'],
\ 'python': ['pyright', 'ruff'],
\ 'c': [],
\ 'cpp': [],
\}
let g:ale_c_clangformat_use_local_file = 1
" map Leader-h to html-ify a given document, and Leader-H for a range
map <silent><Leader>h :TOhtml<CR>
" Expand and contract json
" TODO(mgraczyk): Fix to remove multiple newlines
map <silent><Leader>j :%!python3 -mjson.tool<CR><CR>
map <silent><Leader>J :%s/[\n \t]\+//<CR>
" n is name
nnoremap <Leader>n aMichael Graczyk<Esc>
nnoremap <Leader>N amgraczyk<Esc>
" Toggle paste and line numbers
nnoremap <Leader>p :set invpaste paste?<CR>:set expandtab<CR>:set paste?<CR>
nnoremap <Leader>l :set invnumber invrelativenumber<CR>
" Toggle hex view
nnoremap <Leader>x :syntax off<CR> :%!xxd<CR>
nnoremap <Leader>X :%!xxd -r<CR> :syntax on<CR>
" Run make with ,m
nnoremap <leader>m :silent make\|redraw!\|cc<CR>
" Run buffer with ,r
nnoremap <leader>r :!%:p<Enter>
" Save
nnoremap <leader>w :w <CR> :bp\|bd # <CR>
" https://stackoverflow.com/a/45897194/1301879
nnoremap <leader>u a<CR><ESC>:.-1read !python3 -c 'from uuid import uuid4; import sys; sys.stdout.write(str(uuid4()))'<CR>I<BS><ESC>j0i<BS><ESC>l
nnoremap <leader>U a<CR><ESC>:.-1read !python3 -c 'import os; from base64 import urlsafe_b64encode; import sys; sys.stdout.write(urlsafe_b64encode(os.urandom(16)).decode().rstrip("="))'<CR>I<BS><ESC>j0i<BS><ESC>l
" Fix indentation.
nnoremap <leader>i :setl noai nocin nosi inde=<CR>
" delete without yanking
nnoremap <leader>d "_d
vnoremap <leader>d "_d
" replace currently selected text with default register
" without yanking it
vnoremap <leader>p "_dP
nnoremap <leader>g :ALEGoToDefinition<CR>
nnoremap <leader>s :ALEFindReferences<CR>
let g:typescript_compiler_binary = 'node_modules/typescript/bin/tsc'
let g:prettier#exec_cmd_async = 1
augroup ReactFiletypes
autocmd!
autocmd BufRead,BufNewFile *.jsx set filetype=javascriptreact
autocmd BufRead,BufNewFile *.tsx set filetype=typescriptreact
augroup END
augroup PrettierFileDetect
autocmd BufNewFile,BufReadPost tsconfig.json setfiletype jsonc
augroup end
" Format code
autocmd FileType go nnoremap <buffer><Leader>f :GoFmt<CR>
autocmd FileType rust nnoremap <buffer><Leader>f :silent! RustFmt<CR>
autocmd FileType rust vnoremap <buffer><Leader>f :silent! RustFmt<CR>
autocmd FileType python setlocal indentkeys-=<:>
autocmd FileType python setlocal indentkeys-=:
autocmd FileType python setlocal formatoptions=crnqj
autocmd FileType terraform nnoremap <Leader>f :%!terraform fmt -<CR>
autocmd FileType python nnoremap <leader>f :ALEImport<Cr> :ALEFix<Cr>
autocmd FileType python nnoremap <leader>F :ALEImport<Cr> :ALEFix<Cr>
autocmd FileType python vnoremap <leader>f :ALEImport<Cr> :ALEFix<Cr>
autocmd FileType python vnoremap <leader>F :ALEImport<Cr> :ALEFix<Cr>
autocmd FileType xml,c,cpp,objc nnoremap <leader>f :ALEFix<Cr>
autocmd FileType xml,c,cpp,objc nnoremap <leader>F :ALEFix<Cr>
autocmd FileType xml,c,cpp,objc vnoremap <leader>f :ALEFix<Cr>
autocmd FileType xml,c,cpp,objc vnoremap <leader>F :ALEFix<Cr>
autocmd FileType css,html,json,jsonc,javascript,typescript,typescriptreact,solidity nnoremap <leader>f :Prettier<Cr>
autocmd FileType css,html,json,jsonc,javascript,typescript,typescriptreact,solidity nnoremap <leader>F :ALEFix<Cr>
autocmd FileType css,html,json,jsonc,javascript,typescript,typescriptreact,solidity vnoremap <leader>f :Prettier<Cr>
autocmd FileType css,html,json,jsonc,javascript,typescript,typescriptreact,solidity vnoremap <leader>F :ALEFix<Cr>
" Automatically reload folds
au BufWinLeave ?* mkview
au BufWinEnter ?* silent loadview
au BufRead,BufNewFile,BufEnter * setlocal et sw=2 ts=2 sts=2
au BufRead,BufNewFile,BufEnter *.m setlocal et sw=2 ts=2 sts=2
au BufRead,BufNewFile,BufEnter *.py setlocal et sw=2 ts=2 sts=2 textwidth=100
au BufRead,BufNewFile,BufEnter *.pyx setlocal et sw=2 ts=2 sts=2 textwidth=100
au BufRead,BufNewFile,BufEnter *.pxd setlocal et sw=2 ts=2 sts=2 textwidth=100
au BufRead,BufNewFile,BufEnter *.go setlocal noet sw=4 ts=4 sts=4 textwidth=100
au BufRead,BufNewFile,BufEnter *.sol setlocal et sw=4 ts=4 sts=4 textwidth=100
au BufRead,BufNewFile,BufEnter **/fbsource/**.py setlocal et sw=4 ts=4 sts=4 textwidth=88
au BufRead,BufNewFile,BufEnter **/instagram-server/**.py setlocal et sw=4 ts=4 sts=4 textwidth=88
au BufRead,BufNewFile,BufEnter **/chia-blockchain/**.py setlocal et sw=4 ts=4 sts=4 textwidth=100
au BufRead,BufNewFile,BufEnter **/exomind/**.py setlocal et sw=2 ts=2 sts=2 textwidth=120
call SourceIfExists(glob("~/.vimrc.local"))