about summary refs log tree commit diff
path: root/nixos/config/vimrc
blob: 43b39ac310eecea0eb6c702d4c5cb8750e9edb25 (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
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
" This is Venomade's vimrc

" Install Vim Plug
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
  silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs  https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
  autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif

" PLUGins
call plug#begin('~/.vim/plugged')

" Maybe replace with fzf in future
Plug 'ctrlpvim/ctrlp.vim'

" COC because YCM is too hard
Plug 'neoclide/coc.nvim', {'branch': 'release'}

" Pretty Colors
Plug 'jackguo380/vim-lsp-cxx-highlight'
"put this into coc-settings.json
"{
    "suggest.noselect": true,
    "clangd.semanticHighlighting": true,
    "coc.preferences.semanticTokensHighlights": false
"}

" λ Mathematical Crowbars λ
Plug 'neovimhaskell/haskell-vim'

" I'm too lazy to actually program
Plug 'Exafunction/codeium.vim'

" Getting Gruuvy
Plug 'dkasak/gruvbox'

" Space then... ummm
Plug 'liuchengxu/vim-which-key'

" Ahhh a lovely #00ff00 field
Plug 'chrisbra/Colorizer'

" Customize the flight path
Plug 'vim-airline/vim-airline'

"          \("^_^")/
Plug 'LunarWatcher/auto-pairs'

" So take me back in time!!!
Plug 'farmergreg/vim-lastplace'

" One  please! Oooh and a   too!
" Plug 'ryanoasis/vim-devicons'

call plug#end()

" Colorscheme
colorscheme gruvbox
set bg=dark

" Undo History
set undofile
set undodir=~/.vim/undodir

" Common Settings
syntax on
filetype plugin indent on
set ts=2 sts=2 sw=4 et ai si
set nu rnu
set nowrap
set formatoptions-=cro
set splitbelow splitright
set encoding=UTF-8
set shell=zsh
set ignorecase
set smartcase
set incsearch

" Cursor Shapes
let &t_SI = "\<Esc>[6 q"
let &t_SR = "\<Esc>[4 q"
let &t_EI = "\<Esc>[2 q"

" Terminal Title
autocmd BufEnter * let &titlestring = '' . expand("%:t")
set title

" Airline Config
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#codeium#enabled = 1
let g:airline#extensions#tabline#formatter = 'unique_tail'
let g:airline_powerline_fonts = 1
let g:airline#extensions#coc#enabled = 1
let g:airline#extensions#coc#show_coc_status = 1


" Haskell Highlighting
let g:haskell_enable_quantification = 1   " to enable highlighting of `forall`
let g:haskell_enable_recursivedo = 1      " to enable highlighting of `mdo` and `rec`
let g:haskell_enable_arrowsyntax = 1      " to enable highlighting of `proc`
let g:haskell_enable_pattern_synonyms = 1 " to enable highlighting of `pattern`
let g:haskell_enable_typeroles = 1        " to enable highlighting of type roles
let g:haskell_enable_static_pointers = 1  " to enable highlighting of `static`
let g:haskell_backpack = 1                " to enable highlighting of backpack keywords

" Color Highlighting
set termguicolors
let g:colorizer_auto_color = 1

" AutoPairs
let g:AutoPairsMapBS = 1

" Recentre view on slow move
nnoremap j jzz
nnoremap k kzz

" Same for mouse
set mouse=a
map <ScrollWheelDown> 2jzz
map <ScrollWheelUp> 2kzz

" Leader Key
let mapleader = " "

" WhichKey
nnoremap <silent> <leader> :WhichKey '<Space>'<CR>

" Quick split movement
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l

" Terminal Buffer
map <leader>t :term<CR>

" Fuzzy Find
map <leader>ff :CtrlP<CR>
map <leader>fb :CtrlPBuffer<CR>
map <leader>fa :CtrlPMixed<CR>

" Copy and Paste from System Clipboard
noremap <Leader>y "*y
noremap <Leader>p "*p

" Quick Add/Remove Semicolon
map <leader>; :s/\v(.)$/\=submatch(1)==';' ? '' : submatch(1).';'<CR>

" Buffers
map <leader>bk :bd<CR>
map <leader>bn :bn<CR>
map <leader>bp :bp<CR>

" Clang Build Individual File (No Includes)
" map <leader>bf :!clang -Werror % -o out/%:r && ./out/%:r <CR>

" Haskell Run File
map <leader>rh :!runhaskell %<CR>

" Remove Trailing Whitespaces on Save
autocmd BufWritePre * %s/\s\+$//e

" Codeium Config
let g:codeium_disable_bindings = 1
inoremap <silent><script><expr> <C-space> codeium#Accept()

" ----------
" COC Config
" ----------
set encoding=utf-8

set nobackup "DANGER
set nowritebackup "But it's needed :/

set updatetime=300
set signcolumn=yes

function! CheckBackspace() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~# '\s'
endfunction

inoremap <silent><expr> <TAB>
      \ coc#pum#visible() ? coc#pum#next(1) :
      \ CheckBackspace() ? "\<Tab>" :
      \ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"

inoremap <silent><expr> <c-@> coc#refresh()

" GoTo code navigation
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)

" Use K to show documentation in preview window
nnoremap <silent> K :call ShowDocumentation()<CR>

function! ShowDocumentation()
  if CocAction('hasProvider', 'hover')
    call CocActionAsync('doHover')
  else
    call feedkeys('K', 'in')
  endif
endfunction

" Highlight the symbol and its references when holding the cursor
autocmd CursorHold * silent call CocActionAsync('highlight')

" Symbol renaming
nmap <leader>cn <Plug>(coc-rename)

" Formatting selected code
xmap <leader>cf  <Plug>(coc-format-selected)
nmap <leader>cf  <Plug>(coc-format-selected)

augroup mygroup
  autocmd!
  " Setup formatexpr specified filetype(s)
  autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  " Update signature help on jump placeholder
  autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end

" Applying code actions to the selected code block
" Example: `<leader>aap` for current paragraph
xmap <leader>caa  <Plug>(coc-codeaction-selected)
nmap <leader>caa  <Plug>(coc-codeaction-selected)

" Remap keys for applying code actions at the cursor position
nmap <leader>cac  <Plug>(coc-codeaction-cursor)
" Remap keys for apply code actions affect whole buffer
nmap <leader>cs  <Plug>(coc-codeaction-source)
" Apply the most preferred quickfix action to fix diagnostic on the current line
nmap <leader>qf  <Plug>(coc-fix-current)

" Remap keys for applying refactor code actions
nmap <silent> <leader>cre <Plug>(coc-codeaction-refactor)
xmap <silent> <leader>crs  <Plug>(coc-codeaction-refactor-selected)
nmap <silent> <leader>crs  <Plug>(coc-codeaction-refactor-selected)

" Run the Code Lens action on the current line
nmap <leader>cl  <Plug>(coc-codelens-action)

" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)

" Remap <C-f> and <C-b> to scroll float windows/popups
if has('nvim-0.4.0') || has('patch-8.2.0750')
  nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
  inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
  inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
  vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif

" Use CTRL-S for selections ranges
" Requires 'textDocument/selectionRange' support of language server
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)

" Add `:Format` command to format current buffer
command! -nargs=0 Format :call CocActionAsync('format')

" Add `:Fold` command to fold current buffer
command! -nargs=? Fold :call     CocAction('fold', <f-args>)

" Add `:OR` command for organize imports of the current buffer
command! -nargs=0 OR   :call     CocActionAsync('runCommand', 'editor.action.organizeImport')

" Add (Neo)Vim's native statusline support
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}

" Mappings for CoCList
" Show all diagnostics
nnoremap <silent><nowait> <space>cd  :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent><nowait> <space>ce  :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent><nowait> <space>cc  :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent><nowait> <space>co  :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent><nowait> <space>cs  :<C-u>CocList -I symbols<cr>
" Do default action for next item
nnoremap <silent><nowait> <space>cj  :<C-u>CocNext<CR>
" Do default action for previous item
nnoremap <silent><nowait> <space>ck  :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent><nowait> <space>cp  :<C-u>CocListResume<CR>