dotfiles/nvim/init.vim

227 lines
5.7 KiB
VimL
Raw Normal View History

2018-09-19 14:52:29 +02:00
" Pas de compatibilité a VI !
set nocompatible
2024-05-20 10:36:29 +02:00
set notermguicolors
2018-09-19 14:52:29 +02:00
" PLUGNIS ###########################################################{{{
call plug#begin()
2021-06-26 22:16:10 +02:00
" Conquer of Completion
Plug 'neoclide/coc.nvim', {'branch': 'release'}
2019-06-19 10:03:55 +02:00
" General plugins
2018-09-19 14:52:29 +02:00
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
2019-06-19 10:03:55 +02:00
Plug 'https://gitea.tforgione.fr/tforgione/peach.git'
2018-09-19 14:52:29 +02:00
Plug 'scrooloose/nerdtree'
2019-01-30 11:49:57 +01:00
Plug 'tpope/vim-abolish'
2023-05-24 13:10:33 +02:00
Plug 'lambdalisue/suda.vim'
2019-06-19 10:03:55 +02:00
" Language specific plugins
" Rust
2019-06-19 10:04:48 +02:00
Plug 'rust-lang/rust.vim'
2019-06-19 10:03:55 +02:00
" Elm
2019-06-19 10:04:48 +02:00
Plug 'ElmCast/elm-vim'
2019-06-19 10:03:55 +02:00
" Toml
2019-06-19 10:04:48 +02:00
Plug 'cespare/vim-toml'
2019-06-19 10:03:55 +02:00
" Pug
2019-06-19 10:04:48 +02:00
Plug 'digitaltoad/vim-pug'
2019-06-19 10:03:55 +02:00
2023-04-04 16:14:19 +02:00
" Typst
Plug 'kaarmu/typst.vim'
2019-06-19 10:03:55 +02:00
2018-09-19 14:52:29 +02:00
call plug#end()
" Line numbers and syntaxic coloration
" set nu
" syntax on
" Highlight bad spaces (not working...)
" }}}
" INDENTATION #######################################################{{{
set expandtab
set tabstop=4
set shiftwidth=4
set autoindent
2022-02-17 16:18:13 +01:00
set tw=120
2023-10-11 10:20:08 +02:00
if !empty($NVIM_TEXT_WIDTH)
execute 'set tw=' . $NVIM_TEXT_WIDTH
endif
2018-09-19 14:52:29 +02:00
" }}}
" UI CONFIG #########################################################{{{
set number
2019-06-25 14:12:13 +02:00
if $NVIM_LINE_NUMBER == 'rnu'
set rnu
endif
2018-09-19 14:52:29 +02:00
set showcmd
set wildmenu
set lazyredraw
set encoding=utf8
set clipboard=unnamedplus
set updatecount=50
set mouse=a
2019-06-05 16:59:43 +02:00
set guicursor=
2018-09-19 14:52:29 +02:00
" set ttymouse=sgr
" Espaces insécables grrrr
set list
set listchars=tab:,trail,extends:>,precedes:<,nbsp
" Remove trailing spaces
autocmd BufWritePre * :%s/\s\+$//e
2018-09-19 14:52:29 +02:00
" Compile on F12
if executable('mars')
2019-06-12 15:07:10 +02:00
nnoremap <silent><F12> :wa \| !mars -p %:p<CR>
inoremap <silent><F12> <C-O>:wa \|!mars -p %:p<CR>
vnoremap <silent><F12> :wa \|!mars -p %:p<CR>
elseif executable('make')
2019-06-12 15:07:10 +02:00
nnoremap <silent><F12> :wa \| !make -p %:p<CR>
inoremap <silent><F12> <C-O>:wa \|!make -p %:p<CR>
vnoremap <silent><F12> :wa \|!make -p %:p<CR>
endif
2023-05-24 13:10:33 +02:00
" SudaWrite with W
command W SudaWrite
2018-09-19 14:52:29 +02:00
" Escape on F1
map <F1> <Esc>
imap <F1> <Esc>
" vim airline config
set laststatus=2
let g:airline_powerline_fonts = 1
let g:airline#extensions#branch#format = 1
let g:airline_theme='dark'
set t_Co=256
2024-06-04 23:12:01 +02:00
set textwidth=0
2018-09-19 14:52:29 +02:00
" Set textwidth for latex
" autocmd FileType tex set textwidth=79
" }}}
" COLOR #############################################################{{{
set background=dark
syntax enable
2019-04-26 15:37:14 +02:00
try
colorscheme peach
catch
endtry
2018-09-19 14:52:29 +02:00
highlight BadWhitespace ctermbg=red guibg=red
match BadWhitespace / \| \+\t/
" }}}
" SEARCHING #########################################################{{{
set title
set showmatch
set hlsearch
set noincsearch
" }}}
" NERDTREE ##########################################################{{{
let NERDTreeIgnore = ['\.pyc$','__pycache__']
2019-06-25 14:12:13 +02:00
set shell=zsh
2018-09-19 14:52:29 +02:00
let g:NERDTreeIndicatorMapCustom = {
\ "Modified" : "✹",
\ "Staged" : "✚",
\ "Untracked" : "✭",
\ "Renamed" : "➜",
\ "Unmerged" : "═",
\ "Deleted" : "✖",
\ "Dirty" : "✗",
\ "Clean" : "✔︎",
\ "Unknown" : "?"
\ }
let g:WebDevIconsNerdTreeGitPluginForceVAlign = 1
" }}}
" BACKUPS ###########################################################{{{
2019-04-26 14:56:39 +02:00
set dir=$HOME/.nvim/swp//
2019-04-26 14:57:34 +02:00
autocmd BufWritePost * :silent execute ':w! ' ."$HOME/.nvim/backups/" . substitute(escape(substitute(expand('%:p'), "/", "%", "g"), "%"), ' ', '\\ ', 'g')
2018-09-19 14:52:29 +02:00
if exists('+undofile')
set undofile
set undolevels=1000
set undoreload=10000
if exists('+undodir')
2019-04-26 14:57:34 +02:00
set undodir=$HOME/.nvim/undo
2018-09-19 14:52:29 +02:00
endif
endif
" }}}
" MARKDOWN PREVIEW ##################################################{{{
let g:markdown_composer_browser = 'firefox'
let g:instant_markdown_autostart = 0
" }}}
2021-06-26 22:16:10 +02:00
" COC CONFIG ########################################################{{{
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> gp <Plug>(coc-diagnostic-prev)
nmap <silent> gn <Plug>(coc-diagnostic-next)
" 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)
2021-10-11 14:10:52 +02:00
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')
2021-06-26 22:16:10 +02:00
" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>
2019-06-18 17:28:07 +02:00
2021-06-26 22:16:10 +02:00
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('doHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code.
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
2019-06-18 17:28:07 +02:00
2018-09-19 14:52:29 +02:00
" Autoclose preview
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
2019-06-18 17:28:07 +02:00
" Complete on tab
2022-12-07 14:31:02 +01:00
" inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
" Insert <tab> when previous text is space, refresh completion if not.
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1):
\ <SID>check_back_space() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
2018-09-19 14:52:29 +02:00
" }}}
2019-05-24 09:53:57 +02:00
" CUSTOM THINGS DEPENDING ON ENV ####################################{{{
2020-02-05 09:04:17 +01:00
let g:rustfmt_autosave = 1
2023-04-04 16:14:19 +02:00
" Apprently some people don't use vim
" set autoread | au CursorHold * checktime | call feedkeys("lh")