" Vundle
set nocompatible " be iMproved, required
filetype off " required
scriptencoding utf-8
set encoding=utf-8
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim', {'pinned': 1}
" Special syntaxes
Plugin 'groenewege/vim-less' " Less
Plugin 'digitaltoad/vim-pug' " Pug
Plugin 'lervag/vimtex' " TeX
Plugin 'andymass/vim-matchup' " TeX parentheses; see https://github.com/lervag/vimtex/issues/1143
Plugin 'Shirk/vim-gas' " GNU Assembly
Plugin 'git@gitlab.com:clean-and-itasks/vim-clean' " Clean
Plugin 'camilstaps/vim-fuspel', {'pinned': 1} " Fuspel
Plugin 'camilstaps/vim-snug', {'pinned': 1} " Snug
Plugin 'iamcco/markdown-preview.nvim' " live markdown preview with :MarkdownPreview; use :call mkdp#util#install() to finish installation
Plugin 'https://gitlab.com/camilstaps/nir', {'pinned': 1, 'rtp': 'vim'} " Nir
Plugin 'camilstaps/vim-sil', {'pinned': 1} " Sil
Plugin 'rust-lang/rust.vim' " Rust
Plugin 'rhysd/vim-llvm' " LLVM
Plugin 'rhysd/vim-wasm' " WebAssembly text
" Other plugins
Plugin 'mg979/vim-visual-multi' " Multiple cursors
Plugin 'tpope/vim-surround' " cs)] to replace parenthesis pairs, e.g.
Plugin 'airblade/vim-gitgutter' " git diff in gutter
" Color schemes
Plugin 'NLKNguyen/papercolor-theme'
if has('nvim')
Plugin 'neovim/nvim-lspconfig' " Language Server Protocol configs
endif
call vundle#end()
" End Vundle
function! s:reset_gitgutter_highlights()
highlight! link SignColumn LineNr
let ctermbg=synIDattr(synIDtrans(hlID('SignColumn')), 'bg', 'cterm')
exe 'highlight GitGutterAdd ctermfg=2 ctermbg='.ctermbg
exe 'highlight GitGutterChange ctermfg=3 ctermbg='.ctermbg
exe 'highlight GitGutterDelete ctermfg=1 ctermbg='.ctermbg
endfunction
" Source some special files on writing
autocmd! BufWritePost .vimrc source % | call s:reset_gitgutter_highlights()
autocmd! BufWritePost .Xresources !xrdb -merge %
" Common settings
set tabstop=4 shiftwidth=4
set colorcolumn=80
set textwidth=79
set formatoptions-=t
set linebreak
set number
set path+=**
set dir=~/.swp
set listchars=nbsp:¬,tab:▸\ ,extends:»,precedes:«,trail:•
set nolist
set nowrap
set scrolloff=10
set tabpagemax=100
set nrformats=hex,alpha
set fillchars+=fold:\
set statusline=
set switchbuf=usetab,newtab
set incsearch
set hlsearch
map <LocalLeader>q :nohlsearch<CR>
" Fix `gx`: https://github.com/vim/vim/issues/4738#issuecomment-856925080
nnoremap <silent> gx :execute 'silent! !xdg-open ' . shellescape(expand('<cfile>'), 1)<cr>
filetype plugin indent on
syntax enable
" Colours & Highlighting
set cursorline
colorscheme PaperColor
highlight SpellBad cterm=underline,bold ctermfg=black ctermbg=red
highlight SpellCap cterm=underline,bold ctermfg=black ctermbg=yellow
highlight SpellLocal cterm=underline,bold ctermfg=black ctermbg=blue
highlight SpellRare cterm=underline,bold ctermfg=black ctermbg=white
highlight ColorColumn ctermfg=black ctermbg=yellow
" The terminal background (set in .Xresources) is the background for that part
" of the terminal where characters can be placed. The padding at the bottom
" and right side are the line border (color 708 in .Xresources). This is not
" colored by Vim by default. When the color scheme is changed, we check the
" current background color and update the line border of the terminal.
function! s:set_terminal_line_border(color)
if has('nvim')
call chansend(v:stderr, "\033]708;#".a:color."\007")
else
silent execute ':!echo -e "\033]708;\#'.a:color.'\007"'
endif
endfunction
function! s:detect_terminal_line_border()
let bg=synIDattr(synIDtrans(hlID('Normal')), 'bg', 'cterm')
if bg == '255'
call s:set_terminal_line_border('eeeeee')
else
if bg != '234'
echohl WarningMsg
echo 'Vim background was set to '.bg.', which is unknown; resetting terminal lineBorder to default...'
echohl None
call getchar()
endif
call s:set_terminal_line_border('1c1c1c')
endif
endfunction
function! s:colorscheme_changed()
call s:detect_terminal_line_border()
call s:reset_gitgutter_highlights()
endfunction
autocmd VimEnter,ColorScheme * call s:colorscheme_changed()
" When we leave vim we restore the value set also in .Xresources
autocmd VimLeave * call s:set_terminal_line_border('002b36')
let network = system("iwconfig wlp2s0 | grep ESSID | cut -d'\"' -f2")
let network = substitute(network, '\n', '', '')
if index(["WiFi in de trein", "Syntus-Utrecht"], network) >= 0
set background=light
else
set background=dark
endif
map <LocalLeader>s :syn sync fromstart<CR>
function! s:enable_automatic_background()
augroup bg
autocmd! bg
autocmd bg BufEnter *
\ set background=dark
\ | call s:colorscheme_changed()
autocmd bg BufEnter *.bib,*.md,*.tex,*.txt
\ if &ft != 'help'
\ | set background=light
\ | call s:colorscheme_changed()
\ | end
augroup END
endfunction
function! s:disable_automatic_background()
augroup bg
autocmd! bg
augroup END
augroup! bg
endfunction
command! AutomaticBackgroundEnable call s:enable_automatic_background()
command! AutomaticBackgroundDisable call s:disable_automatic_background()
call s:enable_automatic_background()
" Setting the color scheme messes up the git gutter highlight groups, so reset
" them. For some discussion, see:
" - https://github.com/airblade/vim-gitgutter/issues/696
" - https://stackoverflow.com/a/7383051
augroup gitgutter
autocmd! gitgutter
autocmd gitgutter BufEnter * call s:reset_gitgutter_highlights()
augroup END
" Move through long lines as they were short multiple lines
map <down> gj
map <up> gk
" Case-sensitive search for vim-visual-multi
let g:VM_case_setting = 'sensitive'
" Don't let match-up mess up the statusline
let g:matchup_matchparen_status_offscreen=0
" Status line based on LSP
set statusline+=%{luaeval('lsp_first_hover_code()')}
" Clean has no language server, we use the cloogletags statusline component
set statusline+=%{cleanvim#tags#statusline()}%<
" Git gutter
set updatetime=300
" VimTeX
let g:vimtex_compiler_latexmk = {
\ 'callback': 0,
\ 'options': [
\ '-pdf',
\ '-shell-escape',
\ '-enable-pipes',
\ ],
\ }
let g:vimtex_latexmk_file_line_error = 0
let g:tex_flavor='latex'
let g:matchup_override_vimtex = 1
" Assembly
let asmsyntax='gas'
" X clipboard manipulation using xsel
" See: http://vim.wikia.com/wiki/Accessing_the_system_clipboard
" Use :Cz in visual mode to copy to clipboard, :Pz for pasting
" x instead of z for primary selection, v for secondary selection
command! -range Cz :silent :<line1>,<line2>w !xsel -i -b
command! -range Cx :silent :<line1>,<line2>w !xsel -i -p
command! -range Cv :silent :<line1>,<line2>w !xsel -i -s
command! -range Pz :silent :r !xsel -o -b
command! -range Px :silent :r !xsel -o -p
command! -range Pv :silent :r !xsel -o -s
" For syntax definition debugging
"function! SyntaxItem()
" return synIDattr(synID(line("."),col("."),1),"name")
"endfunction
"set statusline+=%{SyntaxItem()}
"set laststatus=2
" Emulate the default statusline: https://unix.stackexchange.com/a/243667
set statusline+=%=%(%l,%c%V\ %=\ %P%)
" Shorten paths in nitrile-packages/*/PACKAGE/lib in tabline, for Clean
set tabline=%!TabLine()
function! TabLine()
" First generate all the titles
let titles = []
let total_size = 0
for i in range(tabpagenr('$'))
let titles += [s:TabLabel(i+1)]
let total_size += len(titles[i])
endfor
" Add at least the title of the current tab
let after = tabpagenr()
let before = after - 2
let s = '%' . after . 'T%#TabLineSel# ' . titles[before+1] . '%#TabLine#'
let selected_size = len(titles[before+1])
let max_size = &columns - 8
" Continue adding titles after and before the current tab as long as it
" fits on the screen
while 1
let break = 1
if after < len(titles) && selected_size + len(titles[after]) < max_size
" set the tab page number (for mouse clicks)
let s .= ' %' . (after+1) . 'T' . titles[after]
let selected_size += len(titles[after]) + 1
let after += 1
let break = 0
endif
if before >= 0 && selected_size + len(titles[before]) < max_size
let s = '%' . (before+1) . 'T' . titles[before] . ' ' . s
let selected_size += len(titles[before]) + 1
let before -= 1
let break = 0
endif
if break
break
endif
endwhile
let s .= '%T'
" If not all titles were shown, add spaces and guillements on either side
" of the tabline
if before != -1
let s = ' ' . s
let selected_size += 3
endif
if after != len(titles)
let s .= ' '
let selected_size += 3
endif
if before != -1 || after != len(titles)
while selected_size < &columns
if after != len(titles)
let s .= '»'
let selected_size += 1
endif
if before != -1 && selected_size < &columns
let s = '«' . s
let selected_size += 1
endif
endwhile
endif
let s = '%#TabLine#' . s
return s
endfunction
function! s:TabLabel(n)
let buflist = tabpagebuflist(a:n)
let winnr = tabpagewinnr(a:n)
let flags = ''
" Number of windows in tab
if len(buflist) > 1
let flags .= len(buflist)
endif
" Append asterisk if any window has changes
for b in buflist
if getbufinfo(b)[0].changed
let flags .= '*'
break
endif
endfor
" Filename
let name = bufname(buflist[winnr-1])
if name == ''
let name = 'ε'
else
" When this is a file from a Nitrile package, just display the file
" name and add 'pkg' to the flags
let nitrile_pattern = '\%(.*/\)\?nitrile-packages/[^/]*/[^/]*/lib/\(.*\)'
let nitrile_match = match(name, nitrile_pattern)
if match(name, nitrile_pattern) >= 0
let flags .= flags == '' ? 'pkg' : ',pkg'
let name = substitute(name, nitrile_pattern, '\1', '')
else
let name = pathshorten(name)
endif
endif
if flags != ''
return '[' . flags . '] ' . name
else
return name
endif
endfunction