-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path.vimrc
436 lines (365 loc) · 11.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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
"
" .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
set number
set ruler
set showmatch
set wildmenu
set wildmode=full
set nowrap
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=3 " Always show status-line
set nocursorline " Highlight current line
set scrolloff=4
set nofoldenable
set timeoutlen=200 " Set timeout between key sequences
set background=dark
set mouse=a " Enable mouse in all modes
set directory=~/tmp,/var/tmp,/tmp,. " Keep swap files in one of these
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 noshowmode " Don't show stuff like `-- INSERT --`
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 colorcolumn=80
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 guicursor=n-v-c:block-Cursor/lCursor-blinkon0,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor
set spelllang=en_us,en_gb
set completeopt=menu
set shell=/bin/sh
set signcolumn=yes
set notermguicolors
" Copy all yanked text to system clipboard (requires `xclip`)
" set clipboard+=unnamedplus
" 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>"
" vim.wiki
let g:wiki_filetypes = ['wiki']
" signify
let g:signify_vcs_list = ['git']
" Latex
let g:vimtex_quickfix_mode = 0
" Svelte
let g:svelte_preprocessors = ['typescript', 'ts']
let g:svelte_preprocessor_tags = [
\ { 'name': 'ts', 'tag': 'script', 'as': 'typescript' }
\ ]
" 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 sts=2 sw=2 expandtab nowrap
au FileType go setlocal number ts=4 sw=4 noexpandtab
au FileType c,cpp,glsl setlocal number ts=4 sw=4 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
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=0
au FileType rst setlocal nonumber sw=2 expandtab wrap linebreak textwidth=80
au FileType todo setlocal nonumber sw=2 expandtab nolinebreak nowrap textwidth=0
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
au BufRead,BufNewFile *.wiki setf wiki
" 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
let g:vim_markdown_auto_insert_bullets = 0
let g:vim_markdown_new_list_item_indent = 0
let g:vim_markdown_no_default_key_mappings = 1
" We use a POSIX shell
let g:is_posix = 1
" Haskell
let g:haskellmode_completion_ghc = 0
let g:haskell_enable_quantification = 1
au FileType haskell setlocal omnifunc=necoghc#omnifunc
au FileType haskell setlocal makeprg=stack\ build\ --fast
au FileType haskell setlocal errorformat=
\%-G,
\%-Z\ %#,
\%W%f:%l:%c:\ Warning:\ %m,
\%E%f:%l:%c:\ %m,
\%E%>%f:%l:%c:,
\%+C\ \ %#%m,
\%W%>%f:%l:%c:,
\%+C\ \ %#%tarning:\ %m,
if executable('haskell-tags')
au BufWritePost *.hs silent !haskell-tags % '.tags'
au BufWritePost *.hsc silent !haskell-tags % '.tags'
endif
if executable('ctags')
au BufWritePost *.c,*.cc,*.cpp silent !ctags -f .tags -R .
au BufWritePost *.h silent !ctags -f .tags -R .
endif
" 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 "+y
" Paste form clipboard
noremap PP "+p
" 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>u
" 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
" Like '*' but stays on the original word
nnoremap <C-n> *N
nnoremap <C-p> #N
nnoremap c* *Ncgn
nnoremap <Leader>h :nohl<CR>
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
" Ack
cnoreabbrev ack Ack!
" File navigation/search
nnoremap <Leader>o :FuzzyOpen<CR>
nnoremap <Leader>f :FuzzyGrep<CR>
nnoremap <Leader>t :FuzzyTodo<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
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
" 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 'tpope/vim-commentary'
Plug 'evanleck/vim-svelte', { 'for': ['svelte'], 'branch': 'main' }
Plug 'pangloss/vim-javascript', { 'for': ['javascript'] }
Plug 'mileszs/ack.vim'
Plug 'bronson/vim-visual-star-search'
Plug 'cloudhead/neovim-fuzzy'
Plug 'cloudhead/shady.vim'
Plug 'tikhomirov/vim-glsl'
Plug 'junegunn/goyo.vim'
Plug 'exu/pgsql.vim'
Plug 'lervag/vimtex', { 'for': ['tex'] }
Plug 'itchyny/vim-gitbranch'
Plug 'cespare/vim-toml'
Plug 'rust-lang/rust.vim'
Plug 'neoclide/coc.nvim', { 'branch': 'release', 'for': ['rust', 'typescript', 'svelte'] }
Plug 'neovim/nvim-lspconfig'
Plug 'lewis6991/gitsigns.nvim'
Plug 'leafgarland/typescript-vim', { 'for': ['typescript'] }
Plug 'lambdalisue/fern.vim'
Plug 'lervag/wiki.vim'
call plug#end()
endif
"
" 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!
command! GitAdd silent !git add %
" 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)
" Use K to show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
inoremap <expr> <cr> coc#pum#visible() ? coc#_select_confirm() : "\<CR>"
endfunction
autocmd User CocNvimInit call SetupCoc()
command! CocStop call coc#rpc#stop()
command! CocLspLogs CocCommand workspace.showOutput
" Use custom colors.
" This has to go after plugin initialization.
try
colorscheme shady
catch
endtry