-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
804 lines (707 loc) · 24.2 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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
syntax on
filetype plugin indent on
" Install any missing plugins
autocmd VimEnter *
\ if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
\| PlugInstall --sync | q
\| endif
call plug#begin('~/.vim/vim-plug')
" Plugin Utils
Plug 'nvim-lua/plenary.nvim'
" Colorschemes
" Plug 'EdenEast/nightfox.nvim'
Plug 'KeitaNakamura/neodark.vim'
" Navigation
Plug 'easymotion/vim-easymotion'
Plug 'sjl/gundo.vim'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb'
Plug 'rbong/vim-flog'
Plug 'vim-scripts/taglist.vim'
Plug 'mileszs/ack.vim'
Plug 'junegunn/fzf.vim'
Plug 'gfanto/fzf-lsp.nvim'
Plug 'justinmk/vim-dirvish'
Plug 'roginfarrer/vim-dirvish-dovish'
Plug 'francoiscabrol/ranger.vim'
Plug 'tpope/vim-eunuch'
Plug 'lambdalisue/suda.vim'
Plug 'jeetsukumaran/vim-indentwise'
Plug 'unblevable/quick-scope'
Plug 'bronson/vim-visual-star-search'
Plug 't9md/vim-choosewin'
" Buffers
Plug 'jlanzarotta/bufexplorer'
Plug 'moll/vim-bbye'
Plug 'tmux-plugins/vim-tmux-focus-events'
Plug 'wesQ3/vim-windowswap'
Plug 'tpope/vim-obsession'
Plug 'simeji/winresizer'
Plug 'yssl/QFEnter'
Plug 'ncm2/float-preview'
Plug 'Shougo/echodoc'
Plug 'tommcdo/vim-lister'
" Editing
Plug 'andymass/vim-matchup'
Plug 'NvChad/nvim-colorizer.lua'
Plug 'AndrewRadev/splitjoin.vim'
Plug 'kana/vim-textobj-user'
Plug 'junegunn/vim-easy-align'
Plug 'michaeljsmith/vim-indent-object'
Plug 'nelstrom/vim-textobj-rubyblock'
Plug 'windwp/nvim-autopairs'
Plug 'sirver/UltiSnips'
Plug 'tommcdo/vim-exchange'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-commentary'
Plug 'glts/vim-textobj-comment'
" Plug 'suy/vim-context-commentstring'
Plug 'mattn/emmet-vim'
Plug 'christianrondeau/vim-base64'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'TiuSh/vim-toggline'
Plug 'lewis6991/gitsigns.nvim'
Plug 'RRethy/vim-illuminate'
" Other
Plug 'iamcco/markdown-preview.nvim', {'do': 'cd app && yarn install'}
Plug 'craigemery/vim-autotag'
Plug 'sheerun/vim-polyglot'
Plug 'vim-test/vim-test'
Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-dadbod'
" LSP & Completion
Plug 'neovim/nvim-lspconfig'
Plug 'elixir-tools/elixir-tools.nvim'
Plug 'jose-elias-alvarez/null-ls.nvim'
Plug 'Shougo/deoplete.nvim', {'do': ':UpdateRemotePlugins'}
Plug 'deoplete-plugins/deoplete-lsp'
" Treesitter
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'https://gitlab.com/HiPhish/rainbow-delimiters.nvim'
Plug 'JoosepAlviste/nvim-ts-context-commentstring'
Plug 'nvim-treesitter/nvim-treesitter-refactor'
Plug 'ziontee113/syntax-tree-surfer'
Plug 'RRethy/nvim-treesitter-endwise'
call plug#end()
if has('termguicolors')
if !has('neovim')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif
set termguicolors
endif
set background=dark
let g:neodark#solid_vertsplit = 1
let g:neodark#background = '#303030'
colorscheme neodark
" Colourscheme and highlighting
" red #DC657D
" green #84B97C
" yellow #D4AE58
" blue #639EE4
" purple #B888E2
" orange #E18254
" pink #DC94A2
" teal #4BB1A7
" golden_yellow #C99720
" light_blue #72C7D1
" brown #AE8785
highlight StatusLine guifg=#bcbcbc guibg=#545454
highlight StatusLineNC guifg=#8a8a8a guibg=#3a3a3a
highlight WinSeparator guibg=#3a3a3a
highlight ColorColumn ctermbg=red ctermfg=white guibg=#343434
highlight NormalFloat guibg=#3a3a3a
set fillchars+=vert:\
highlight Error ctermbg=none guibg=none
highlight DiagnosticError guifg=#DC657D guibg=#423538
highlight DiagnosticWarn guifg=#D4AE58 guibg=#413d35
highlight DiagnosticInfo guifg=#639EE4 guibg=#353b42
highlight DiagnosticUnderlineError gui=none guibg=#423538
highlight DiagnosticUnderlineWarn gui=none guibg=#413d35
highlight DiagnosticUnderlineInfo gui=none guibg=#353b42
highlight MatchParen gui=none guibg=#404040 guifg=none
highlight Search guifg=none guibg=#484336 gui=none
highlight CurSearch guifg=none guibg=#484336 gui=none
highlight IncSearch guifg=none guibg=#484336 gui=bold
highlight Visual guifg=none guibg=#484336
highlight QuickFixLine guifg=none guibg=#484336 gui=none
" highlight Identifier guifg=#AE8785
highlight Constant guifg=#4BB1A7
highlight Special guifg=#DC657D
highlight @operator guifg=#84B97C
highlight @function.call guifg=#84B97C
highlight @variable guifg=#AE8785
highlight @markup.raw.markdown_inline guifg=#E18254
" vim-illuminate
highlight IlluminatedWordText guibg=#433d3d
highlight IlluminatedWordRead guibg=#433d3d
highlight IlluminatedWordWrite guibg=#433d3d
" Rainbow Delimiters
highlight RainbowDelimiterA guifg=#D4AE58
highlight RainbowDelimiterB guifg=#84B97C
highlight RainbowDelimiterC guifg=#B888E2
highlight RainbowDelimiterD guifg=#639EE4
highlight RainbowDelimiterE guifg=#4BB1A7
highlight RainbowDelimiterF guifg=#E18254
lua << EOF
require("rainbow-delimiters.setup").setup({
highlight = {
'RainbowDelimiterA',
'RainbowDelimiterB',
'RainbowDelimiterC',
'RainbowDelimiterD',
'RainbowDelimiterE',
'RainbowDelimiterF'
}
})
EOF
set nowrap " Don't wrap by default
set linebreak " Wrap at word boundaries
set sidescroll=1 " Scroll 1 char at a time
set incsearch " Incremental search
set ignorecase " Ignore case when searching
set smartcase " ...but only when lower-case
set scrolloff=5 " Show 5-line context when scrolling
set autoindent " Automatic indentation
set showcmd " Show incomplete commands
set number " Line Number
set shiftwidth=2 " 2 spaces for indenting
set tabstop=2 " 2 spaces for tab
set softtabstop=2 " 2 spaces for backspace
set expandtab " Spaces instead of tabs
set hidden " Allow modified buffers to be hidden
set textwidth=80 " A good standard console width
set autoread " Re-read unchanged buffers if they change on-disk
set spelllang=en_gb " Set the spelling language
set colorcolumn=+1 " Highlight the column after textwidth
set signcolumn=yes " Always show the sign column (no auto-hide)
set updatetime=100 " Default is 4000; lower since most plugins use async
set splitbelow " When splitting, place cursor in bottom window
set splitright " When splitting, place cursor in right-hand window
set noequalalways " Don't resize all windows when closing one
set completeopt-=preview " The float-preview plugin handles completion popups
set listchars+=precedes:<,extends:> " Mark invisible portion of lines
set inccommand=split " Preview effects of substitutions in real time
set wildmode=longest:full,full " More expected command-mode completion
set exrc
" Cursor position highlighting
:nnoremap <silent> <Leader>ml :execute 'match Search /\%'.line('.').'l/'<CR>
:nnoremap <silent> <Leader>mc :execute '2match Search /\%'.virtcol('.').'v/'<CR>
:nmap <Leader>mx <Leader>ml<Leader>mc
:nnoremap <silent> <Leader>mn :match<CR>:2match<CR>
" Automatic window size adjustment
set winheight=25
set winwidth=86
set winminheight=5
set winminwidth=15
" Terminal interaction
set mouse=a " Turn on mouse support
if !has('nvim')
set ttymouse=xterm2 " This fixes window split dragging
endif
set ttimeoutlen=10 " Short timeout for keycodes, or <Esc> is slow to react
" Tmux sends these codes for C-Arrow combinations. As those combinations don't
" have keycode names we can map to directly, we map the keycode to unused
" F-keys, and map that key to our actual target. These codes start with an
" escape, which is why we don't want to map them directly: it would cause an
" annoying delay when trying to escape from insert mode.
if !('nvim') && &term == 'screen-256color'
set <F26>=[1;5A
map <F26> <C-Up>
map! <F26> <C-Up>
set <F27>=[1;5B
map <F27> <C-Down>
map! <F27> <C-Down>
set <F28>=[1;5C
map <F28> <C-Right>
map! <F28> <C-Right>
set <F29>=[1;5D
map <F29> <C-Left>
map! <F29> <C-Left>
endif
" Status Line
set laststatus=2
let &stl = ""
let &stl .= "%<%F " " File path
let &stl .= "%(| %R%M | %)" " Flags
let &stl .= "%= " " Right-align
" let &stl.="%(| %{fugitive#statusline()} %)"
let &stl .= "%(| %{&filetype} %)" " File type
let &stl .= "| %l-%c/%L " " Line/column number
" Dirvish
" Sort directories at the top
let g:dirvish_mode = ':sort _^.*[\/]_'
let g:dirvish_dovish_map_keys = 0
" See ftplugin/dirvish.vim
" choosewin
nmap _ <Plug>(choosewin)
" let g:choosewin_overlay_enable = 1
" Ranger
let g:ranger_map_keys = 0
" Matchup
let g:matchup_matchparen_offscreen = {'method': 'popup'}
command! WhereAmI :MatchupWhereAmI?
lua << EOF
require("nvim-autopairs").setup({})
require("gitsigns").setup()
require("colorizer").setup()
-- TreeSitter
require("nvim-treesitter.configs").setup({
auto_install = true,
highlight = {
enable = true
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<CR>",
node_incremental = "<CR>",
scope_incremental = "<Tab>",
node_decremental = "-"
}
},
indent = {
enable = true
},
endwise = {
enable = true
},
refactor = {
---- Disabled due to excessive slow-down in long C++ files
-- highlight_definitions = {
-- enable = true,
-- clear_on_cursor_move = false
-- },
smart_rename = {
enable = true,
keymaps = {
smart_rename = "<Leader>bR"
}
},
navigation = {
enable = true,
keymaps = {
goto_definition = "<Leader>bg",
list_definitions = "<Leader>br",
list_definitions_toc = "gO",
---- Using vim-illuminate instead due to performance
-- goto_next_usage = "]]",
-- goto_previous_usage = "[[",
}
}
}
})
-- vim-illuminate
vim.keymap.set("n", "[[", require('illuminate').goto_prev_reference)
vim.keymap.set("n", "]]", require('illuminate').goto_next_reference)
vim.keymap.set("n", "yom", require('illuminate').toggle)
-- TreeSitter Highlights - General
vim.api.nvim_set_hl(0, "@keyword", { link = "Define" })
vim.api.nvim_set_hl(0, "@keyword.function", { link = "Define" })
-- TreeSetter Highlights - Elixir
vim.api.nvim_set_hl(0, "@module.elixir", { link = "Type" })
-- Syntax Tree Surfer
require("syntax-tree-surfer").setup({})
local opts = { noremap = true, silent = true }
-- Normal Mode Swapping:
-- Swap The Master Node relative to the cursor with its siblings. Dot-repeatable.
vim.keymap.set("n", "<Leader>K", function()
vim.opt.opfunc = "v:lua.STSSwapUpNormal_Dot"
return "g@l"
end, { silent = true, expr = true })
vim.keymap.set("n", "<Leader>J", function()
vim.opt.opfunc = "v:lua.STSSwapDownNormal_Dot"
return "g@l"
end, { silent = true, expr = true })
-- Swap Current Node at the Cursor with its siblings. Dot-repeatable.
vim.keymap.set("n", "<Leader>k", function()
vim.opt.opfunc = "v:lua.STSSwapCurrentNodePrevNormal_Dot"
return "g@l"
end, { silent = true, expr = true })
vim.keymap.set("n", "<Leader>j", function()
vim.opt.opfunc = "v:lua.STSSwapCurrentNodeNextNormal_Dot"
return "g@l"
end, { silent = true, expr = true })
-- Visual Selection from Normal Mode
-- vim.keymap.set("n", "vx", '<cmd>STSSelectMasterNode<cr>', opts)
-- vim.keymap.set("n", "vn", '<cmd>STSSelectCurrentNode<cr>', opts)
-- Select Nodes in Visual Mode
vim.keymap.set("x", "gk", '<cmd>STSSelectPrevSiblingNode<cr>', opts)
vim.keymap.set("x", "gj", '<cmd>STSSelectNextSiblingNode<cr>', opts)
vim.keymap.set("x", "gh", '<cmd>STSSelectParentNode<cr>', opts)
vim.keymap.set("x", "gl", '<cmd>STSSelectChildNode<cr>', opts)
-- Swapping Nodes in Visual Mode
vim.keymap.set("x", "<Leader>k", '<cmd>STSSwapPrevVisual<cr>', opts)
vim.keymap.set("x", "<Leader>j", '<cmd>STSSwapNextVisual<cr>', opts)
-- LSP - Language Server Protocol
local nvim_lsp = require('lspconfig')
-- Elixir
require("elixir").setup({
nextls = {
enable = true,
spitfire = true,
init_options = {
experimental = {
completions = {
enable = true
}
}
}
},
elixirls = {enable = false}
})
-- nvim_lsp['elixirls'].setup({
-- cmd = { os.getenv("HOME") .. "/.vim/elixir-ls/rel/language_server.sh" },
-- })
-- C/C++
nvim_lsp['clangd'].setup({
capabilities = {
-- https://github.com/neovim/nvim-lspconfig/issues/2184
offsetEncoding = 'utf-16'
}
})
-- Rust
nvim_lsp['rust_analyzer'].setup({
settings = {
["rust-analyzer"] = {
checkOnSave = {
command = "clippy"
}
}
}
})
-- Typescript
nvim_lsp['tsserver'].setup({})
-- VueJS
-- nvim_lsp['vuels'].setup({})
nvim_lsp['volar'].setup({})
-- Python
nvim_lsp['pylsp'].setup({})
-- Diagnostics and Formatting
local null_ls = require("null-ls")
null_ls.setup({
sources = {
null_ls.builtins.diagnostics.eslint.with({
prefer_local = "node_modules/.bin"
}),
-- null_ls.builtins.diagnostics.credo,
null_ls.builtins.formatting.prettier.with({
prefer_local = "node_modules/.bin"
}),
null_ls.builtins.code_actions.gitsigns
}
})
lsp_autoformat = function(opts)
opts = opts or {}
local async = opts["async"] or true
local range = nil
if opts["only_selected"] then
range = {
["start"] = vim.api.nvim_buf_get_mark(0, "<"),
["end"] = vim.api.nvim_buf_get_mark(0, ">")
}
end
vim.lsp.buf.format({
async = async,
filter =
function(client)
return client.name ~= "tsserver"
end,
range = range
})
end
EOF
" LSP bindings
" See `:help vim.lsp.*` for documentation on any of the below functions
nnoremap <silent> <Leader>aa :lua vim.lsp.buf.code_action()<CR>
nnoremap <silent> <Leader>ad :lua vim.lsp.buf.declaration()<CR>
nnoremap <silent> <Leader>ag :lua vim.lsp.buf.definition()<CR>
nnoremap <silent> <Leader>ai :lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> <Leader>ah :lua vim.lsp.buf.hover()<CR>
nnoremap <silent> <Leader>af :lua vim.diagnostic.open_float()<CR>
nnoremap <silent> <Leader>aF :lua lsp_autoformat()<CR>
vnoremap <silent> <Leader>aF :lua lsp_autoformat({ only_selected = true})<CR>
nnoremap <silent> <Leader>ar :lua vim.lsp.buf.references()<CR>
nnoremap <silent> <Leader>aR :lua vim.lsp.buf.rename()<CR>
" Deoplete options
let g:deoplete#enable_at_startup = 1
inoremap <expr><tab> pumvisible() ? "\<c-n>" : "\<tab>"
inoremap <expr><s-tab> pumvisible() ? "\<c-p>" : "\<s-tab>"
call deoplete#custom#source('lsp', 'max_abbr_width', 0)
call deoplete#custom#source('lsp', 'max_menu_width', 0)
" VimTest
let test#strategy = "neovim"
let test#neovim#term_position = ""
nmap <silent> <Leader>tn :TestNearest<CR>
nmap <silent> <Leader>tN :TestNearest<CR><C-o><C-w>_i
nmap <silent> <Leader>tf :TestFile<CR>
nmap <silent> <Leader>tF :TestFile<CR><C-o><C-w>_i
nmap <silent> <Leader>ta :TestSuite<CR>
nmap <silent> <Leader>tA :TestSuite<CR><C-o><C-w>_i
nmap <silent> <Leader>tt :TestLast<CR>
nmap <silent> <Leader>tT :TestLast<CR><C-o><C-w>_i
nmap <silent> <Leader>tg :TestVisit<CR>
" BufExplorer
let g:bufExplorerShowRelativePath=1
" GitSigns
nnoremap <silent> <Leader>hp :Gitsigns preview_hunk<CR>
nnoremap <silent> [h :Gitsigns prev_hunk<CR>
nnoremap <silent> ]h :Gitsigns next_hunk<CR>
xnoremap ah :<C-U>Gitsigns select_hunk<CR>
onoremap ah :<C-U>Gitsigns select_hunk<CR>
xnoremap ih :<C-U>Gitsigns select_hunk<CR>
onoremap ih :<C-U>Gitsigns select_hunk<CR>
" echodoc
let g:echodoc_enable_at_startup = 1
let g:echodoc#type = 'floating'
" FZF (Fuzzy Find)
noremap <Leader>oc :BTags<CR>
noremap <Leader>ob :Buffers<CR>
noremap <Leader>of :Files<CR>
noremap <Leader>oh :Helptags<CR>
noremap <Leader>ol :BLines<CR>
noremap <Leader>ot :Tags<CR>
noremap <Leader>oz :Rg<Space>
imap <C-X><C-w> <plug>(fzf-complete-word)
imap <C-X><C-f> <plug>(fzf-complete-path)
let g:fzf_layout = { 'window': 'enew' }
let g:fzf_colors = {
\ "fg": ["fg", "Normal"],
\ "bg": ["bg", "Normal"],
\ "hl": ["fg", "Conditional"],
\ "fg+": ["fg", "CursorLine", "CursorColumn", "Normal"],
\ "bg+": ["bg", "CursorLine", "CursorColumn"],
\ "hl+": ["fg", "Conditional"],
\ "info": ["fg", "Conditional"],
\ "border": ["fg", "Ignore"],
\ "prompt": ["fg", "Comment"],
\ "pointer": ["fg", "Conditional"],
\ "marker": ["fg", "Conditional"],
\ "spinner": ["fg", "Conditional"],
\ "header": ["fg", "WildMenu"]
\ }
augroup FZF
autocmd!
autocmd! User FzfStatusLine setlocal statusline=[fzf]
augroup END
function! s:build_quickfix_list(lines)
call setqflist(map(copy(a:lines), '{ "filename": v:val }'))
copen
cc
endfunction
function! s:build_location_list(lines)
call setloclist(0, map(copy(a:lines), '{ "filename": v:val }'))
lopen
ll
endfunction
let g:fzf_action = {
\ 'ctrl-q': function('s:build_quickfix_list'),
\ 'ctrl-l': function('s:build_location_list')
\ }
" Folding
noremap <Leader>zz :setlocal foldmethod=syntax<CR>
noremap <Leader>zi :setlocal foldmethod=indent<CR>
noremap <Leader>zm :setlocal foldmethod=manual<CR>
" Indent Guides
" let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_guide_size = 1
let g:indent_guides_auto_colors = 0
augroup IndentGuides
autocmd!
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=#343434 ctermbg=darkgrey
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=#343434 ctermbg=darkgrey
augroup END
" IndentWise
map [< <Plug>(IndentWisePreviousLesserIndent)
map [> <Plug>(IndentWisePreviousGreaterIndent)
map [= <Plug>(IndentWiseBlockScopeBoundaryBegin)
map ]< <Plug>(IndentWiseNextLesserIndent)
map ]> <Plug>(IndentWiseNextGreaterIndent)
map ]= <Plug>(IndentWiseBlockScopeBoundaryEnd)
map [+ <Plug>(IndentWisePreviousEqualIndent)
map ]+ <Plug>(IndentWiseNextEqualIndent)
" map [_ <Plug>(IndentWisePreviousAbsoluteIndent)
" map ]_ <Plug>(IndentWiseNextAbsoluteIndent)
" Ack (Searching)
command! -nargs=* Find :Ack! -- <q-args>
noremap <Leader>f :Find<Space>
noremap <Leader>x :cclose<CR>:pclose<CR>
let g:ackprg = 'rg --vimgrep --smart-case -F'
" UltiSnips options
let g:UltiSnipsUsePythonVersion=3
let g:UltiSnipsSnippetDirectories=['~/.vim/UltiSnips', 'UltiSnips']
let g:UltiSnipsExpandTrigger = "<C-L>"
let g:UltiSnipsJumpForwardTrigger = "<C-L>"
let g:UltiSnipsJumpBackwardTrigger = "<C-H>"
" windowswap
let g:windowswap_map_keys = 0
nnoremap <silent> <leader>wx :call WindowSwap#EasyWindowSwap()<CR>
" Gundo
let g:gundo_width = 25
let g:gundo_prefer_python3 = 1
" Quick-Scope
let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']
" remap j and k so that they move through display lines, rather than physical lines
noremap j gj
noremap <Down> gj
noremap k gk
noremap <Up> gk
" Visually select the text that was last edited / pasted
nmap gV '[V']
" Easy window switching
noremap <C-j> <C-w><C-j>
noremap <C-k> <C-w><C-k>
noremap <C-h> <C-w><C-h>
noremap <C-l> <C-w><C-l>
" Easy viewport scrolling
noremap <A-j> <C-e>
noremap <A-k> <C-y>
noremap <A-h> zh
noremap <A-l> zl
noremap <Space> 3<C-e>
noremap <C-Space> 3<C-y>
" map Q to replay the 'q' macro
nnoremap Q @q
" I often accidentally hit F1 instead of ESC
map <F1> <ESC>
map! <F1> <ESC>
" Shortcuts
nnoremap <Leader>lt :TlistToggle<CR>
vmap <Leader>a <Plug>(LiveEasyAlign)
nmap <Leader>a <Plug>(LiveEasyAlign)
nnoremap <Leader>ts :split +terminal<CR>i
nnoremap <Leader>tv :vsplit +terminal<CR>i
nnoremap <C-w>S :botright split<CR>
nnoremap <C-w>V :botright vsplit<CR>
" Toggle paragraph auto-formatting
function! s:toggle_autoformat()
if &formatoptions =~ 'a'
echo "Auto-format OFF"
set formatoptions-=a
else
echo "Auto-format ON"
set formatoptions+=a
endif
endfunction
nnoremap <silent> yfa :call <SID>toggle_autoformat()<CR>
" Git / Fugitive
nnoremap <Leader>gu :GundoToggle<CR>
nnoremap <Leader>gg :G<CR>
nnoremap <Leader>gt :Flog -all<CR>
vnoremap <Leader>gt :Flog<CR>
nnoremap <Leader>gT :Flog -path=%<CR>
nnoremap <Leader>gca :G commit --amend<CR>
nnoremap <Leader>gcc :G commit<CR>
nnoremap <Leader>gco :G checkout<Space>
nnoremap <Leader>gcs :G show<Space>
nnoremap <Leader>gia :G add<Space>
nnoremap <Leader>gid :G diff --cached<CR>
nnoremap <Leader>gs :G stash<Space>
nnoremap <Leader>gwd :G diff<Space>
" Echo highlight group name under cursor
nnoremap <F8> :echo synIDattr(synID(line('.'), col('.'), 1), 'name')<CR>
" Easier switch to Normal mode in terminal
if has('nvim')
tmap <C-o> <C-\><C-n>
endif
" End-of-line whitespace highlighting
" http://sartak.org/2011/03/end-of-line-whitespace-in-vim.html
augroup EndOfLineWhitespace
autocmd!
autocmd InsertEnter * syn clear EOLWS | syn match EOLWS excludenl /\s\+\%#\@!$/
autocmd InsertLeave * syn clear EOLWS | syn match EOLWS excludenl /\s\+$/
augroup END
highlight EOLWS ctermbg=red guibg=#904040
" Remove all end-of-line whitespace
" http://sartak.org/2011/03/end-of-line-whitespace-in-vim.html
function! <SID>StripTrailingWhitespace()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
%s/\s\+$//e
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
nmap <silent> <Leader><space> :call <SID>StripTrailingWhitespace()<CR>
" Bubble text up and down
nmap <C-Up> [e
nmap <C-Down> ]e
vmap <C-Up> [egv
vmap <C-Down> ]egv
" Easy window / buffer management
nnoremap <Leader>bc :Bdelete<CR>
nnoremap <Leader>qq :quit<CR>
" EasyMotion
nmap s <Plug>(easymotion-s2)
xmap s <Plug>(easymotion-s2)
omap z <Plug>(easymotion-s2)
nmap <Leader>s <Plug>(easymotion-sn)
xmap <Leader>s <Plug>(easymotion-sn)
omap <Leader>z <Plug>(easymotion-sn)
" Emmet
let g:user_emmet_leader_key=','
let g:user_emmet_mode='nv'
" Toggline
nmap <silent> <Leader>a, :call toggline#End(',')<CR>
nmap <silent> <Leader>a. :call toggline#With('[.]$', '', '[^.]$', '\0.')<CR>
nmap <silent> <Leader>a; :call toggline#End(';')<CR>
" Scratch buffers
function! ScratchBuffer(name)
execute "visual " . a:name
setlocal buftype=nofile
setlocal bufhidden=hide
setlocal noswapfile
endfun
command! -nargs=1 ScratchBuffer :call ScratchBuffer('<args>')
" Shortcuts for entering scratch buffer
:nnoremap <silent> <Leader>cs :split<CR>:ScratchBuffer scratch<CR>
:nnoremap <silent> <Leader>cv :vsplit<CR>:ScratchBuffer scratch<CR>
:nnoremap <silent> <Leader>cS :botright :split<CR>:ScratchBuffer scratch<CR>
:nnoremap <silent> <Leader>cV :botright :vsplit<CR>:ScratchBuffer scratch<CR>
:vnoremap <silent> <Leader>cs y:split<CR>:ScratchBuffer scratch<CR>ggVGp
:vnoremap <silent> <Leader>cv y:vsplit<CR>:ScratchBuffer scratch<CR>ggVGp
:vnoremap <silent> <Leader>cS y:botright :split<CR>:ScratchBuffer scratch<CR>ggVGp
:vnoremap <silent> <Leader>cV y:botright :vsplit<CR>:ScratchBuffer scratch<CR>ggVGp
" Work around for eunuch plugin
" See: https://github.com/tpope/vim-eunuch/issues/56
" NOTE: Get rid of suda when it's not needed any more
command! SudoWrite :w suda://%
" XML Formatting
command! PrettyXML %!xmllint --format -
augroup vimrc
autocmd!
" https://neovim.io/doc/user/lua.html#vim.highlight
autocmd TextYankPost * silent! lua vim.highlight.on_yank {higroup='Visual', timeout=1000}
" Place the cursor where it was when the file was last edited
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Auto-close Fugitive buffers after we're done with them
autocmd BufReadPost fugitive://* set bufhidden=delete
" Auto-close preview window after completion
autocmd InsertLeave * silent! pclose!
" Auto-format on save
" autocmd BufWritePre * lua lsp_autoformat({ async = false })
" Language-specific
autocmd BufReadCmd *.epub call zip#Browse(expand("<amatch>"))
autocmd BufRead *.md set filetype=markdown
autocmd BufRead *.qml set filetype=qml smartindent
autocmd FileType asciidoc setlocal wrap spell
autocmd FileType elixir setlocal textwidth=98 colorcolumn=99 formatoptions+=c foldlevel=1 formatexpr=
autocmd FileType help setlocal nospell
autocmd FileType text setlocal formatoptions=ant
autocmd FileType mail setlocal textwidth=75 colorcolumn=76 formatoptions=ant
autocmd FileType make setlocal tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab
autocmd FileType markdown setlocal wrap spell
autocmd FileType typescript syntax sync fromstart
autocmd FileType vue setlocal formatoptions-=t
autocmd FileType * let &l:formatprg = "par -w" . &l:textwidth
augroup END
let g:xml_syntax_folding=1