summaryrefslogtreecommitdiff
path: root/vim/.vimrc
blob: 91ef1ab9929f82ccb1534a05911dcd5d0bb1247e (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
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
"" Download vim-plug if necessary {{{1
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

"" Leader and Localleader {{{1
let mapleader = " "
let maplocalleader = ","

"" Plugins {{{1
call plug#begin('~/.vim/plugged')
Plug 'andymass/vim-matchup'
Plug 'PotatoesMaster/i3-vim-syntax'
Plug 'SirVer/ultisnips'
Plug 'airblade/vim-gitgutter'
Plug 'AndrewRadev/splitjoin.vim'
Plug 'honza/vim-snippets'
Plug 'jamessan/vim-gnupg', { 'branch': 'main' }
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'junegunn/gv.vim'
Plug 'junegunn/heytmux'
Plug 'junegunn/vim-easy-align'
Plug 'junegunn/vim-emoji'
Plug 'junegunn/vim-peekaboo'
Plug 'junegunn/vim-slash'
Plug 'justinmk/vim-dirvish'
Plug 'justinmk/vim-sneak'
Plug 'kshenoy/vim-signature'
Plug 'lervag/vimtex'
Plug 'machakann/vim-highlightedyank'
Plug 'mg979/vim-visual-multi'
Plug 'neomake/neomake'
Plug 'sjl/Gundo.vim', { 'on' : 'GundoToggle' }
Plug 'tommcdo/vim-exchange'
Plug 'tommcdo/vim-ninja-feet'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-apathy'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-eunuch'
Plug 'tpope/vim-flagship'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-obsession'
Plug 'tpope/vim-projectionist'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-rsi'
Plug 'tpope/vim-scriptease'
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-speeddating'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
Plug 'troydm/zoomwintab.vim'
Plug 'vim-scripts/ReplaceWithRegister'
Plug 'vim-scripts/gmsh.vim'
Plug 'wellle/targets.vim'
if isdirectory($HOME."/dotfiles/plugins")
    Plug '~/dotfiles/plugins/vim-remembrall'
    Plug '~/dotfiles/plugins/vim-tmux-pilot'
    Plug '~/dotfiles/plugins/vim-ripple'
    Plug '~/dotfiles/plugins/vim-darjeeling'
    Plug '~/dotfiles/plugins/vim-macaw'
endif

if has("nvim") && hostname() != "peuplier"
    Plug '~/dotfiles/plugins/nvim-i3scratchpad'
    Plug 'neovim/nvim-lspconfig'
    " Plug 'nvim-treesitter/nvim-treesitter'
    " Plug 'hrsh7th/nvim-cmp', { 'branch': 'main' }
    " Plug 'nvim-treesitter/playground'
endif

" Colors
Plug 'sonph/onehalf', { 'rtp': 'vim' }
Plug 'lifepillar/vim-solarized8'
Plug 'junegunn/seoul256.vim'
Plug 'romainl/Apprentice'
Plug 'JuliaEditorSupport/julia-vim'
Plug 'arcticicestudio/nord-vim'
" Plug 'axvr/zepl.vim'
call plug#end()

"" Plugin configuration {{{1

" Toggles
nnoremap cpg :GitGutterToggle<cr>
nnoremap cpu :GundoToggle<cr>

" Fuzzy finder
nnoremap <c-p>b :Buffers<cr>
nnoremap <c-p>f :Files<cr>
nnoremap <c-p>g :GitFiles<cr>
nnoremap <c-p>r :History<cr>
nnoremap <c-p>: :History:<cr>
nnoremap <c-p>/ :History/<cr>
nnoremap <c-p>l :BLines<cr>
nnoremap <a-b> :Buffers<cr>
nnoremap <a-f> :Files<cr>
nnoremap <a-g> :GitFiles<cr>

" Fugitive
nnoremap <Leader>gs :Git<cr>
nnoremap <Leader>gc :Git commit<cr>
nnoremap <Leader>gr :Gread<cr>
nnoremap <Leader>gd :Gdiff<cr>

" Multiple cursors
let g:VM_maps = {}
let g:VM_maps["Select Cursor Down"] = "<M-j>"
let g:VM_maps["Select Cursor Up"] = "<M-k>"

" Heytmux
function! Call_heytmux(vm)
    call feedkeys(":'[,']Heytmux!
")
endfunction
nnoremap <silent> gh :set opfunc=Call_heytmux<cr>g@
xnoremap <silent> gh :Heytmux!<cr>

" Easy align
xmap ga <Plug>(EasyAlign)
nmap ga <Plug>(EasyAlign)
xmap gl <Plug>(LiveEasyAlign)
nmap gl <Plug>(LiveEasyAlign)

" Plug
nnoremap ,pi :PlugInstall<cr>
nnoremap ,pu :PlugUpdate<cr>
nnoremap ,pc :PlugClean<cr>

" Remembrall
if &runtimepath =~ 'remembrall'
    let g:remembrall_auto_accept = 1
    nnoremap <silent> <buffer> <nowait> <expr> ,p Remembrall(',p')
    nnoremap <silent> <expr> ,, Remembrall('')
    augroup remembrall
        autocmd FileType tex nnoremap <buffer> <silent> <expr> ,l Remembrall(',l')
    augroup END
endif
let g:remembrall_suffixes = []
let g:ripple_winpos = "vertical"
let g:ripple_term_name = "term: ripple"
nmap ,w <Plug>(ripple_send_motion)iw:Ripple <c-v><cr><cr>
nmap ,<cr> :Ripple <c-v><cr><cr>

" Ultisnips
nnoremap cps :UltiSnipsEdit<cr>

" Neomake
nnoremap gm :Make<cr>
nnoremap gM :Neomake!<cr>
if &runtimepath =~ 'neomake'
    call neomake#configure#automake('w')
endif

let g:neomake_gcc_args=[
            \ '-Wall',
            \ '-Wextra',
            \ '-Wpedantic',
            \ '-I.', '-I..', '-I../..'
            \ ]

let g:neomake_python_enabled_makers = ['python', 'pylint']
 let g:neomake_error_sign = {
     \ 'text': '🍁',
     \ 'texthl': 'NeomakeErrorSign',
     \ }
 let g:neomake_warning_sign = {
     \   'text': '💦',
     \   'texthl': 'NeomakeWarningSign',
     \ }

" FZF.vim
let $FZF_DEFAULT_OPTS='--layout=reverse'
let g:fzf_buffers_jump = 1
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }

" Gundo
let g:gundo_prefer_python3 = 1

" Ultisnips
let g:UltiSnipsEditSplit="horizontal"
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsListSnippets="<c-l>"

" Vimtex
let g:vimtex_fold_manual=1
let g:vimtex_fold_enabled=1
let g:vimtex_fold_bib_enabled=1
let g:vimtex_view_method='zathura'
let g:vimtex_quickfix_mode=2
let g:vimtex_compiler_progname='nvr'
let g:vimtex_syntax_enabled=1
let g:vimtex_toc_config={
            \ 'layer_status': {
                \ 'content': 1,
                \ 'label': 0,
                \ 'todo': 1,
                \ 'include': 1 },
            \ 'show_help': 0}

let g:vimtex_delim_toggle_mod_list = [
  \ ['\left', '\right'],
  \ ['\bigl', '\bigr'],
  \ ['\Bigl', '\Bigr'],
  \ ['\biggl', '\biggr'],
  \ ['\Biggl', '\Biggr'],
  \]

nmap <c-c> m`gcc<esc>``

" Pilot
let g:pilot_boundary='ignore'
let g:pilot_mode='wintab'
" let g:pilot_split_or_new='new'
" let g:pilot_key_h='<a-h>'
" let g:pilot_key_j='<a-j>'
" let g:pilot_key_k='<a-k>'
" let g:pilot_key_l='<a-l>'
" let g:pilot_key_p='<a-\>'

"" Vim variables {{{1
let g:netrw_bufsettings='relativenumber'

" Latex configuration
let g:tex_conceal= ''
let g:tex_flavor='latex'

augroup latex
    autocmd!
    autocmd FileType tex let b:surround_124 = "\\lvert \r \\rvert"
    autocmd FileType tex let b:surround_110 = "\\lVert \r \\rVert"
    autocmd FileType tex let b:surround_101 = "\\begin{\1environment: \1}\r\\end{\1\1}"
    autocmd FileType tex let b:surround_99 = "\\\1command\1{\r}"
augroup END

"" Vim options {{{1
set backup
set undofile
set backupdir^=~/.vim/backup//
set directory^=~/.vim/swap//
" ^= : prepends to list
" // : store absolute path

" set complete+=k
set conceallevel=0
set cursorline
set diffopt=filler,vertical,hiddenoff
set expandtab
set exrc
set foldmethod=marker
set hidden
set ignorecase
set lazyredraw
set laststatus=2
set listchars+=eol:$
set wildcharm=<C-z>
set mouse=a
set equalalways
set nojoinspaces
set nowrap
set path+=$PWD/**
set shiftwidth=4
set showcmd
set splitright
set smartcase
set nosmartindent
set softtabstop=-1 " set sotftabstop=&shiftwidth
" set formatoptions+=orw
silent! set breakindent
let &showbreak='--> '
set clipboard^=unnamedplus,unnamed
" set spellfile="$HOME/.vim/spell/en.utf-8.add"
set spelllang=fr,en
if !has("nvim")
  set encoding=utf-8
endif
if has("nvim")
  set inccommand=split
endif

"" Mappings {{{1
nnoremap <leader>1 m`yypVr=``
nnoremap <leader>2 m`yypVr-``

nnoremap <leader>m :.m

nnoremap n nzz
nnoremap N Nzz

nnoremap <silent> <Plug>AddWhiteSpaceAfter a <Esc>h:silent call repeat#set("\<Plug>AddWhiteSpaceAfter")<cr>
nnoremap <silent> <Plug>AddWhiteSpaceBefore i <Esc>l:silent call repeat#set("\<Plug>AddWhiteSpaceBefore")<cr>
nmap ]w <Plug>AddWhiteSpaceAfter
nmap [w <Plug>AddWhiteSpaceBefore

nnoremap <Leader>w :update<cr>
nnoremap <Leader>q :q<cr>
nnoremap <Leader>d :bd!<cr>
nnoremap <c-d> :q<cr>

nnoremap ,bd :ls<cr>:bd<space>

nnoremap gl :+tabmove<cr>
nnoremap gh :-tabmove<cr>

" Delete cache
nnoremap <Leader>c :call delete($HOME."/.vim/swap/".substitute(expand('%:p'), '/', '%', 'g').".swp")<cr>

" Dispatch
nnoremap <Leader>r :Start %:p<cr>
nnoremap <Leader>R :Start! %:p<cr>

" Quickfix
nnoremap cqo :copen<cr>
nnoremap cqh :colder<cr>
nnoremap cqc :cclose<cr>

" Terminal and file manager
nnoremap goT :call system('alacritty --working-directory '.shellescape(getcwd()).' &')<cr>
nnoremap got :call system('alacritty --working-directory '.shellescape(expand("%:p:h")).' &')<cr>
nnoremap goF :call system('alacritty -e vifm '.shellescape(getcwd()).' '.shellescape(getcwd()).' &')<cr>
nnoremap gof :call system('alacritty -e vifm '.shellescape(expand("%:p:h")).' '.shellescape(expand("%:p:h")).' &')<cr>

" Header files
nnoremap \h :e %:p:s,.hpp$,.X123X,:s,.cpp$,.hpp,:s,.X123X$,.cpp,<cr>

" Make Y behave like C, D
nnoremap Y y$

" Formatting
nnoremap <Leader>fw m`:silent! keeppattern %s/\s\+$//<cr>``:update<cr>
nnoremap <Leader>ft m`:silent! keeppattern %s/    /    /g<cr>``:update<cr>
nmap <Leader>ff <Leader>fw<Leader>ft

" Swap <c-p>/<c-n> and <up>/<down>
cnoremap <c-p> <up>
cnoremap <c-n> <down>
cnoremap <up> <c-p>
cnoremap <down> <c-n>

" Alternate file
no remap <bs> 

" Buffers
nnoremap + :Buffers<cr>

" Align
nnoremap yA vip:EasyAlign * <bar><cr>:w<cr>

" Source current file
nnoremap ,s :source %<cr>

" Shebang
inoreabbrev <expr> #!! "#!/usr/bin/env" . (empty(&filetype) ? '' : ' '.&filetype)

" Spell
inoremap <nowait> <c-g> <esc>h1z=ea
nnoremap <Leader>s 1z=

" fzf
nnoremap <Tab> :GitFiles<cr>

" Projectionist
nnoremap ,e :E

" Unimpaired
nmap co yo

"" Autocommands {{{1
augroup vimrc
    autocmd!
    autocmd BufWritePost *vimrc,*exrc :call feedkeys(":source %\<cr>")
    autocmd BufNewFile,Bufread /tmp/mutt-* setlocal tw=72
    autocmd BufWritePre *
        \ if !isdirectory(expand('<afile>:p:h')) |
        \   call mkdir(expand('<afile>:p:h'), 'p') |
        \ endif

    " Detect filetypes (! 'setf freefem' does not override...)
    autocmd BufNewFile,BufRead *.geo,*.msh set filetype=gmsh
    autocmd BufNewFile,BufRead *.pde set filetype=freefem
    autocmd BufNewFile,BufRead *.plt set filetype=gnuplot

    " Filetype specific
    autocmd FileType cmake setlocal commentstring=#%s
    autocmd FileType cpp setlocal commentstring=//%s
    autocmd FileType freefem comp freefem
    autocmd FileType gmsh setlocal makeprg=gmsh\ %
    autocmd FileType gnuplot setlocal commentstring=#%s
    autocmd FileType gnuplot setlocal makeprg=gnuplot\ %
    autocmd FileType python setlocal makeprg=python\ %
    autocmd FileType julia setlocal makeprg=julia\ %
    autocmd FileType tex setlocal spell spelllang=en_us

    " Dirvish
    autocmd FileType dirvish nnoremap <buffer> t :!touch %
    autocmd FileType dirvish setlocal errorformat=%f
    autocmd FileType dirvish setlocal relativenumber
    autocmd FileType dirvish silent! unmap <buffer> <C-p>
augroup END

"" Colorscheme {{{1
nnoremap ,cd  :colorscheme darjeeling<cr>
nnoremap ,cs :colorscheme seoul256<cr>

set notermguicolors
colo darjeeling

" set termguicolors
" colo nord
" highlight Comment ctermfg=66 guifg=#5f8787
" highlight SignColumn ctermbg=234 ctermfg=232 guibg=#1c1c1c guifg=#080808



" set notermguicolors
" colo darjeeling

"" Neovim {{{1
if has("nvim")
    nnoremap goh :let @a=getcwd() \| lcd %:h \| terminal<cr>:execute 'lcd '.@a<cr>A
    tnoremap <c-x> <c-\><c-n><c-^>:bd! #<cr>
    nnoremap <c-_> :b # \| norm A<cr>
    tnoremap <c-_> <c-\><c-n><c-^>
    nnoremap <Leader>t :b term \| norm A<cr>
endif

if has("nvim") && &runtimepath =~ 'treesitter'
lua <<EOF
require'nvim-treesitter.configs'.setup {
highlight = { enable = true },
incremental_selection = { enable = true },
textobjects = { enable = true },
}
EOF
endif

"" Experimental {{{1
if has("nvim") && hostname() != "peuplier"
try
    " lua require('lspconfig').pyls.setup{}
    lua require('lspconfig').julials.setup{}
    " autocmd Filetype python setlocal omnifunc=v:lua.vim.lsp.omnifunc
    autocmd Filetype julia setlocal omnifunc=v:lua.vim.lsp.omnifunc
    nnoremap <silent> <expr> <c-g> Remembrall('<c-g>')
    nnoremap <silent> <c-g>h <cmd>lua vim.lsp.buf.hover()<cr>
    nnoremap <silent> <c-g>a <cmd>lua vim.lsp.buf.declaration()<cr>
    nnoremap <silent> <c-g>d <cmd>lua vim.lsp.buf.definition()<cr>
    nnoremap <silent> <c-g>i <cmd>lua vim.lsp.buf.implementation()<cr>
    nnoremap <silent> <c-g>s <cmd>lua vim.lsp.buf.signature_help()<cr>
    nnoremap <silent> <c-g>t <cmd>lua vim.lsp.buf.type_definition()<cr>
    nnoremap <silent> <c-g><c-g> <cmd>lua vim.lsp.stop_client(vim.lsp.get_active_clients())<cr>
catch
    echom "Error with LPS configuration"
endtry
endif

let g:matchup_override_vimtex = 1

" Tests {{{1
let g:ripple_repls = {
            \ "python": {
                \ "command": "ipython",
                \ "pre": "\<esc>[200~",
                \ "post": "\<esc>[201~",
                \ "addcr": 1,
                \ "filter": function('ripple#remove_leading_whitespaces'),
                \ },
            \ "r": "radian"
            \ }

" Vim sensible fix
inoremap <c-w> <c-w>

" For latex snippet
function! Get_surrounding()
    let dict = { 'equation': 'eq', 'align': 'eq'}
    let env = vimtex#env#get_surrounding("normal")[0]['name']
    if has_key(dict, env)
        return dict[env]
    else
        return env
    endif
endfunction

" vim: nospell