-
Notifications
You must be signed in to change notification settings - Fork 4
/
.vimrc
405 lines (337 loc) · 10.9 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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
" .vimrc
"
" Tabs and Spaces
set tabstop=4
set shiftwidth=2
set softtabstop=2
set backspace=indent,eol,start
set expandtab
set autoindent
set cindent
set smarttab
" Misc
"
" Hubrid line numbers: https://jeffkreeftmeijer.com/vim-number/
set number relativenumber
set nu rnu
set ruler
set showmatch
set wildmenu
set wildmode=full
set wrap
set linebreak
set hidden
set modeline
set hlsearch
set incsearch
set autoread " Auto-reload modified files (with no local changes)
set ignorecase " Ignore case in search
set smartcase " Override ignorecase if uppercase is used in search string
set report=0 " Report all changes
set laststatus=2 " Always show status-line
set scrolloff=4
set timeoutlen=200 " Set timeout between key sequences
set background=dark
set mouse=a " Enable mouse in all modes
set wmh=0 " Minimum window height = 0
set showcmd
set updatetime=250 " How long before 'CursorHold' event
set nobackup
set nowritebackup
set noswapfile
set nostartofline
set foldlevel=99 " Open all folds by default
set cmdheight=1
set matchtime=2 " Shorter brace match time
set virtualedit=block
set tags+=.tags
set tags+=codex.tags
set undofile
set gdefault " Always use /g with %s/
set list
set listchars=tab:·\ ,eol:¬,trail:█
set fillchars=diff:\ ,vert:│
set diffopt=filler,vertical,foldcolumn:0
set statusline=%<%f\ (%{gitbranch#name()})\ %h%m%r%=%y\ \ %-14(%{&sw}:%{&sts}:%{&ts}%)%-14.(%l,%c%V%)\ %P
set spelllang=en_us,en_gb
set completeopt=menu
set termguicolors
set foldmethod=syntax
let g:asyncrun_open = 6
" We don't use tabs much, but at least try and show less cruft
function! Tabline()
let s = ''
for i in range(tabpagenr('$'))
let tab = i + 1
let winnr = tabpagewinnr(tab)
let buflist = tabpagebuflist(tab)
let bufnr = buflist[winnr - 1]
let bufname = bufname(bufnr)
let s .= (tab == tabpagenr() ? '%#TabLineSel#' : '%#TabLine#')
let s .= ' ' . (!empty(bufname) ? fnamemodify(bufname, ':t') : '[No Name]') . ' '
endfor
return s
endfunction
set tabline=%!Tabline()
if !has("nvim")
set nocompatible " Don't try to be compatible with vi
set ttyfast
set t_Co=256
endif
let mapleader = "\<Space>"
let g:signify_vcs_list = ['git']
" Markdown
let g:vim_markdown_auto_insert_bullets = 0
let g:vim_markdown_new_list_item_indent = 2
let g:vim_markdown_no_default_key_mappings = 1
" Latex
let g:vimtex_quickfix_mode = 0
" inccommand
if has("nvim")
set inccommand=nosplit
endif
" Save on focus lost
au FocusLost * call s:SaveOnFocusLost()
function! s:SaveOnFocusLost()
if !empty(expand('%:p')) && &modified
write
endif
endfunction
" Per file-type indentation
au FileType haskell setlocal number sts=4 sw=4 expandtab formatprg=stylish-haskell
au FileType javascript setlocal number sts=2 sw=2 expandtab nowrap
au FileType typescript setlocal number sts=2 sw=2 expandtab nowrap
au FileType svelte setlocal number sts=2 sw=2 expandtab nowrap
au FileType css setlocal number ts=2 sw=2 noexpandtab nowrap
au FileType go setlocal number ts=4 sw=4 noexpandtab
au FileType c,cpp,glsl setlocal number ts=8 sw=8 noexpandtab
au FileType lua setlocal number sw=2 expandtab
au FileType sh,zsh setlocal number sts=2 sw=2 expandtab
au FileType vim,ruby setlocal number sts=2 sw=2 expandtab
au FileType help setlocal number ts=4 sw=4 noexpandtab
au FileType solidity setlocal number ts=4 sw=4 expandtab nowrap colorcolumn=120 textwidth=120 signcolumn=yes
au FileType graphql setlocal number ts=4 sw=4 expandtab nowrap
au FileType rust setlocal number signcolumn=yes nowrap colorcolumn=100 textwidth=100
au FileType plain setlocal nonumber noai nocin nosi inde= wrap linebreak textwidth=80
au FileType pandoc setlocal nonumber
au FileType markdown setlocal nonumber conceallevel=2
au FileType rst setlocal nonumber sw=2 expandtab wrap linebreak textwidth=80
au FileType fountain setlocal nonumber noai nocin nosi inde= wrap linebreak
au FileType tex setlocal
au BufRead,BufNewFile *.md setf markdown
au BufRead,BufNewFile *.tex setf tex
au BufRead,BufNewFile *.todo setf todo
au BufRead,BufNewFile *.tikz setf tex
au BufRead,BufNewFile *.toml setf toml
au BufRead,BufNewFile *.rs setf rust
au BufRead,BufNewFile *.mustache setf mustache
au BufRead,BufNewFile *.tera setf htmldjango
au BufRead,BufNewFile *.svelte setf svelte
" If no file-type is detected, set to plain.
autocmd BufEnter * if &filetype == "" | setlocal ft=plain | endif
let c_no_curly_error = 1
if has("nvim")
au TermOpen * set nonumber modifiable
endif
" Remove trailing whitespace on save
autocmd BufWritePre * call s:StripTrailing()
function! s:StripTrailing()
if &ft =~ 'rust'
return
endif
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfunction
" Markdown, highlight YAML frontmatter
let g:vim_markdown_frontmatter = 1
" We use a POSIX shell
let g:is_posix = 1
" File-type
filetype on
filetype plugin on
filetype indent on
nnoremap <Space> <NOP>
nnoremap Q <NOP>
" Make `Y` behave like `D` and `C`
nnoremap Y y$
" Copy selected text to clipboard
xnoremap Y :w !pbcopy
" Paste form clipboard
noremap PP :r !pbpaste
" Easy command mode switch
inoremap kj <Esc>
inoremap <C-l> <C-x><C-l>
" Correct spelling mistakes
inoremap <C-s> <c-g>u<Esc>[s1z=`]a<c-g>
" Jump to high/low and scroll
noremap <C-k> H{
noremap <C-j> L}
" Move easily between ^ and $
noremap <C-h> ^
noremap <C-l> $
noremap j gj
noremap k gk
" Add headers
noremap <Leader>h .! headers
nnoremap <C-n> *N
nnoremap <C-p> #N
nnoremap c* *Ncgn
nnoremap <Leader>n :cnext<CR>
nnoremap <Leader>p :cprev<CR>
autocmd BufRead fugitive\:* xnoremap <buffer> dp :diffput<CR>
autocmd BufRead fugitive\:* xnoremap <buffer> do :diffget<CR>
" Support jsonc comments in json files
autocmd FileType json syntax match Comment +\/\/.\+$+
" Select recently pasted text
nnoremap <leader>v V`]
" Switch buffers easily
nnoremap <Tab> <C-^>
" Switch between .c and .h files easily
autocmd BufRead,BufNewFile *.c,*.h nnoremap <silent> <S-Tab> :e %:p:s,.h$,.X123X,:s,.c$,.h,:s,.X123X$,.c,<CR>
" Switch between .cc and .h files easily
autocmd BufRead,BufNewFile *.cc,*.h nnoremap <silent> <S-Tab> :e %:p:s,.h$,.X123X,:s,.cc$,.h,:s,.X123X$,.cc,<CR>
" Actually easier to type and I do it by mistake anyway
cnoreabbrev W w
cnoreabbrev Q q
" Nerdtree toggle
nnoremap <C-t> :NERDTreeToggle<CR>
" Navigate relative to the current file
cmap %/ %:p:h/
map <Leader>m :make<CR>
map <Leader>e :e ~/.vimrc<CR>
map <Leader>s :source ~/.vimrc<CR>
" Repeat previous command
map <Leader><Space> @:
" Commenting
nmap <C-_> <Plug>CommentaryLine
xmap <C-_> <Plug>Commentary
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
if has("nvim")
tnoremap <Esc> <C-\><C-n>
endif
if executable('rg')
let g:ackprg = 'rg -F -S --no-heading --vimgrep'
set grepprg=rg\ -S\ -F\ --no-heading\ --vimgrep\ $*
endif
" Syntax coloring
syntax enable
filetype plugin on
set ofu=syntaxcomplete#Complete
highlight Pmenu guibg=brown gui=bold
highlight CocErrorHighlight ctermfg=Red guifg=#ff0000
" Profiling
command! ProfileStart call s:ProfileStart()
function! s:ProfileStart()
profile start profile
profile func *
profile file *
endfunction
command! ProfileStop call s:ProfileStop()
function! s:ProfileStop()
profile stop
tabnew profile
endfunction
" Get highlight group under cursor
command! Syn call s:Syn()
function! s:Syn()
echo synIDattr(synID(line("."), col("."), 1), "name")
endfunction
if has("nvim")
call plug#begin()
Plug 'ekalinin/Dockerfile.vim'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'mileszs/ack.vim'
Plug 'preservim/nerdtree'
Plug 'tpope/vim-commentary'
Plug 'evanleck/vim-svelte', { 'for': ['svelte'], 'branch': 'main' }
Plug 'pangloss/vim-javascript', { 'for': ['javascript'] }
Plug 'bronson/vim-visual-star-search'
Plug 'gabrielelana/vim-markdown'
Plug 'tikhomirov/vim-glsl'
Plug 'junegunn/goyo.vim'
Plug 'exu/pgsql.vim'
Plug 'hail2u/vim-css3-syntax'
Plug 'lervag/vimtex', { 'for': ['tex'] }
Plug 'itchyny/vim-gitbranch'
Plug 'cespare/vim-toml'
Plug 'rust-lang/rust.vim'
Plug 'neoclide/coc.nvim', { 'branch': 'release'}
Plug 'tomlion/vim-solidity'
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-lua/plenary.nvim'
Plug 'lewis6991/gitsigns.nvim'
Plug 'leafgarland/typescript-vim', { 'for': ['typescript'] }
Plug 'jparise/vim-graphql'
Plug 'tpope/vim-fugitive'
Plug 'vim-ruby/vim-ruby'
Plug 'skywind3000/asynctasks.vim'
Plug 'skywind3000/asyncrun.vim'
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && yarn install' }
Plug 'github/copilot.vim'
call plug#end()
endif
lua << EOF
require('gitsigns').setup {
signs = {
changedelete = { text = "│" }
}
}
EOF
"
" Quickfix Signs
"
sign define quickfix-error text=× texthl=ErrorSign
command! QuickfixSigns call s:QuickfixSigns()
" autocmd BufWrite * sign unplace *
autocmd CursorHold *.rs silent QuickfixSigns
function! s:QuickfixSigns()
silent! cgetfile
sign unplace *
for dict in getqflist()
if dict.type != 'E'
continue
endif
try
silent exe "sign"
\ "place"
\ dict.lnum
\ "line=" . string(dict.lnum)
\ "name=" . "quickfix-error"
\ "file=" . bufname(dict.bufnr)
catch
endtry
endfor
endfunction
command! Write setlocal spell | Goyo 100x98%
command! Code setlocal nospell | Goyo!
" Delete the current file.
command! Delete call delete(expand('%')) | bdelete!
if has("nvim")
" Make sure we dont' load the rust cargo plugin from rust.vim!
let g:loaded_rust_vim_plugin_cargo = 1
" Don't add errors to quickfix if rustfmt fails.
let g:rustfmt_fail_silently = 1
endif
" coc.vim
function! SetupCoc()
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
nmap <silent> gj <Plug>(coc-diagnostic-next)
nmap <silent> gk <Plug>(coc-diagnostic-prev)
nmap <silent> <leader>/ :CocList --interactive symbols<CR>
nmap <silent> <leader>r <Plug>(coc-rename)
" This is a kind of hack to make <C-Y> not trigger snippet expansion.
" We use <C-p><C-n> to insert the selection without triggering anything, and
" then close the popup.
inoremap <silent><expr> <C-Y> pumvisible() ? "<C-p><C-n><Esc>a" : "\<C-Y>"
" Trigger completion on <CR>.
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
endfunction
autocmd User CocNvimInit call SetupCoc()
autocmd VimEnter * NERDTree | wincmd p