Files
dotfiles/nvim/init.vim

331 lines
8.4 KiB
VimL
Raw Normal View History

2018-07-29 16:29:44 +02:00
set nocompatible
filetype off
2024-08-16 09:53:52 +02:00
" Find python
if has("macunix")
" Required for virtualenvs
let arch=substitute(system('uname -m'), '\n', '', '')
if arch == 'arm64'
let g:python_interpreter=expand("~/python-envs/neovim/bin/python3")
else
let g:python_interpreter="/usr/local/bin/python3"
endif
2025-04-17 08:56:46 +02:00
let g:tagbar_ctags="/opt/homebrew/bin/ctags"
2024-08-16 09:53:52 +02:00
else
let g:python_interpreter = 'python3'
endif
let g:python3_host_prog=g:python_interpreter
2018-07-29 16:29:44 +02:00
" Plugins
2022-10-06 17:02:37 +02:00
" Note: on most systems, this will make the plugins reside in \
" ~/.local/share/nvim/plugged/
let data_dir = has('nvim') ? stdpath('data') . '/site' : expand('~/.vim')
2022-09-05 14:40:20 +02:00
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
2024-07-19 14:08:16 +02:00
let &runtimepath = &runtimepath
2022-09-05 14:40:20 +02:00
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
2024-02-28 11:47:29 +01:00
" Disable Perl
let g:loaded_perl_provider = 0
2022-09-05 14:40:20 +02:00
call plug#begin()
2023-04-14 09:28:35 +02:00
2024-10-05 10:56:06 +02:00
if !exists('g:vscode')
2023-04-14 09:28:35 +02:00
" Warn about plugin updates
Plug 'semanser/vim-outdated-plugins'
2018-07-29 16:29:44 +02:00
" Powerline replacement
2022-09-05 14:40:20 +02:00
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
2018-07-29 16:29:44 +02:00
" Tags
2022-09-05 14:40:20 +02:00
Plug 'xolox/vim-misc'
2021-10-23 18:07:57 +02:00
"Plugin 'ludovicchabant/vim-gutentags'
2022-09-05 14:40:20 +02:00
Plug 'majutsushi/tagbar'
2018-07-29 16:29:44 +02:00
" Templates
2022-09-05 14:40:20 +02:00
Plug 'aperezdc/vim-template'
2018-07-29 16:29:44 +02:00
" Selection expand
2022-09-05 14:40:20 +02:00
Plug 'terryma/vim-expand-region'
Plug 'kana/vim-textobj-user'
Plug 'kana/vim-textobj-line'
Plug 'kana/vim-submode'
2018-07-29 16:29:44 +02:00
" Better Pasting
2022-09-05 14:40:20 +02:00
Plug 'ConradIrwin/vim-bracketed-paste'
2018-07-29 16:29:44 +02:00
" Tmux navigation
2022-09-05 14:40:20 +02:00
Plug 'christoomey/vim-tmux-navigator'
2018-07-29 16:29:44 +02:00
" YouCompleteMe
function! BuildYCM(info)
" info is a dictionary with 3 fields
" - name: name of the plugin
" - status: 'installed', 'updated', or 'unchanged'
" - force: set on PlugInstall! or PlugUpdate!
if a:info.status == 'installed' || a:info.status == 'updated' || a:info.force
execute '!' . g:python_interpreter . ' ./install.py --all'
endif
endfunction
Plug 'ycm-core/YouCompleteMe', { 'do': function('BuildYCM') }
2022-09-05 14:40:20 +02:00
Plug 'rdnetto/YCM-Generator'
2018-07-29 16:29:44 +02:00
" Git
2022-09-05 14:40:20 +02:00
Plug 'tpope/vim-fugitive'
2018-07-29 16:29:44 +02:00
" Snippets
" Track the engine.
2022-09-05 14:40:20 +02:00
Plug 'SirVer/ultisnips'
2018-07-29 16:29:44 +02:00
" Snippets are separated from the engine. Add this if you want them:
2022-09-05 14:40:20 +02:00
Plug 'honza/vim-snippets'
Plug 'ervandew/supertab'
2018-07-29 16:29:44 +02:00
"Buftabeline
2022-09-05 14:40:20 +02:00
"Plug 'ap/vim-buftabline'
2018-07-29 16:29:44 +02:00
" Highlight matching xml tags
2022-09-05 14:40:20 +02:00
Plug 'Valloric/MatchTagAlways'
2018-07-29 16:29:44 +02:00
"Javascript
2022-09-05 14:40:20 +02:00
Plug 'pangloss/vim-javascript'
2018-07-29 16:29:44 +02:00
" Tex
2022-09-05 14:40:20 +02:00
Plug 'lervag/vimtex'
2018-07-29 16:29:44 +02:00
"Go
2022-09-05 14:40:20 +02:00
Plug 'fatih/vim-go'
2018-07-29 16:29:44 +02:00
2024-04-05 12:59:08 +02:00
"Macdown (only on macOS)
2025-01-10 10:02:06 +01:00
"if has("macunix")
"Plug 'hashrocket/vim-macdown'
"endif
2024-10-05 10:56:06 +02:00
" Comments
Plug 'scrooloose/nerdcommenter'
" Surround
Plug 'tpope/vim-surround'
endif
2024-04-05 12:59:08 +02:00
2022-09-05 14:40:20 +02:00
call plug#end()
2022-10-06 16:37:30 +02:00
" Run PlugInstall if there are missing plugins
autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
\| PlugInstall --sync | source $MYVIMRC
\| endif
2018-07-29 16:29:44 +02:00
filetype plugin indent on
set cinkeys-=0#
" Terminal emulator settings
2023-04-06 12:27:01 +02:00
set termguicolors
2018-07-29 16:29:44 +02:00
" Color configuration
2022-10-24 11:38:50 +02:00
try
source ~/.config/nvim/scheme.vim
catch
" Ignore non existing file
endtry
2023-04-06 12:27:01 +02:00
highlight Comment cterm=italic gui=italic
2018-07-29 16:29:44 +02:00
syntax enable " enable syntax processing
" Disable annoying bell
set noerrorbells
" Allow modelines at the beginning and end of a file
set modeline
" Key configuration
let mapleader = "\<Space>" " Make space the leader key
nnoremap <Leader>w :w<CR>| " Write file
nnoremap <Leader>q :q<CR>| " Close file
2023-07-25 13:59:37 +02:00
nnoremap <Leader>s :w !sudo -A tee %<CR>L<CR>
cmap w!! w !sudo -A tee > /dev/null %
2018-07-29 16:29:44 +02:00
nmap <Leader><Leader> V| " Change to visual line mode
map q: :q| " No command history
nmap <Leader><CR> O<ESC> | " Add line above
nmap <CR> o<ESC>| " Add line below
nmap <Leader>f gq}| " Format paragraph
" Window management
nmap <Leader>mt :tab sp<CR> | " maximize window to new tab
nmap <Leader>. <C-w>= | " Split windows equally
map gb :bnext<CR>
map gB :bNext<CR>
2024-10-05 10:56:06 +02:00
if !exists('g:vscode')
2018-07-29 16:29:44 +02:00
call submode#enter_with('grow/shrink', 'n', '', '<Leader>r', '<Nop>')
call submode#map('grow/shrink', 'n', '', '+', '<C-w>+')
call submode#map('grow/shrink', 'n', '', '-', '<C-w>-')
call submode#map('grow/shrink', 'n', '', '<', '<C-w><')
call submode#map('grow/shrink', 'n', '', '>', '<C-w>>')
2024-10-05 10:56:06 +02:00
endif
2018-07-29 16:29:44 +02:00
set splitbelow
set splitright
2025-01-10 10:01:49 +01:00
" Delete without copying
nnoremap <leader>d "_d
xnoremap <leader>d "_d
nnoremap <leader>x "_x
xnoremap <leader>x "_x
xnoremap <leader>p "_dP
2018-07-29 16:29:44 +02:00
"disable submode timeouts:
let g:submode_timeout = 0
" don't consume submode-leaving key
let g:submode_keep_leaving_key = 1
" Configuration of spaces and tabs
set tabstop=4 " show 4 spaces per TAB
set softtabstop=4 " insert 4 spaces per TAB
set smarttab
set expandtab " tabs are spaces
set shiftwidth=4
" UI
set number " show line numbers
set relativenumber "relative line numbers
set showcmd " show last command in bottom bar
set cursorline " highlight current line
" Statusline
set statusline+=%f\ " show Filepath
set statusline+=[%{strlen(&fenc)?&fenc:'none'}] "file encoding
set statusline+=%m%r " Modified and read only flag
set statusline+=%= " align left
set statusline+=%y " show Filetype
set statusline+=[%{&fo}] " Show format options
set laststatus=2 " always show statusline
" Filetypes
filetype on " filetype detection on
filetype indent on " filetype-specific indent .vim/indent/
filetype plugin on " filteype plugins in .vim/ftplugins
set smartindent
set wildmenu " visual autocomplete for command menu
set lazyredraw " redraw only when necessary
set showmatch " highlight matching brackets
set mouse=a " Mouse control
" Searching
set incsearch " search while entering
set hlsearch " highlight matches
nnoremap <Leader>h :set hlsearch!<CR>
set ignorecase
set smartcase
" Line wrapping
2019-08-22 15:22:49 +02:00
set tw=100 " set textwidth of 100 characters
2018-07-29 16:29:44 +02:00
set formatoptions-=t " Don't wrap code
set formatoptions+=c " Wrap comments
set formatoptions+=mB " Don't break multibyte characters
set formatoptions+=j " Remove multiple comment markers
function TextWrapToggle()
if &fo =~'t'
setlocal fo-=t
else
setlocal fo+=t
endif
let formatoptions = &formatoptions
echom formatoptions
endfunction
nmap <Leader>t :call TextWrapToggle()<CR>
" Highlight characters past 80
"augroup vimrc_autocmds
"autocmd BufEnter * highlight OverLength ctermbg=88 guibg=#592929
"autocmd BufEnter * match OverLength /\%81v.*/
"augroup END
"Copying
2025-07-31 15:24:07 +02:00
if !exists('g:vscode')
2025-05-08 08:58:53 +02:00
lua << EOF
vim.g.clipboard = 'osc52'
EOF
2025-07-31 15:24:07 +02:00
endif
2018-07-29 16:29:44 +02:00
set clipboard=unnamedplus,unnamed " Copy/Paste
2020-03-23 15:08:52 +01:00
" Airline
let g:airline_powerline_fonts = 1
2018-07-29 16:29:44 +02:00
" TagBar
nmap <F8> :TagbarToggle<CR>
imap <F8> <ESC>:TagbarToggle<CR>gi
nmap <C-]> <C-w><C-]><C-w>T
" YouCompleteMe
let g:ycm_collect_identifiers_from_tags_files = 1 " Read from tag files
let g:ycm_global_ycm_extra_conf = expand('~/.config/nvim/.ycm_extra_conf.py') " Standard conf
2018-07-29 16:29:44 +02:00
let g:ycm_enable_diagnostic_signs = 0 " Do not show semantic error bar
let g:ycm_server_python_interpreter=g:python_interpreter
2024-08-16 09:53:52 +02:00
let g:ycm_python_interpreter_path=g:python_interpreter
" Enable virtualenv autocompletion
2024-08-16 09:53:52 +02:00
let g:ycm_python_binary_path = 'python3'
2018-07-29 16:29:44 +02:00
let g:ycm_key_list_select_completion = ['<C-j>', '<C-n>', '<Down>']
let g:ycm_key_list_previous_completion = ['<C-k>', '<C-p>', '<Up>']
"Tags
let g:easytags_async = 1
" make
2022-02-17 09:11:22 +01:00
set switchbuf=split
"autocmd QuickFixCmdPre make set cmdheight=2
2018-07-29 16:29:44 +02:00
"autocmd QuickFixCmdPost make nested cwindow "Open the quickfix window
"autocmd QuickFixCmdPost make nested lwindow "Change to the quickfix window
2022-02-17 09:11:22 +01:00
"nmap <F9> :silent! make<CR>:redraw!<CR>
"nmap <Leader>m :silent! make<CR>:redraw!<CR>
"nmap <Leader>x :silent! make ex<CR>:redraw!<CR>
"imap <F9> <ESC>:make<CR>:redraw!<CR>i
2018-07-29 16:29:44 +02:00
" vim-templates config-file
try
source ~/.config/nvim/.vimrc_config_template
catch
" Ignore non existing file
endtry
" Expand region
vmap v <Plug>(expand_region_expand)
vmap <C-v> <Plug>(expand_region_shrink)
" Snippets
let g:SuperTabDefaultCompletionType = '<C-n>'
let g:SuperTabCrMapping = 0
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
let g:UltiSnipsEditSplit="vertical"
set rtp+=~/.config/nvim/my-snippets
2022-02-17 09:11:22 +01:00
" Folding
set foldmethod=syntax
set foldlevel=100
" Use F9 to toggle folding
inoremap <F9> <C-O>za
nnoremap <F9> za
onoremap <F9> <C-C>za
vnoremap <F9> zf
nnoremap <Leader>a za
onoremap <Leader>a <C-C>za
vnoremap <Leader>a zf
2018-07-29 16:29:44 +02:00
try
source ~/.config/nvim/.vimrc_config_expand_region
catch
" Ignore non existing file
endtry
" Extra stuff
try
source ~/.config/nvim/.vimrc_config_extra_stuff
catch
" Ignore non existing file
endtry
let g:tex_flavor = "latex"
2021-01-11 10:33:43 +01:00
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab