summaryrefslogtreecommitdiff
path: root/vim/.vimrc
blob: f58f6eed7152db5f6163674b83f47b42187f778e (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
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
"" 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 'LnL7/vim-nix'
Plug 'PotatoesMaster/i3-vim-syntax'
Plug 'SirVer/ultisnips'
Plug 'airblade/vim-gitgutter'
Plug 'AndrewRadev/splitjoin.vim'
Plug 'beloglazov/vim-online-thesaurus'
Plug 'easymotion/vim-easymotion'
Plug 'holomorph/vim-freefem'
Plug 'honza/vim-snippets'
Plug 'inkarkat/vim-SpellCheck'
Plug 'inkarkat/vim-ingo-library'
Plug 'jamessan/vim-gnupg'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'junegunn/goyo.vim'
Plug 'junegunn/gv.vim'
Plug 'junegunn/heytmux'
Plug 'junegunn/vim-easy-align'
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 'majutsushi/tagbar'
Plug 'neomake/neomake'
Plug 'scrooloose/nerdtree'
Plug 'sjl/Gundo.vim', { 'on' : 'GundoToggle' }
Plug 'terryma/vim-multiple-cursors'
Plug 'tommcdo/vim-exchange'
Plug 'tommcdo/vim-ninja-feet'
Plug 'ton/vim-bufsurf'
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-surround'
Plug 'tpope/vim-unimpaired'
Plug 'troydm/zoomwintab.vim'
let g:zoomwintab_hidetabbar=0
Plug 'vim-scripts/ReplaceWithRegister'
Plug 'vim-scripts/gmsh.vim'
Plug 'wellle/targets.vim'
" Plug 'zchee/deoplete-clang'

Plug 'liuchengxu/vim-which-key'

if isdirectory($HOME."/dotfiles/plugins")
    Plug '~/dotfiles/plugins/vim-remembrall'
    Plug '~/dotfiles/plugins/vim-tmux-pilot'
    Plug '~/dotfiles/plugins/darjeeling'
endif

if has("nvim")
    " Plug 'roxma/nvim-completion-manager'
    " Plug 'Shougo/deoplete.nvim', { 'do' : ':UpdateRemotePlugins', 'tag' : '4.1' }
    " Plug 'autozimu/LanguageClient-neovim', { 'do': 'bash install.sh', 'branch': 'next' }
    " Plug 'zchee/deoplete-jedi'
    " Plug 'hkupty/iron.nvim', { 'branch': 'legacy' }
    Plug 'hkupty/iron.nvim'
    Plug 'neovim/nvim-lsp'
else
    Plug 'Shougo/neocomplete.vim'
endif

" Colors
Plug 'KKPMW/sacredforest-vim'
Plug 'altercation/vim-colors-solarized'
Plug 'arcticicestudio/nord-vim'
Plug 'KKPMW/moonshine-vim'
Plug 'KKPMW/sacredforest-vim'
Plug 'junegunn/seoul256.vim'
Plug 'romainl/Apprentice'
Plug 'joshdick/onedark.vim'
" Plug 'josuegaleas/jay'

" Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()

"" Plugin configuration {{{1

" Toggles
nnoremap cpg :GitGutterToggle<cr>
nnoremap cpn :NERDTreeToggle<cr>
nnoremap cpt :TagbarToggle<cr>
nnoremap cpu :GundoToggle<cr>
nnoremap <expr> cp Remembrall('cp')

" Easy motion
map gs <Plug>(easymotion-prefix)

" Fuzzy finder
nnoremap <c-p>a  :Ag
nnoremap <c-p>b  :Buffers<cr>
nnoremap <c-p>C  :Colors<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 <c-p>a  :Ag

nnoremap <a-b>  :Buffers<cr>
nnoremap <a-f>  :Files<cr>
nnoremap <a-g>  :GitFiles<cr>

" Fugitive
nnoremap <Leader>gs :Gstatus<cr>
nnoremap <Leader>gc :Gcommit<cr>
nnoremap <Leader>gr :Gread<cr>
nnoremap <Leader>gd :Gdiff<cr>

" Heytmux
function! Call_heytmux(vm)
    call feedkeys(":'[,']Heytmux!
")
endfunction

nnoremap <silent> gh :set opfunc=Call_heytmux<cr>g@
xnoremap <silent> gh :Heytmux!<cr>

" Iron
if has("nvim")
    let g:iron_map_defaults=0
    let g:iron_map_extended=0
    nnoremap cpr :IronRepl<cr>
    nmap yr <Plug>(iron-send-motion)
    xmap R <Plug>(iron-send-motion)
    nmap yrr VR

lua << EOF
local iron = require("iron")

local open_repl = function(buffer)
  vim.api.nvim_command('vnew')
end

iron.core.set_config{
    preferred = {
        python = "ipython"
    },
    repl_open_cmd = open_repl
}
EOF
" let g:iron_repl_open_cmd = 'vsplit'
endif

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

" Online thesaurus
nnoremap cpd :OnlineThesaurusCurrentWord<cr>

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

" Remembrall
if &runtimepath =~ 'remembrall'
    let g:remembrall_auto_accept = 0
    nnoremap <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 = [""]

" LanguageClient
if executable('pyls')
    let g:LanguageClient_serverCommands = { 'python': ['pyls'], }
endif

let g:LanguageClient_diagnosticsEnable = 0
nnoremap <silent> <leader>lh :call LanguageClient#textDocument_hover()<CR>
nnoremap <silent> <leader>ld :call LanguageClient#textDocument_definition()<CR>
nnoremap <silent> <leader>lr :call LanguageClient#textDocument_rename()<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']

" Deoplete
let g:deoplete#enable_at_startup = 1
let g:deoplete#sources#jedi#show_docstring = 1
if !exists('g:deoplete#omni#input_patterns')
    let g:deoplete#omni#input_patterns = {}
endif

if &runtimepath =~ 'vimtex'
    let g:deoplete#omni#input_patterns.tex = g:vimtex#re#deoplete
endif

" FZF.vim
let g:fzf_buffers_jump = 1

" Gundo
let g:gundo_prefer_python3 = 1

" Localvimrc
let g:localvimrc_sandbox = 0
let g:localvimrc_whitelist='/home/*'

" NerdTree
let g:NERDTreeHijackNetrw = 0

" Ultisnips
let g:UltiSnipsEditSplit="horizontal"
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsListSnippets="<c-l>"
let g:UltiSnipsSnippetDirectories=['UltiSnips', 'mySnippets']
let g:UltiSnipsSnippetsDir="~/.vim/mySnippets"
" let g:UltiSnipsUsePythonVersion=3

" Vimtex
let g:vimtex_fold_enabled=1  " Makes %s slow!
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_fold_types = {
"        \ 'preamble' : {'enabled' : 0},
"        \ 'envs' : {
"        \   'blacklist' : ['lemma', 'proposition', 'theorem', 'equation'],
"        \   'whitelist' : ['proof'],
"        \ },
"        \}

" 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-\>'

" YouCompleteMe
let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']
let g:ycm_add_preview_to_completeopt = 0
let g:ycm_confirm_extra_conf = 0
let g:ycm_auto_trigger = 1
if !exists('g:ycm_semantic_triggers')
    let g:ycm_semantic_triggers = {}
    let g:ycm_semantic_triggers.tex = ['re!\\[A-Za-z]*(ref|cite)[A-Za-z]*([^]]*])?{([^}]*, ?)*' ]
endif

" Plugins interactions
function! Multiple_cursors_before()
    if has("nvim") && &runtimepath =~ 'deoplete'
        let b:deoplete_disable_auto_complete = 1
        call deoplete#disable()
    endif
endfunction

function! Multiple_cursors_after()
    if has("nvim") && &runtimepath =~ 'deoplete'
        let b:deoplete_disable_auto_complete = 0
        call deoplete#enable()
    endif
endfunction

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

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

set complete+=k
set conceallevel=2
set cursorline
set diffopt=filler,vertical,hiddenoff
set expandtab
set exrc
set foldmethod=marker
set hidden
set ignorecase
set lazyredraw
set laststatus=2
set mouse=a
set nojoinspaces
set nowrap
set path+=$PWD/**
set shiftwidth=4
set showcmd
set splitright
set smartcase
set smartindent
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"
if !has("nvim")
  set encoding=utf-8
endif
if has("nvim")
  set inccommand=split
endif

"" Mappings {{{1

" .rst headings
nnoremap <leader>1 m`yypVr=``
nnoremap <leader>2 m`yypVr-``

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 <nowait> <c-d> :q<cr>

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

nnoremap ,te :tabedit<space>
nnoremap ,tl :+tabmove<cr>
nnoremap ,th :-tabmove<cr>
nnoremap ,t0 :tabmove 0<cr>
nnoremap ,t$ :tabmove<cr>

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

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

nnoremap got :call system('urxvt -cd '.getcwd().' &')<cr>
nnoremap goT :call system('urxvt -cd '.expand("%:p:h").' &')<cr>
nnoremap gof :call system('urxvt -e vifm '.getcwd().' '.getcwd().' &')<cr>
nnoremap goF :call system('urxvt -e vifm '.expand("%:p:h").' '.expand("%:p:h").' &')<cr>

nnoremap <LocalLeader>h :e %:p:s,.hpp$,.X123X,:s,.cpp$,.hpp,:s,.X123X$,.cpp,<cr>
nnoremap Y y$

nnoremap <Leader>fw :%s/\s\+$//<cr>
nnoremap <Leader>ft :%s/^	\+//g<cr>

cnoremap <c-p> <up>
cnoremap <c-n> <down>
cnoremap <up> <c-p>
cnoremap <down> <c-n>

" Overwrite unimpaired mappings
nnoremap <silent> <b :BufSurfBack<cr>
nnoremap <silent> >b :BufSurfForward<cr>
nnoremap <silent> <B :BufSurfBack<cr>:bd! #<cr>
nnoremap <silent> >B :BufSurfForward<cr>:bd! #<cr>

" Alternate file
nnoremap <bs> 
nnoremap + :Buffers<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=

" Projectionist
nnoremap ,e :E

" Unimpaired
nmap co yo

"" Colorscheme {{{1
nnoremap ,c  :colorscheme<space>
nnoremap ,cl :set background=light<cr>:colorscheme solarized<cr>
nnoremap ,cl :set background=dark<cr>:colorscheme solarized<cr>
nnoremap ,cs :colorscheme seoul256<cr>
nnoremap ,cn :colorscheme nord<cr>
colo seoul256

"" 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 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

"" My search {{{1

" http://vim.wikia.com/wiki/Searching_for_files
function! MySearch(...)
    let l:prevgrepprg=&grepprg
    let l:prevgrepformat=&grepformat
    if a:1 == "Rg"
        set grepprg=rg\ -uu\ --vimgrep
        set grepformat=%f:%l:%c:%m
    elseif a:1 == "Gnufind"
        set grepprg=find\ .\ -name
        set grepformat=%f
    elseif a:1 == "Gitfind"
        set grepprg=git\ ls-files\ -i\ -x
        set grepformat=%f
    endif
    execute 'silent grep!' a:2 | cwindow | redraw!
    let &grepprg=l:prevgrepprg
    let &grepformat=l:prevgrepformat
endfun

command! -nargs=+ -complete=file_in_path Rg      call MySearch("Rg", <q-args>)
command! -nargs=+ -complete=file_in_path Gnufind call MySearch("Gnufind", <q-args>)
command! -nargs=+ -complete=file_in_path Gitfind call MySearch("Gitfind", <q-args>)
command! -nargs=+ -complete=file_in_path GitGrep execute 'silent Ggrep!' <q-args> | cw | redraw!
command! -nargs=+ -complete=file_in_path VimGrep execute 'silent vimgrep!' <q-args> | cw | redraw!

" Default search and find programs
function! FillSearch(...)
    if a:0 == 0
        let l:filltext = ""
    else
        let l:is_visual=(a:1 == "v")
        let l:line=getline(l:is_visual ? "'<" : "'[")
        let [line1,col1] = getpos(l:is_visual ? "'<" : "'[")[1:2]
        let [line2,col2] = getpos(l:is_visual ? "'>" : "']")[1:2]
        let l:filltext =l:line[col1 - 1: col2 - 1]
    endif
    call feedkeys(':' . g:my_fillprg . ' "' . l:filltext . '"'."\<Left>")
endfunction

let g:my_searchprgs = ['Rg', 'GitGrep', 'VimGrep']
let g:my_findprgs = ['Gnufind', 'Gitfind']
let g:my_searchprg = 0
let g:my_findprg = 0

nnoremap <silent> g/  :let g:my_fillprg=g:my_searchprgs[g:my_searchprg]<cr>:set opfunc=FillSearch<cr>g@
nnoremap <silent> ,g  :let g:my_fillprg=g:my_searchprgs[g:my_searchprg]<cr>:call FillSearch()<cr>
xnoremap <silent> ,g  :<c-u>let g:my_fillprg=g:my_searchprgs[g:my_searchprg]<cr>:call FillSearch(visualmode())<cr>
nnoremap <silent> ,f  :let g:my_fillprg=g:my_findprgs[g:my_findprg]<cr>:call FillSearch()<cr>

" Cycle search / find prgs
nnoremap <silent> cog :let g:my_searchprg=(g:my_searchprg+1)%len(g:my_searchprgs)<cr>:let &ro = &ro<cr>
nnoremap <silent> cof :let g:my_findprg=(g:my_findprg+1)%len(g:my_findprgs)<cr>:let &ro = &ro<cr>

"" Status line {{{1
function! Mixed_indent()
    let l:spaces=search('\v(^ +)','n')
    let l:tabs=search('\v(^\t+)','n')
    return (l:spaces * l:tabs > 0)
endfunction

function! GlobalCwd()
    return getcwd(-1, -1)
endfunction

function! TabCwd(number)
    if haslocaldir(-1, a:number)
        return getcwd(-1, a:number)
    endif
    return ""
endfunction

function! WinCwd()
    if haslocaldir(0)
        return getcwd()
    endif
    return ""
endfunction

set showtabline=2
let g:tabprefix = ""
let g:tablabel = "%N%{flagship#tabmodified()} %{TabCwd(v:lnum) != '' ? pathshorten(TabCwd(v:lnum)) : ''}"
let g:flagship_skip = 'FugitiveStatusline'

augroup myflags
    autocmd!
    autocmd CmdwinEnter,BufEnter,BufRead,BufWritePost * let b:trailing=search('\s\+$','n')
    autocmd CmdwinEnter,BufEnter,BufRead,BufWritePost * let b:mixed=Mixed_indent()
    autocmd User Flags call Hoist("buffer", "%{FugitiveHead('') != '' ? '['.FugitiveHead('').']' : ''}")
    autocmd User Flags call Hoist("buffer", "%{b:trailing?'[tw]':''}")
    autocmd User Flags call Hoist("buffer", "%{b:mixed?'[mixed]':''}")
    autocmd User Flags call Hoist("buffer", "%{&paste?'[paste]':''}")
    autocmd User Flags call Hoist("window", "%{WinCwd() != '' ? '['.WinCwd().']' : ''}")

    highlight MyGlobals ctermfg=255 ctermbg=240
    autocmd User Flags call Hoist("global", {"hl": "MyGlobals"}, "[%{pathshorten(GlobalCwd())}, %{g:my_searchprgs[g:my_searchprg]}, %{g:my_findprgs[g:my_findprg]}]")
augroup END

"" 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

"" Experimental {{{1
set wildcharm=<C-z>
nnoremap ,e :e **/*<C-z><S-Tab>

let $FZF_DEFAULT_OPTS='--layout=reverse'
let g:fzf_layout = { 'window': 'call FloatingFZF()' }

hi Pmenu ctermfg=3 ctermbg=239
function! FloatingFZF()
  let buf = nvim_create_buf(v:false, v:true)
  call setbufvar(buf, '&laststatus', '1')

  let height = &lines - 10
  let width = float2nr(&columns - (&columns * 2 / 10))
  let col = float2nr((&columns - width) / 2)

  let opts = {
        \ 'relative': 'editor',
        \ 'row': 5,
        \ 'col': col,
        \ 'width': width,
        \ 'height': height
        \ }

  call nvim_open_win(buf, v:true, opts)
  call setbufvar(buf, '&laststatus', '2')
endfunction

" highlight default link LspDiagnosticsError Delimiter
" highlight default link LspDiagnosticsWarning Delimiter
" lua << EOF
" require'nvim_lsp'.pyls.setup{}
" EOF

" Default Values:
"   cmd = { "pyls" }
"   filetypes = { "python" }
"   log_level = 2
"   root_dir = vim's starting directory
"   settings = {}

" if !exists('g:lsp_config_sourced')
"     call lsp#add_filetype_config({
"           \ 'filetype': 'python',
"           \ 'name': 'pyls',
"           \ 'cmd': 'pyls',
"           \ 'callbacks': {}
"           \ })
"     autocmd Filetype python setl omnifunc=lsp#omnifunc
"     let g:lsp_config_sourced = 1
" endif

" lua <<EOF
" vim.lsp.start_client({"pyls"})
" EOF
" nvim_lsp = require('nvim_lsp')
" print(nvim_lsp.skeleton)

autocmd Filetype python setl omnifunc=v:lua.vim.lsp.omnifunc
nnoremap <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>

" inoremap <c-g><esc>:call remembrall#remind('i', '<c-g>')<cr>
" nnoremap <expr> <c-g> Remembrall('<c-g>')
" nnoremap <c-g>h <esc>:call lsp#text_document_hover()<cr>
" nnoremap <c-g>a <esc>:call lsp#text_document_declaration()<cr>
" nnoremap <c-g>d <esc>:call lsp#text_document_definition()<cr>
" nnoremap <c-g>i <esc>:call lsp#text_document_implementation()<cr>
" nnoremap <c-g>s <esc>:call lsp#text_document_signature_help()<cr>
" nnoremap <c-g>t <esc>:call lsp#text_document_type_definition()<cr>