-
Notifications
You must be signed in to change notification settings - Fork 1
/
.vimrc
384 lines (345 loc) · 9.42 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
" -------------------------
" Plugins
" -------------------------
" Much of my Vim setup relies on plugins, managed by vim-plug. Ensure vim-plug
" is installed on Vim startup.
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" List plugins I use
call plug#begin()
Plug 'AndrewRadev/splitjoin.vim'
Plug 'Asheq/close-buffers.vim'
Plug 'airblade/vim-gitgutter'
Plug 'airblade/vim-rooter'
Plug 'andymass/vim-matchup'
Plug 'ap/vim-css-color'
Plug 'cocopon/iceberg.vim'
Plug 'dense-analysis/ale'
Plug 'direnv/direnv.vim'
Plug 'dominickng/fzf-session.vim'
Plug 'editorconfig/editorconfig-vim'
Plug 'Exafunction/codeium.vim'
Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() } }
Plug 'inkarkat/vim-ingo-library'
Plug 'wincent/loupe'
Plug 'inkarkat/vim-SearchHighlighting'
Plug 'itchyny/lightline.vim'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'junegunn/limelight.vim', { 'on': ['Limelight'] }
Plug 'junegunn/vim-peekaboo'
Plug 'justinmk/vim-sneak'
Plug 'kana/vim-textobj-user'
Plug 'machakann/vim-highlightedyank'
Plug 'maxbrunsfeld/vim-yankstack'
Plug 'maximbaz/lightline-ale'
Plug 'michaeljsmith/vim-indent-object'
if has('nvim')
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
endif
Plug 'osyo-manga/vim-over'
Plug 'preservim/vim-textobj-quote'
Plug 'rickhowe/diffchar.vim'
if !has('nvim')
Plug 'sheerun/vim-polyglot'
endif
Plug 'sjl/gundo.vim'
Plug 'sodapopcan/vim-ifionly'
Plug 'tommcdo/vim-fugitive-blame-ext'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-eunuch'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-rhubarb'
Plug 'tpope/vim-sensible'
if !has('nvim')
Plug 'tpope/vim-sleuth'
endif
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-vinegar'
Plug 'vim-utils/vim-husk'
Plug 'wellle/targets.vim'
Plug 'yssl/QFEnter'
call plug#end()
" Install missing plugins on Vim startup
autocmd VimEnter *
\ if !empty(filter(copy(g:plugs), '!isdirectory(v:val.dir)'))
\| PlugInstall --sync | q
\| endif
" -------------------------
" Color
" -------------------------
set background=dark
set cursorline
set cursorlineopt=number
colorscheme iceberg
" -------------------------
" Various Vim options
" -------------------------
set backupcopy=yes
set backupdir=~/.vim/backup//
set breakindent
set completeopt=menu,menuone,preview,noselect,noinsert
set directory=~/.vim/swp//
set hidden
set lazyredraw
set linebreak
set nocompatible
set nojoinspaces
set number
set relativenumber
set sessionoptions-=curdir " Increase session compatbility with vim-rooter
set showbreak=…
set showtabline=2
set splitright
set switchbuf=uselast
set undodir=~/.vim/undodir//
set undofile
set updatetime=100
if has("gui_running")
set guifont=MesloLGMDZ\ Nerd\ Font
set guioptions-=e
set guioptions-=T
set macmeta
endif
" Speed up startup with a Vim-dedicated virtualenv. Follow setup instructions
" in :help python-virtualenv.
let g:python3_host_prog="~/.pyenv/versions/py3nvim/bin/python"
let mapleader = ","
let maplocalleader = ","
" -------------------------
" Vim plugin options
" -------------------------
"
" ale
let g:ale_completion_enabled = 1
let g:ale_fix_on_save = 1
let g:ale_floating_preview = 1
let g:ale_floating_window_border = [' ', ' ', ' ', ' ', ' ', ' ']
inoremap <silent><expr> <Tab> pumvisible() ? "\<C-n>" : "\<TAB>"
inoremap <silent><expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-TAB>"
map <leader>u :ALEFindReferences<CR>
nnoremap <M-LeftMouse> <LeftMouse>:ALEGoToDefinition<CR>
nnoremap <silent> gd :ALEGoToDefinition<CR>
nnoremap <silent> gds :ALEGoToDefinition -split<CR>
nnoremap <silent> gdt :ALEGoToDefinition -tab<CR>
nnoremap <silent> gdv :ALEGoToDefinition -vsplit<CR>
nnoremap <silent> gk :ALEDetail<CR>
let g:ale_linter_aliases = {'astro': ['css', 'javascript', 'typescript']}
let g:ale_fixers = {
\ 'astro': ['eslint', 'stylelint', 'prettier'],
\ 'css': ['stylelint', 'prettier'],
\ 'javascript': ['eslint', 'prettier'],
\ 'json': ['fixjson', 'prettier'],
\ 'html': ['prettier'],
\ 'markdown': ['remark-lint', 'prettier'],
\ 'python': ['ruff', 'ruff_format'],
\ 'rust': ['rustfmt'],
\ 'sh': ['shfmt'],
\ 'svelte': ['eslint', 'prettier'],
\ 'typescript': ['eslint', 'prettier'],
\ 'vue': ['eslint', 'prettier'],
\}
" TODO: add tsserver to astro. tsserver seems to parse a whole Astro file as TypeScript.
let g:ale_linters = {
\ 'astro': ['eslint', 'stylelint'],
\ 'css': ['stylelint'],
\ 'handlebars': ['ember-template-lint', 'glint'],
\ 'html': [],
\ 'javascript': ['eslint', 'tsserver'],
\ 'markdown': ['remark-lint'],
\ 'python': ['mypy', 'pylsp', 'ruff'],
\ 'typescript': ['eslint', 'tsserver'],
\ 'vue': ['eslint', 'vls'],
\}
set omnifunc=ale#completion#OmniFunc
" codeium
let g:codeium_no_map_tab = 1
imap <script><silent><nowait><expr> <M-Tab> codeium#Accept()
" gundo.vim
if has('python3')
let g:gundo_prefer_python3 = 1
endif
" lightline.vim
let g:lightline = {
\ 'colorscheme': 'iceberg',
\ 'active': {
\ 'left': [
\ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'absolutepath', 'modified' ]
\ ],
\ 'right': [
\ [ 'lineinfo' ],
\ [ 'linter_warnings', 'linter_errors', 'linter_ok' ],
\ ],
\ },
\ 'component': {
\ 'lineinfo': '%c%V',
\ },
\ 'component_expand': {
\ 'linter_warnings': 'lightline#ale#warnings',
\ 'linter_errors': 'lightline#ale#errors',
\ 'linter_ok': 'lightline#ale#ok',
\ },
\ 'component_function': {
\ 'gitbranch': 'LightlineFugitive',
\ 'readonly': 'LightlineReadonly',
\ },
\ 'component_type': {
\ 'linter_warnings': 'warning',
\ 'linter_errors': 'error'
\ },
\ 'inactive': {
\ 'left': [
\ [ 'absolutepath', 'modified' ],
\ ],
\ 'right': [
\ [ 'lineinfo' ],
\ ],
\ },
\ 'separator': {
\ 'left': '',
\ 'right': '',
\ },
\ 'subseparator': {
\ 'left': '',
\ 'right': '',
\ },
\}
let g:lightline#ale#indicator_warnings = '◆ '
let g:lightline#ale#indicator_errors = '✗ '
let g:lightline#ale#indicator_ok = '✓'
function! LightlineReadonly()
return &readonly ? '' : ''
endfunction
function! LightlineFugitive()
let branch = FugitiveHead()
return branch !=# '' ? ' '.branch : ''
endfunction
" QFEnter
let g:qfenter_vopen_map = ['<C-v>']
let g:qfenter_hopen_map = ['<C-x>']
let g:qfenter_topen_map = ['<C-t>']
" fzf.vim
let g:fzf_session_path = '~/.vim/session//'
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always ' . <q-args>, 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
map <silent> <Leader>i :Sessions<CR>
" Simulate ctrlp.vim with fzf.vim.
map <silent> <C-P> :Files<CR>
nnoremap <silent> <Leader>p :Buffers<CR>
" vim-highlightedyank
let g:highlightedyank_highlight_duration = 300
" vim-ifionly
nnoremap L :IfIOnly<CR>
" Markdown
let g:markdown_fenced_languages = [
\ 'bash=sh',
\ 'css',
\ 'handlebars=html',
\ 'hbs=html',
\ 'html',
\ 'javascript',
\ 'js=javascript',
\ 'json',
\ 'rust',
\ 'sh',
\ 'python',
\ 'zsh',
\]
let g:mkdp_auto_close = 1
" vim-rooter
let g:rooter_patterns = [
\ '.git',
\ 'Cargo.toml',
\ 'Gemfile',
\ 'Makefile',
\ 'package.json',
\ 'pyvenv.cfg',
\]
let g:rooter_silent_chdir = 1
" vim-sneak
let g:sneak#label = 1
" Treesitter
if has('nvim')
lua <<EOF
require'nvim-treesitter.configs'.setup {
ensure_installed = {
"astro",
"bash",
"css",
"glimmer",
"html",
"javascript",
"json",
"json5",
"just",
"make",
"markdown",
"python",
"ruby",
"rust",
"scss",
"svelte",
"swift",
"toml",
"tsx",
"typescript",
"vue",
},
highlight = {
enable = true,
},
incremental_selection = { enable = true },
indent = { enable = true },
matchup = { enable = true },
textobjects = { enable = true },
}
require("nvim-treesitter.parsers").get_parser_configs().just = {
install_info = {
url = "https://github.com/IndianBoy42/tree-sitter-just",
files = { "src/parser.c", "src/scanner.cc" },
branch = "main",
use_makefile = true,
},
maintainers = { "@IndianBoy42" },
}
EOF
endif
" vim-yankstack
let g:yankstack_yank_keys = ['c', 'C', 'd', 'D', 'x', 'X', 'y', 'Y']
nmap p <Plug>yankstack_substitute_older_paste
nmap P <Plug>yankstack_substitute_newer_paste
" -------------------------
" Spelling
" -------------------------
autocmd FileType gitcommit,markdown setl spell
" -------------------------
" Custom Bindings
" -------------------------
" Ease window switching in all directions. Inspired by vim-tmux-navigator,
" although I don't use tmux.
nmap <C-h> <C-w>h
nmap <C-j> <C-w>j
nmap <C-k> <C-w>k
nmap <C-l> <C-w>l
" Find/replace with visual feedback. Courtesy vim-over &
" https://github.com/toranb/dotfiles/blob/46ae158e51dbdbba72e284081dc9a12b5e54ef8c/vimrc#L130
nnoremap <Leader>fr :call VisualFindAndReplace()<CR>
xnoremap <Leader>fr :call VisualFindAndReplaceWithSelection()<CR>
function! VisualFindAndReplace()
:OverCommandLine%s/
endfunction
function! VisualFindAndReplaceWithSelection() range
:'<,'>OverCommandLine s/
endfunction