summaryrefslogtreecommitdiff
path: root/vim/.vimrc
blob: 85e73dfe20adbc736bcb5c3f7131df8ebe22bf6a (plain)
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
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
endif
let g:polyglot_disabled = ['markdown']
call plug#begin('~/.vim/plugged')
Plug 'itchyny/lightline.vim'
Plug 'rafi/awesome-vim-colorschemes'
Plug 'mattn/emmet-vim'
Plug 'liuchengxu/vim-which-key'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'kamil-stachowski/flatwhite-vim'
Plug 'ap/vim-buftabline'
Plug 'sheerun/vim-polyglot'
Plug 'preservim/vim-markdown'
Plug 'tpope/vim-commentary'
Plug 'yegappan/lsp'
Plug 'dense-analysis/ale'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'andymass/vim-matchup'
Plug 'kalbasit/vim-colemak'
call plug#end()

let mapleader = "\<Space>"
syntax on
filetype on
filetype indent on
filetype plugin on

set updatetime=300
set completeopt=menuone,popup,noinsert,noselect
set scrolloff=5 " same as helix's scrolloff
set clipboard=unnamedplus
set splitright
set splitbelow
set confirm
set title
set fileformat=unix
set encoding=UTF-8
set number
set nowrap
set relativenumber
set expandtab
set tabstop=4
set shiftwidth=4
set smarttab
set smartindent
set noswapfile
set incsearch
set ignorecase
set smartcase
set autochdir
set hidden
set virtualedit=onemore
set timeoutlen=500
set ttimeoutlen=1
set termguicolors
set laststatus=2
set noshowmode
set undofile
set undodir=~/.vim/undodir
set signcolumn=yes
set shortmess+=c
" etc
colorscheme carbonized-dark
augroup colors_whichkey
    autocmd!
autocmd FileType which_key highlight WhichKey         guifg=#88C0D0 gui=bold
autocmd FileType which_key highlight WhichKeySeperator guifg=#4C566A
autocmd FileType which_key highlight WhichKeyGroup     guifg=#EBCB8B gui=bold
autocmd FileType which_key highlight WhichKeyDesc      guifg=#ECEFF4
augroup END

nnoremap <Space> <Nop>
nnoremap <silent> <leader> :WhichKey '<Space>'<CR>
inoremap <silent> <Esc> <Esc>l
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
function! Oxlint_fix(buffer) abort
    return {
                \ 'command': 'oxlint --fix --stdin --stdin-filename %s < %t'
                \}
endfunction
execute ale#fix#registry#Add('oxlint', 'Oxlint_fix', ['javascript', 'typescript'], 'oxlint')
let g:ale_linters = {
            \'vim': ['vint'],
            \'css': ['stylelint'],
            \'html': ['tidy', 'htmlhint'],
            \'javascript': [],
            \'typescript': [],
            \'go': ['golangci-lint'],
            \'markdown': [],
            \}
let g:ale_fixers = {
            \'html': ['tidy'],
            \'javascript': ['oxlint'],
            \'typescript': ['oxlint'],
            \}
let g:ale_html_tidy_options = '-indent -asxhtml -q '
let g:ale_sign_column_always = 1
let g:lsp_settings_filetype_markdown = []
let g:ale_lint_on_save = 1
let g:ale_fix_on_save = 1

let g:buftabline_show = 2
let g:buftabline_numbers = 1

let g:user_emmet_leader_key='<Space>'
let g:user_emmet_mode='n'
let g:user_emmet_install_global = 0

let g:surround_no_mappings = 1

let g:vim_markdown_folding_disabled = 0
let g:vim_markdown_folding_style_pythonic = 1
let g:vim_markdown_override_foldtext = 0
let g:vim_markdown_conceal_code_blocks = 1
let g:vim_markdown_fenced_languages = ['haskell']
augroup md_fold
autocmd!
autocmd FileType markdown setlocal foldlevelstart=99
autocmd FileType markdown setlocal conceallevel=2 concealcursor=nc
augroup END

let g:which_key_map = {}
let g:which_key_map.f = ['Files', 'file buffer']
let g:which_key_map.b = {
            \ 'name' : '+buffer',
            \ 'n' : ['bn', 'next buffer'],
            \ 'p' : ['bp', 'previous buffer'],
            \ 'b' : ['Buffers', 'fuzzy find buffers'],
            \ }
nmap <leader>sa  <Plug>Ysurround
nmap <leader>saa <Plug>Yssurround
nmap <leader>sc  <Plug>Csurround
nmap <leader>sd  <Plug>Dsurround
xmap <leader>s   <Plug>VSurround

let g:which_key_map.s = { 'name' : '+surround' }
let g:which_key_map.s.a  = 'add surround'
let g:which_key_map.s.aa = 'add surround (line)'
let g:which_key_map.s.c  = 'change surround'
let g:which_key_map.s.d  = 'delete surround'
call which_key#register('<Space>', 'g:which_key_map')

augroup lsp
    autocmd!
autocmd User LspSetup call LspOptionsSet(#{
            \ autoComplete: v:true,
            \ autoHighlightDiags: v:true,
            \ noNewlineCompletion: v:true,
            \ showDiagInPopup: v:true,
            \ formatFallback: v:false,
            \ })

autocmd User LspSetup call LspAddServer([
            \ #{name: 'hs', filetype: ['haskell', 'lhaskell'], path: 'haskell-language-server-wrapper'},
            \ #{name: 'pylsp',  filetype: 'python',  path: 'pylsp'},
            \ #{name: 'clangd', filetype: ['c', 'cpp', 'objc', 'objcpp'], path: 'clangd', args: ['--background-index']},
            \ #{name: 'html', filetype: 'html', path: 'vscode-html-language-server', args: ['--stdio']},
            \ #{name: 'css', filetype: ['css', 'scss', 'less'], path: 'vscode-css-language-server', args: ['--stdio']},
            \ #{name: 'ts', filetype: ['typescript', 'javascript', 'javascriptreact', 'typescriptreact'], path: 'typescript-language-server', args: ['--stdio']},
            \ #{name: 'oxlint', filetype: ['typescript', 'javascript', 'javascriptreact', 'typescriptreact'], path: 'oxlint', args: ['--lsp']},
            \ #{name: 'vim', filetype: 'vim', path: 'vim-language-server', args: ['--stdio']},
            \ #{name: 'go', filetype: 'go', path: 'gopls', args: ['--stdio']},
            \ #{name: 'zk', filetype: 'markdown', path: 'zk', args: ['lsp']},
            \])


autocmd User LspAttached call s:lsp_keymaps()
function! s:lsp_keymaps() abort
    nmap <buffer> gs  :LspDocumentSymbol<CR>
    nmap <buffer> gr  :LspShowReferences<CR>
    nmap <buffer> gi  :LspGotoImpl<CR>
    nmap <buffer> gt  :LspGotoTypeDef<CR>
    nmap <buffer> gm  :LspGotoDefinition<CR>
    nmap <buffer> <leader>rn :LspRename<CR>
    nmap <buffer> [g  :LspDiagPrev<CR>
    nmap <buffer> ]g  :LspDiagNext<CR>
    nmap <buffer> K   :LspHover<CR>
    if index(['vim', 'html', 'css', 'markdown'], &filetype) == -1
        autocmd BufWritePre <buffer> LspFormat
    endif
endfunction
augroup END