-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.vim
514 lines (387 loc) · 13.5 KB
/
init.vim
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
syntax on
filetype plugin indent on
set nocompatible
set number
set nowrap
set noshowmode
set tw=80
set formatprg=par
set pumheight=12
set conceallevel=0
set smartcase
set smarttab
set smartindent
set autoindent
set softtabstop=2
set shiftwidth=2
set expandtab
set vb
set nofoldenable
set wildignore+=*\\tmp\\*,*.swp,*.swo,*.zip,.git,.cabal-sandbox,.stack-work
set wildmode=longest,list,full
set wildmenu
set cmdheight=1
call plug#begin('~/.vim/plugged')
" Full path fuzzy file, buffer, mru, tag, ... finder for Vim.
Plug 'ctrlpvim/ctrlp.vim'
" Terminal
Plug 'kassio/neoterm'
" Lean & mean status/tabline for vim that's light as air
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" A tree explorer plugin for vim.
Plug 'scrooloose/nerdtree'
" Comments
Plug 'scrooloose/nerdcommenter'
" Nerd Tree Git status
Plug 'Xuyuanp/nerdtree-git-plugin'
" JSON
Plug 'tpope/vim-jdaddy'
" Repeat
Plug 'tpope/vim-repeat'
" Tabular
Plug 'godlygeek/tabular'
" Git
Plug 'tpope/vim-fugitive'
" Surround
Plug 'tpope/vim-surround'
" Haskell formatting
Plug 'sdiehl/vim-ormolu'
" Utilities
Plug 'tomtom/tlib_vim'
" Commenting
Plug 'tpope/vim-commentary'
" JavaScript
Plug 'neoclide/coc.nvim', {'do': 'yarn install --frozen-lockfile'} " this is for auto complete, prettier and tslinting
let g:coc_global_extensions = ['coc-tslint-plugin', 'coc-tsserver', 'coc-css', 'coc-html', 'coc-json', 'coc-prettier'] " list of CoC extensions needed
Plug 'jiangmiao/auto-pairs' "this will auto close ( [ {
Plug 'neoclide/coc.nvim', {'do': 'yarn install --frozen-lockfile'} " this is for auto complete, prettier and tslinting
let g:coc_global_extensions = ['coc-tslint-plugin', 'coc-tsserver', 'coc-css', 'coc-html', 'coc-json', 'coc-prettier'] " list of CoC extensions needed
Plug 'jiangmiao/auto-pairs' "this will auto close ( [ {
" these two plugins will add highlighting and indenting to JSX and TSX files.
Plug 'yuezk/vim-js'
Plug 'HerringtonDarkholme/yats.vim'
Plug 'maxmellon/vim-jsx-pretty'
" these two plugins will add highlighting and indenting to JSX and TSX files.
Plug 'yuezk/vim-js'
Plug 'HerringtonDarkholme/yats.vim'
Plug 'maxmellon/vim-jsx-pretty'
" ----------------------------------------------
" Rust
" ----------------------------------------------
" Collection of common configurations for the Nvim LSP client
Plug 'neovim/nvim-lspconfig'
" Extensions to built-in LSP, for example, providing type inlay hints
Plug 'nvim-lua/lsp_extensions.nvim'
" Autocompletion framework for built-in LSP
Plug 'nvim-lua/completion-nvim'
Plug 'rust-lang-nursery/rustfmt'
call plug#end()
" ----------------------------------------------
" Snippets
" ----------------------------------------------
:imap <C-J> <Plug>snipMateNextOrTrigger
:smap <C-J> <Plug>snipMateNextOrTrigger
" ----------------------------------------------
" Colors
" ----------------------------------------------
colorscheme NeoSolarized
""if strftime("%H") < 20
"" set background=light
""else
set background=dark
""endif
" ----------------------------------------------
" Terminal
" ----------------------------------------------
tnoremap <Esc> <C-\><C-n>
" ----------------------------------------------
" Colors
" ----------------------------------------------
set termguicolors
set t_Co=256
" ----------------------------------------------
" Tab Completion
" ----------------------------------------------
set completeopt=menuone,menu,longest
set completeopt+=longest
inoremap <C-Space> <C-x><C-o>
inoremap <C-@> <C-Space>
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <expr> <tab> InsertTabWrapper()
inoremap <s-tab> <c-n>
" ----------------------------------------------
" CTRL+P
" ----------------------------------------------
map <silent> <Leader>t :CtrlP()<CR>
noremap <leader>b<space> :CtrlPBuffer<cr>
let g:ctrlp_custom_ignore = '\v[\/]dist$'
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard']
" ----------------------------------------------
" NerdTree
" ----------------------------------------------
map <Leader>n :NERDTreeToggle<CR>
let NERDTreeIgnore = ['\.pyc$','.stack-work','*.swp']
let g:NERDTreeChDirMode = 2
" ----------------------------------------------
" Indentation
" ----------------------------------------------
map <Leader>ig :IndentGuidesToggle<CR>
" ----------------------------------------------
" Fix trailing Whitespace
" ----------------------------------------------
" Autofix all whitespace on save
autocmd BufWritePre *.py :%s/\s\+$//e
" Delete all trailing empty lines on files
autocmd BufWritePre *.py :%s/\(\s*\n\)\+\%$//e
" Autofix all whitespace on save
autocmd BufWritePre *.hs :%s/\s\+$//e
" Delete all trailing empty lines on files
autocmd BufWritePre *.hs :%s/\(\s*\n\)\+\%$//e
"
" ----------------------------------------------
" Nightmode
" ----------------------------------------------
" ----------------------------------------------
" GUI Options
" ----------------------------------------------
set mouse=a
set mousemodel=popup
set guioptions-=m
set guioptions-=r
set guioptions-=T
set guioptions-=L
set wildmenu
set wildmode=longest:list
set dictionary="/usr/dict/words"
" ----------------------------------------------
" Flush
" ----------------------------------------------
" Flush swap files recursively in this directory, usefull if Vim
" crashes.
command! Flush :call Flush()
func! Flush()
exec "!find . -name \".*.swp\" | xargs rm -f"
endfunc
" ----------------------------------------------
" HTML
" ----------------------------------------------
let g:mta_use_matchparen_group = 1
" ----------------------------------------------
" Haskell
" ----------------------------------------------
let g:ormolu_options=["--unsafe", "-o -XTypeApplications"]
"let g:ormolu_disable=1
nnoremap tf :call RunOrmolu()<CR>
nnoremap to :call ToggleOrmolu()<CR>
xnoremap tb :<c-u>call OrmoluBlock()<CR>
let $PATH = $PATH . ':' . expand('~/.stack/bin')
" Type Lookup
map tt :call GHC_ShowType(0)<CR>
" Type Insertion
map <silent> tw :GhcModTypeInsert<CR>
map <silent> ts :GhcModSplitFunCase<CR>
map <silent> tq :GhcModType<CR>
map <silent> te :GhcModTypeClear<CR>
au FileType haskell nnoremap <buffer> <F1> :GhcModType<CR>
au FileType haskell nnoremap <buffer> <F2> :GhcModTypeClear<CR>
function! Pointfree()
call setline('.', split(system('pointfree '.shellescape(join(getline(a:firstline, a:lastline), "\n"))), "\n"))
endfunction
vnoremap <silent> <leader>h. :call Pointfree()<CR>
nmap <silent> <leader>hl :SyntasticCheck hlint<CR>
" ----------------------------------------------
" Syntastic
" ----------------------------------------------
map <Leader>s :SyntasticToggleMode<CR>
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 0
let g:syntastic_check_on_open = 0
let g:syntastic_check_on_wq = 0
"let g:syntastic_mode_map = { 'mode': 'active', 'passive_filetypes': ['haskell'] }
" ----------------------------------------------
" Python
" ----------------------------------------------
autocmd bufnewfile,bufread *.py set formatprg=par
" ----------------------------------------------
" Other Languages
" ----------------------------------------------
autocmd BufNewFile,BufRead *.y set filetype=happy
autocmd BufNewFile,BufRead *.x set filetype=alex
autocmd BufNewFile,BufRead *.agda set filetype=agda
autocmd BufNewFile,BufRead *.idr set filetype=idris
autocmd BufNewFile,BufRead *.ocaml set filetype=ocaml
autocmd BufNewFile,BufRead *.js set filetype=javascript
autocmd BufNewFile,BufRead *.md set filetype=markdown
autocmd BufNewFile,BufRead *.ll set filetype=llvm
autocmd BufNewFile,BufRead *.scala set filetype=scala
autocmd BufNewFile,BufRead *.c set filetype=c
autocmd BufNewFile,BufRead *.ws set filetype=wist
" ----------------------------------------------
" Pane Switching
" ----------------------------------------------
nnoremap <C-j> <C-W>w
nnoremap <C-j> <C-W>w
" tab navigation like firefox
map tn :tabnext<CR>
map tp :tabprevious<CR>
map <C-t> :tabnew<CR>
highlight SpellBad term=underline gui=underline guisp=Blue
highlight Error term=underline gui=underline guibg=#00ff00
"------------------------------------------------------------
" Window split
"------------------------------------------------------------
" Make splits equal size
noremap <silent> <F12> :wincmd =<CR>
autocmd VimResized * wincmd =
" ----------------------------------------------
" Autocorect
" ----------------------------------------------
ab teh the
ab sefl self
ab equivelant equivalent
" ----------------------------------------------
" Tabularize
" ----------------------------------------------
let g:haskell_tabular = 1
vmap a= :Tabularize /=<CR>
vmap a; :Tabularize /::<CR>
vmap a, :Tabularize /,<CR>
vmap a- :Tabularize /-><CR>
" ----------------------------------------------
" Git Version Traversal
" ----------------------------------------------
map gd :Gdiff<CR>
map gb :Gblame<CR>
" Git checkout at block level
vmap do :diffget<CR>
map gd :Gdiff<CR>
" ----------------------------------------------
" Fast Navigation
" ----------------------------------------------
" Go to last edited line one keystroke
map ` g;
map gl <C-^>
" ----------------------------------------------
" Searching
" ----------------------------------------------
set incsearch
map ff /\c
if &t_Co > 2 || has("gui_running")
set hlsearch "Highlight all search matches if color is
endif "possible (:noh to toggle off)
nnoremap <silent> <return> :noh<return>
" ----------------------------------------------
" Inactive Buffers
" ----------------------------------------------
function! Wipeout()
" list of *all* buffer numbers
let l:buffers = range(1, bufnr('$'))
" what tab page are we in?
let l:currentTab = tabpagenr()
try
" go through all tab pages
let l:tab = 0
while l:tab < tabpagenr('$')
let l:tab += 1
" go through all windows
let l:win = 0
while l:win < winnr('$')
let l:win += 1
" whatever buffer is in this window in this tab, remove it from
" l:buffers list
let l:thisbuf = winbufnr(l:win)
call remove(l:buffers, index(l:buffers, l:thisbuf))
endwhile
endwhile
" if there are any buffers left, delete them
if len(l:buffers)
execute 'bwipeout' join(l:buffers)
endif
finally
" go back to our original tab page
execute 'tabnext' l:currentTab
endtry
endfunction
" ----------------------------------------------
" Writing Mode
" ----------------------------------------------
autocmd BufNewFile,BufRead *.rst,*.txt,*.tex,*.latex,*.md setlocal spell
autocmd BufNewFile,BufRead *.rst,*.txt,*.tex,*.latex,*.md setlocal nonumber
" ----------------------------------------------
" Clipboard
" ----------------------------------------------
set clipboard+=unnamedplus
set showmode
set shellslash
set showmatch
" ----------------------------------------------
" Rust
" ----------------------------------------------
"
" Set completeopt to have a better completion experience
" :help completeopt
" menuone: popup even when there's only one match
" noinsert: Do not insert text until a selection is made
" noselect: Do not select, force user to select one from the menu
set completeopt=menuone,noinsert,noselect
" Avoid showing extra messages when using completion
set shortmess+=c
" Configure LSP
" https://github.com/neovim/nvim-lspconfig#rust_analyzer
lua <<EOF
-- nvim_lsp object
local nvim_lsp = require'lspconfig'
-- function to attach completion when setting up lsp
local on_attach = function(client)
require'completion'.on_attach(client)
end
-- Enable rust_analyzer
nvim_lsp.rust_analyzer.setup({ on_attach=on_attach })
-- Enable diagnostics
vim.lsp.handlers["texDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = true,
signs = true,
update_in_insert = true,
}
)
EOF
" Use <Tab> and <S-Tab> to navigate through popup menu
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
" use <Tab> as trigger keys
imap <Tab> <Plug>(completion_smart_tab)
imap <S-Tab> <Plug>(completion_smart_s_tab)
" Code navigation shortcuts
nnoremap <silent> <c-]> <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> gD <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> <c-k> <cmd>lua vim.lsp.buf.signature_help()<CR>
nnoremap <silent> 1gD <cmd>lua vim.lsp.buf.type_definition()<CR>
nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> g0 <cmd>lua vim.lsp.buf.document_symbol()<CR>
nnoremap <silent> gW <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
nnoremap <silent> gd <cmd>lua vim.lsp.buf.declaration()<CR>
nnoremap <silent> ga <cmd>lua vim.lsp.buf.code_action()<CR>
" Set updatetime for CursorHold
" 300ms of no cursor movement to trigger CursorHold
set updatetime=300
" Show diagnostic popup on cursor hold
autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics()
" Goto previous/next diagnostic warning/error
nnoremap <silent> g[ <cmd>lua vim.lsp.diagnostic.goto_prev()<CR>
nnoremap <silent> g] <cmd>lua vim.lsp.diagnostic.goto_next()<CR>
" Enable type inlay hints
autocmd CursorMoved,InsertLeave,BufEnter,BufWinEnter,TabEnter,BufWritePost *
\ lua require'lsp_extensions'.inlay_hints{ prefix = '', highlight = "Comment", enabled = {"TypeHint", "ChainingHint", "ParameterHint"} }