]> Git — Sourcephile - julm/julm-nix.git/blob - homes/softwares/vim/init.vim
replace unmaintained youtube-dl by yt-dlp
[julm/julm-nix.git] / homes / softwares / vim / init.vim
1 " vim: ft=vim
2 "if has("nvim")
3 " autocmd! BufWritePost,BufEnter * Neomake
4 "endif
5 if has("nvim")
6 let EDITOR="nvim"
7 else
8 let EDITOR="vim"
9 end
10
11 hi Comment ctermfg=black ctermbg=NONE cterm=bold
12 "hi Comment ctermfg=darkgray cterm=bold
13 hi Conceal ctermfg=black ctermbg=NONE cterm=bold
14 hi CursorLine cterm=none guibg=NONE
15 hi CursorLineNr ctermfg=white cterm=NONE
16 hi FoldColumn ctermfg=black ctermbg=none cterm=bold
17 hi Folded ctermfg=black ctermbg=NONE cterm=bold
18 hi LineNr ctermfg=black ctermbg=none cterm=bold
19 hi Pmenu ctermbg=magenta ctermfg=black
20 hi PmenuSel ctermbg=darkmagenta ctermfg=black
21 hi PmenuSbar ctermfg=gray ctermbg=black
22 hi PmenuThumb ctermfg=white
23 hi Search ctermfg=black ctermbg=yellow
24 hi SignColumn ctermbg=black
25 hi SpecialKey ctermfg=black cterm=bold
26 hi StatusLine term=bold,reverse ctermfg=white ctermbg=blue cterm=none
27 hi StatusLineNC term=reverse ctermfg=blue ctermbg=none cterm=underline
28 hi Visual ctermfg=black ctermbg=yellow cterm=none
29 hi WarningMsg ctermbg=darkyellow ctermfg=white
30 au FileType xml hi xmlAttrib ctermfg=green
31 au FileType xslt hi xmlNamespace ctermfg=red
32 au FileType xslt hi xmlAttrib ctermfg=green
33 au FileType * hi Special ctermfg=red
34 "au FileType haskell hi Comment ctermfg=DarkGreen
35 au FileType haskell hi Identifier ctermfg=LightGray
36
37 " Search term under cursor
38 nmap <silent> * :set hls<CR>:let @/="\\<<C-r><C-w>\\>"<CR>/<BS>
39 nmap <silent> <C-n> :set hls<CR>:call Vimgrepbuffers('\<' . expand('<cword>') . '\>')<CR>
40 " Search subterm under cursor
41 nmap <silent> µ :set hls<CR>:let @/="<C-r><C-w>"<CR>/<BS>
42 nmap <silent> <C-m> :set hls<CR>:call Vimgrepbuffers(expand('<cword>'))<CR>
43
44 fun! Vimgrepbuffers(pattern)
45 exe 'vimgrep /' . a:pattern . '/g ' . getbufinfo({'buflisted': 1})->map({_,b -> fnameescape(b.name)})->join(' ')
46 let @/ = a:pattern
47 let l:winnr = winnr()
48 cwindow 3
49 " If focus changed, restore it (jump to the last window).
50 if l:winnr isnot# winnr()
51 wincmd p
52 endif
53 endfun
54 command! -nargs=1 G set hls | call Vimgrepbuffers(<f-args>)
55
56 " Navigation
57 nmap i gk
58 nmap k gj
59 nmap j <Left>
60 nmap l <Right>
61 xmap i gk
62 xmap k gj
63 xmap j <Left>
64 xmap l <Right>
65
66 nmap K :join<CR>
67 nmap J <Home>
68 nmap L <End>
69 nmap m :buffer
70
71 " Maintain Visual Mode after shifting > and <
72 vmap < <gv
73 vmap > >gv
74
75 " Move visual block
76 vmap I :m '<-2<CR>gv=gv
77 vmap K :m '>+1<CR>gv=gv
78
79 if &term =~ '^screen'
80 " Fix <Home>, <End>, <C-Left>, etc. when vim is in tmux;
81 " tmux will send xterm-style keys when xterm-keys is on
82 execute "set <xHome>=\e[7~"
83 execute "set <xEnd>=\e[8~"
84 execute "set <xRight>=\e[1;*C"
85 execute "set <xLeft>=\e[1;*D"
86 execute "set <xUp>=\e[1;*A"
87 execute "set <xDown>=\e[1;*B"
88 endif
89
90 set autoindent
91 set background=dark
92 set breakindent
93 set cmdheight=1
94 if !has("nvim")
95 set completeopt=menu,menuone,popup,longest
96 endif
97 set conceallevel=0
98 set cpoptions+=M " ignore backslashes in % matching
99 set cursorline
100 execute "silent !mkdir -p ~/.cache/" . EDITOR . "/swap"
101 execute "set directory=$HOME/.cache/" . EDITOR . "/swap"
102 if !has("nvim")
103 set diffopt=internal,filler,closeoff,algorithm:histogram,indent-heuristic
104 endif
105 set encoding=utf-8
106 set expandtab
107 set foldcolumn=0
108 set foldenable
109 function! GetFoldExprFromIndent()
110 " Calcule l'indentation en fonction des tabulations
111 " et espaces au début des lignes
112 let line = getline(v:lnum)
113 let tabs = matchend(line,"^\t*")
114 let spaces = matchend(line,"^[ \t]*") - tabs
115 return tabs + ((spaces + 3) / 4)
116 endfunction
117 set foldexpr=GetFoldExprFromIndent()
118 set foldignore=
119 set foldlevelstart=99
120 set foldmethod=indent
121 set foldminlines=0
122 set hidden
123 set history=1042
124 set hlsearch
125 set incsearch
126 set laststatus=2
127 set lazyredraw
128 set linebreak
129 set list
130 set path=.,/usr/include,/usr/local/include,,
131 set scroll=0
132 set scrolloff=10
133 set sidescroll=0
134 set sidescrolloff=0
135 set signcolumn=yes
136 set shortmess+=A
137 set swapfile
138 let mapleader = ","
139 set matchpairs+=<:>
140 set maxmempattern=2000
141 set noautochdir
142 set nocompatible
143 set noerrorbells
144 set noignorecase
145 "set noloadplugins
146 set nosmartindent
147 set nowrapscan
148 set number
149 set ruler
150 "set runtimepath=$HOME/.$EDITOR,$VIMRUNTIME,$VIM
151 set sessionoptions=curdir,folds
152 set shiftwidth=2
153 set showcmd
154 set statusline=%f
155 "set statusline+=\ %l:%c
156 "set statusline=\ %{get(b:,'coc_current_function','')}
157 set statusline+=%=
158 "set statusline+=%#ErrorMsg#%{CocStatusDiagnosticError()}%*
159 "set statusline+=\ %{CocStatus()}
160 set statusline+=%{LinterStatus()}
161 set statusline+=\ %m%R\ %Y
162 set tabstop=2
163 set ttyfast
164 set undolevels=542
165 set updatetime=300
166 set verbose=0
167 execute "silent !mkdir -p ~/.cache/" . EDITOR . "/view"
168 execute "set viewdir=$HOME/.cache/" . EDITOR . "/view"
169 execute "set viminfo+=n$HOME/.cache/" . EDITOR . "/info"
170 set visualbell
171 set visualbell t_vb=
172 set whichwrap+=<,>,[,]
173 set wildignore=*.a,*.d,*.o,*.so,*~,*.cmo,*.cmi,*.cmx,*.cmxs,*.cma,*.cmxa,*.byte,*.native,*.hi
174 set wildmenu
175 set wildmode=list:longest,full
176 set wrap
177 syntax on
178 " When editing a file, always jump to the last known cursor position.
179 " Don't do it when the position is invalid or when inside an event handler
180 " (happens when dropping a file on gvim).
181 autocmd BufReadPost *
182 \ if line("'\"") > 0 && line("'\"") <= line("$") |
183 \ exe "normal g`\"" |
184 \ endif
185 " Set screen title
186 if (&term == "screen" || &term == "screen.linux")
187 "set t_ts=\ek
188 "set t_fs=\e\
189 endif
190 if has("gui_running")
191 set title
192 set titlelen=0
193 set titlestring=VIM:\ %F\ %a%r%m
194 else
195 " Italic
196 set t_ZH=\e[3m
197 set t_ZR=\e[23m
198 " Underline
199 set t_us=\e[4m
200 set t_ue=\e[m
201 " Set window title
202 set t_ts=\e]0;
203 set t_fs=\a
204 "set titlestring=%t%(\ %M%)%(\ (%{expand(\"%:p:h\")})%)%(\ %a%)\ -\ %{v:servername}
205 auto BufEnter * :set title | let &titlestring = 'VIM: ' . expand('%:p')
206 "auto VimLeave * :set t_ts=\ek\e\
207 endif
208 let space = &shiftwidth == 0 ? &tabstop : &shiftwidth
209 if (&term == "linux" || &term == "screen.linux")
210 "set foldtext=substitute(getline(v\:foldstart),'^\\(\\s*\\)',{m->substitute(m[1],'\\('.repeat('\ ',&shiftwidth).'\\\|\\t\\)','\|'.repeat('.',&shiftwidth-1),'g')},'').'\ \ ('.(v\:foldend-v\:foldstart+1).')\ '
211 "set fillchars=fold:_
212 set list listchars=nbsp:+,tab:\|.,trail:_,extends:>,precedes:<
213 set foldtext=getline(v\:foldstart).'\ \ ('.(v\:foldend-v\:foldstart+1).')\ '
214 else
215 "set foldtext=substitute(getline(v\:foldstart),'^\\(\\s*\\)',{m->substitute(m[1],'\\('.repeat('\ ',&shiftwidth).'\\\|\\t\\)','⎢'.repeat('·',&shiftwidth-1),'g')},'').'\ \ ('.(v\:foldend-v\:foldstart+1).')\ '
216 "set fillchars=fold:·
217 set foldtext=getline(v\:foldstart).'\ \ ('.(v\:foldend-v\:foldstart+1).')\ '
218 set list listchars=nbsp:¬,tab:⎢·,trail:·,extends:>,precedes:<
219 endif
220
221 "let g:indentLine_char_list = ['⎢']
222 "" Concealed text is not highlighted by the visual mode, this is annoying.
223 ""let g:indentLine_concealcursor = 'incv'
224 "let g:indentLine_faster = 1
225 "let g:indentLine_first_char = '⎢'
226 "let g:indentLine_leadingSpaceChar = '·'
227 "let g:indentLine_leadingSpaceEnabled = 1
228 "let g:indentLine_showFirstIndentLevel = 1
229 "let g:indentLine_bgcolor_term = 'NONE'
230 "let g:indentLine_defaultGroup = 'Folded'
231
232 if (v:version >= 700)
233 hi TabLine term=bold,reverse ctermfg=white ctermbg=blue cterm=none
234 hi TabLineFill term=bold,reverse ctermfg=none ctermbg=blue cterm=none
235 hi TabLineSel term=reverse ctermfg=white ctermbg=none cterm=bold
236 imap <C-S-tab> <Esc>:tabprevious<CR>i
237 imap <C-t> <Esc>:tabnew<CR>
238 imap <C-tab> <Esc>:tabnext<CR>i
239 nmap <C-S-tab> :tabprevious<CR>
240 nmap <Esc><tab> :bnext<CR>
241 nmap <C-t> :tabnew<CR>
242 "nmap <C-tab> :tabprevious<CR>
243 "nmap <tab> :tabnext<CR>
244 nmap <C-tab> :bprevious!<CR>
245 nmap <tab> :bnext!<CR>
246 nmap td :tabclose<CR>
247 nmap ti :tabfirst<CR>
248 nmap tj :tabprev<CR>
249 nmap tk :tablast<CR>
250 nmap tl :tabnext<CR>
251 nmap tm :tabm<Space>
252 nmap tn :tabnew<Space>
253 nmap tt :tabedit<Space>
254 nmap <C-i> :bprevious!<CR>
255 nmap <C-k> :bnext!<CR>
256 nmap <C-j> :lprevious<CR>
257 nmap <C-l> :lnext<CR>
258 nmap <C-u> :cprevious<CR>
259 nmap <C-o> :cnext<CR>
260 nmap <C-w>k :wincmd j<CR>
261 nmap <C-w>i :wincmd k<CR>
262 nmap <C-w>j :wincmd h<CR>
263 nmap <C-w>l :wincmd l<CR>
264 set tabpagemax=1000
265 set sessionoptions+=tabpages
266 endif
267 if (v:version >= 704)
268 execute "silent !mkdir -p ~/.cache/" . EDITOR . "/undo"
269 execute "set undodir=$HOME/.cache/" . EDITOR . "/undo"
270 set undofile
271 autocmd BufWritePre /tmp/* setlocal noundofile
272 autocmd BufWritePre */sec/* setlocal noundofile
273 endif
274 fun! TrimWhitespace()
275 let l:save = winsaveview()
276 keeppatterns %s/\s\+$//e
277 call winrestview(l:save)
278 endfun
279 autocmd BufRead .envrc setfiletype sh
280 "autocmd BufRead *.hamlet setfiletype html
281 "autocmd BufRead *.julius setfiletype javascript
282 "autocmd BufRead *.lucius setfiletype css
283 autocmd BufRead *.ledger setfiletype ledger
284 autocmd BufRead *.lhs setfiletype haskell
285 autocmd BufRead HLint.hs setfiletype txt
286 autocmd BufRead *.purs
287 \ setfiletype purescript |
288 \ set syntax=haskell
289 "autocmd BufRead *.nix set syntax=zsh | set expandtab
290 autocmd BufNewFile,BufRead *.nix
291 \ hi nixAntiquotation ctermfg=cyan |
292 \ set expandtab |
293 \ set isk+=- |
294 \ set foldmethod=indent
295 autocmd BufWritePre *.nix :call TrimWhitespace()
296 autocmd BufNewFile,BufRead *.py
297 \ set noexpandtab |
298 \ set tabstop=2 |
299 \ set softtabstop=0
300 autocmd BufNewFile,BufRead *.hs set expandtab
301 autocmd BufNewFile,BufRead *.tct set filetype=tct | set expandtab
302 autocmd BufWritePost * if &diff == 1 | diffupdate | endif
303 augroup quickfix
304 autocmd!
305 autocmd FileType qf setlocal wrap
306 augroup END
307 " If doing a diff. Upon writing changes to file, automatically update the differences
308 """
309 """ plugins
310 """
311 " matchit
312 let b:match_words = '«:»,“:”'
313 " easy_align
314 nmap <Leader>a <Plug>(EasyAlign)
315 vmap <Enter> <Plug>(EasyAlign)
316 let g:easy_align_ignore_groups = ['Comment', 'String', 'ledgerTransaction', 'ledgerTag', 'jccComment', 'jccTransaction']
317 " netrw
318 let g:netrw_liststyle = 3
319 "let g:netrw_cursorline = 0
320 let s:netrw_usercul = 0
321 " NERD_tree
322 " buffergator
323 let g:buffergator_display_regime = "bufname"
324 let g:buffergator_show_full_directory_path = 0
325 let g:buffergator_viewport_split_policy = 'R'
326 let g:buffergator_autoupdate = 1
327 let g:buffergator_autodismiss_on_select = 0
328 let g:buffergator_suppress_keymaps = 1
329 nmap <leader>bq :bp <BAR> bd #<CR>
330 "let g:buffergator_mru_cycle_loop = 1
331 nmap <leader>i :BuffergatorMruCyclePrev<cr>
332 nmap <leader>k :BuffergatorMruCycleNext<cr>
333 nmap <leader>bl :BuffergatorOpen<cr>
334 nmap <leader>T :enew<cr>
335 set cpoptions+=M " ignore backslashes in % matching
336 " TOHtml
337 let g:html_expand_tabs = 0
338 let g:html_ignore_conceal = 0
339 let g:html_ignore_folding = 1
340 let g:html_number_lines = 0
341 let g:html_use_xhtml = 0
342 " CtrlP
343 "map <C-p> :CtrlPBuffer<CR>
344 "let g:ctrlp_working_path_mode = 'c'
345 "let g:ctrlp_map = '<Leader>t'
346 "let g:ctrlp_match_window_bottom = 0
347 "let g:ctrlp_match_window_reversed = 0
348 "let g:ctrlp_custom_ignore = '\v\~$|\.(o|swp|pyc|wav|mp3|ogg|blend)$|(^|[/\\])\.(hg|git|bzr)($|[/\\])|__init__\.py'
349 "let g:ctrlp_working_path_mode = 0
350 "let g:ctrlp_dotfiles = 0
351 "let g:ctrlp_switch_buffer = 0
352 " vimproc
353 " ghc-mod
354 "map <silent> tu :call GHC_BrowseAll()<CR>
355 "map <silent> tw :call GhcModType<CR>
356 map <silent> hc :GhcModTypeClear<CR>
357 map <silent> he :GhcModExpand<CR>
358 map <silent> hi :GhcModTypeInsert<CR>
359 map <silent> hs :GhcModSigCodegen<CR>
360 map <silent> hs :GhcModSplitFunCase<CR>
361 map <silent> ht :GhcModType<CR>
362 " vimBall
363 " AnsiEsc
364 " Hoogle
365 nmap <F5> :Hoogle <C-R><C-W><CR>
366 " TimeKeeper
367 "let g:TimeKeeperUpdateFileTimeSec = 5
368 ""let g:TimeKeeperStartOnLoad = 1
369 "let g:TimeKeeperUseFlatFile = 0
370 "nmap <silent> <F8> :call TimeKeeper_ToggleTaskWindow()<cr>
371 "call TimeKeeper_StartTracking()
372 " Recover
373 let g:RecoverPlugin_Delete_Unmodified_Swapfile = 1
374 " calendar-vim
375 let g:calendar_number_of_months = 1
376 let g:calendar_wruler = 'di lu ma me je ve sa'
377 let g:calendar_monday = 1
378 function MyCalAction(day,month,year,week,dir)
379 " day : day you actioned
380 " month : month you actioned
381 " year : year you actioned
382 " week : day of week (Mo=1 ... Su=7)
383 " dir : direction of calendar
384 endfunction
385 "let calendar_action = 'MyCalAction'
386 "hi link ALEError Error
387 "hi Warning term=underline cterm=underline ctermfg=Yellow gui=undercurl guisp=Gold
388 "hi link ALEWarning Warning
389 "hi link ALEInfo SpellCap
390 " echodoc
391 "let g:echodoc#enable_at_startup = 1
392 "let g:echodoc#type = 'signature'
393 " vim-gitgutter
394 "let g:gitgutter_grep = 'rg'
395 let g:gitgutter_grep = 'grep'
396 let g:gitgutter_diff_args = '--diff-algorithm=histogram'
397 let g:gitgutter_map_keys = 0
398 let g:gitgutter_sign_added = '+'
399 let g:gitgutter_sign_modified = '±'
400 let g:gitgutter_sign_modified_removed = '-'
401 let g:gitgutter_sign_removed = '_'
402 let g:gitgutter_sign_removed_first_line = '▔'
403 let g:gitgutter_sign_priority = 9
404 hi GitGutterAdd ctermfg=green
405 hi GitGutterDelete ctermfg=red
406 hi GitGutterChange ctermfg=yellow
407 hi GitGutterChangeDelete ctermfg=red
408 nmap [c <Plug>(GitGutterPrevHunk)
409 nmap ]c <Plug>(GitGutterNextHunk)
410 nmap <Leader>p <Plug>(GitGutterPreviewHunk)
411 nmap <Leader>+ <Plug>(GitGutterStageHunk)
412 nmap <Leader>- <Plug>(GitGutterUndoHunk)
413 " deoplete
414 "let g:deoplete#enable_at_startup = 1
415 "call deoplete#custom#option('sources', {
416 "\ '_': ['ale', 'buffer', 'around'],
417 "\})