aboutsummaryrefslogtreecommitdiff
path: root/vim/.vimrc
blob: 186ba282d02241327ffce7197cdfcdbb3e46076a (plain) (blame)
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
" 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-jade'                 " Jade
Plugin 'lervag/vimtex'                        " TeX
Plugin 'andymass/vim-matchup'                 " TeX parentheses; see https://github.com/lervag/vimtex/issues/1143
Plugin 'derekwyatt/vim-scala'                 " Scala
Plugin 'Shirk/vim-gas'                        " GNU Assembly
Plugin 'git@github.com:alisdair/vim-armasm'   " ARM Assembly
Plugin 'git@gitlab.science.ru.nl:cstaps/vim-clean' " Clean
Plugin 'git@github.com:camilstaps/vim-bb'     " Blackboard feedback
Plugin 'camilstaps/vim-fuspel', {'pinned': 1} " Fuspel
Plugin 'camilstaps/vim-sil', {'pinned': 1}    " Sil
Plugin 'camilstaps/vim-smv', {'pinned': 1}    " SMV
Plugin 'camilstaps/vim-torxakis', {'pinned': 1} " Torxakis
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 'scrooloose/syntastic'         " Syntastic
Plugin 'tpope/vim-surround'           " cs)] to replace parenthesis pairs, e.g.
Plugin 'rickhowe/diffchar.vim'        " diffing on character level
Plugin 'airblade/vim-gitgutter'       " git diff in gutter
Plugin 'godlygeek/tabular'            " tabularize things
Plugin 'google/vim-searchindex'       " shows '[N/M]' when searching

" Color schemes
Plugin 'NLKNguyen/papercolor-theme'

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 cc=80
set linebreak
set nu
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>

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()
	let bg=synIDattr(synIDtrans(hlID('Normal')), 'bg', 'cterm')
	if bg == '255'
		silent execute ':!echo -e "\033]708;\#eeeeee\007"'
	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
		silent execute ':!echo -e "\033]708;\#1c1c1c\007"'
	endif
endfunction
autocmd VimEnter,ColorScheme * call s:set_terminal_line_border()
" When we leave vim we restore the value set also in .Xresources
autocmd VimLeave * silent execute ':!echo -e "\033]708;\#002b36\007"'

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>

autocmd BufEnter * set bg=dark | call s:set_terminal_line_border()
autocmd BufEnter *.md,*.tex,*.txt set bg=light | call s:set_terminal_line_border()

" 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
autocmd BufEnter * call s:reset_gitgutter_highlights()

" 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

" Clean
let g:clean_load_cloogle_tags = 1
let g:clean_warnings_hide_libraries =
			\ [ "ArgEnv"
			\ , "Dynamics"
			\ , "GraphCopy"
			\ , "iTasks"
			\ , "StdEnv"
			\ , "TCPIP"
			\ ]
set statusline+=%{cleanvim#tags#statusline()}

" Syntastic
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

let g:syntastic_python_checkers = ['pylint', 'pep8']
let g:syntastic_python_pylint_exec = 'pylint.sh'
let g:syntastic_python_pylint_args = '--guess'

let g:syntastic_mode_map = {
			\ "mode": "passive",
			\ "passive_filetypes": [] }

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

" Mutt
au BufRead /tmp/mutt-* set tw=72

" 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
cabbrev cv Cv
cabbrev cz Cz
cabbrev cx Cx

command! -range Pz :silent :r !xsel -o -b
command! -range Px :silent :r !xsel -o -p
command! -range Pv :silent :r !xsel -o -s

cabbrev pz Pz
cabbrev px Px
cabbrev pv Pv

" For syntax definition debugging
"function! SyntaxItem()
"  return synIDattr(synID(line("."),col("."),1),"name")
"endfunction
"set statusline+=%{SyntaxItem()}
"set laststatus=2

" https://unix.stackexchange.com/a/243667/37050
set statusline+=%=%(%l,%c%V\ %=\ %P%)