Edit page AbridgedResume
[wiki.git] / vimrc
1 " Copyright 2004, 2005, 2008 Develer S.r.l. (http://www.develer.com/)
2 " Copyright 2009-2022 Bernie Innocenti <bernie@codewiz.org>
3 "
4 " Author: Bernie Innocenti <bernie@codewiz.org>
5 " Author: Simone Zinanni <s.zinanni@develer.com>
6 " Author: Stefano Fedrigo <aleph@develer.com>
7 " Author: Daniele Varrazzo <piro@develer.com>
8 "
9 " note: to reload this file after a change, use ':so %'
10
11 set nocompatible        " Use Vim defaults (much better!)
12 set bs=indent,eol,start " allow backspacing over everything in insert mode
13 set history=1000
14 set ruler               " show the cursor position all the time
15 set laststatus=2        " Always show the status line at the bottom (neovim)
16 set clipboard+=unnamed,unnamedplus
17
18 augroup fedora
19   autocmd!
20   " In text files, always limit the width of text to 78 characters
21   autocmd BufRead *.txt set tw=78
22   " When editing a file, always jump to the last cursor position
23   autocmd BufReadPost *
24   \ if line("'\"") > 0 && line ("'\"") <= line("$") |
25   \   exe "normal! g'\"" |
26   \ endif
27   " don't write swapfile on most commonly used directories for NFS mounts or USB sticks
28   autocmd BufNewFile,BufReadPre /media/*,/run/media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp
29   " start with spec file template
30   autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec
31 augroup END
32
33 " Switch syntax highlighting on, when the terminal has colors
34 " Also switch on highlighting the last used search pattern.
35 if &t_Co > 2 || has("gui_running")
36   syntax on
37   " bernie: hilighting long lines is very slow
38   set synmaxcol=320
39   set hlsearch
40   set incsearch
41   set background=dark
42
43   " bernie: Show matching parenthesis when writing
44   set showmatch
45   " bernie: add bottom horizontal scroll bar
46   set guioptions+=b
47   " aleph: remove useless luser toolbar
48   set guioptions-=T
49
50   " highlighting for embedded LUA in nvim
51   let g:vimsyn_embed='l'
52
53   " bernie: highlight cursor line
54   set cursorline
55   set colorcolumn=+1
56
57   " Limit modern terminal stuff to known-good terminals
58   if has("gui_running") || $KONSOLE_VERSION != '' || $VTE_VERSION != '' || $XTERM_VERSION != '' || $WEZTERM_EXECUTABLE != ''
59     if has('termguicolors')
60       set termguicolors
61     endif
62     colorscheme darkblue
63
64     highlight Normal ctermfg=248 ctermbg=NONE guibg=#000818 guifg=#eeeeee
65     highlight Visual                          guibg=fg      guifg=#4040d0 gui=reverse
66
67     " Make the splits look pretty
68     highlight VertSplit guibg=#001111 guifg=#224422
69
70     " bernie: blinky cursor!
71     " let &guicursor = &guicursor . ',a:blinkwait175-blinkoff10-blinkon20'
72
73     " Enable spelling for comments in various languates
74     " bernie: don't enable by default because has too many false positives
75     "autocmd FileType c,cpp,java,python,rust,vim,text  set spell
76   endif
77
78   " Make the wrap column and cursor line more discrete
79   highlight CursorLine   term=NONE cterm=NONE ctermbg=233 guibg=#001133
80   highlight CursorColumn term=NONE cterm=NONE ctermbg=233 guibg=#000820
81   highlight ColorColumn  term=NONE cterm=NONE ctermbg=233 guibg=#200818
82
83   " The autocomplete menu
84   highlight Pmenu       ctermfg=250    ctermbg=240 guifg=#ABB2BF guibg=#282C34
85   highlight PmenuSel    ctermfg=253    ctermbg=245 guifg=#353B45 guibg=#A3BE8C
86   highlight PmenuSbar   ctermbg=248                              guibg=#353b45
87   highlight PmenuThumb  ctermbg=15                               guibg=#81A1C1
88
89   highlight! CmpItemAbbrDeprecated guibg=NONE gui=strikethrough guifg=#808080
90   highlight! CmpItemAbbrMatch guibg=NONE guifg=#569CD6
91   highlight! CmpItemAbbrMatchFuzzy guibg=NONE guifg=#569CD6
92   highlight! CmpItemKindVariable guibg=NONE guifg=#9CDCFE
93   highlight! CmpItemKindInterface guibg=NONE guifg=#9CDCFE
94   highlight! CmpItemKindText guibg=NONE guifg=#9CDCFE
95   highlight! CmpItemKindFunction guibg=NONE guifg=#C586C0
96   highlight! CmpItemKindMethod guibg=NONE guifg=#C586C0
97   highlight! CmpItemKindKeyword guibg=NONE guifg=#D4D4D4
98   highlight! CmpItemKindProperty guibg=NONE guifg=#D4D4D4
99   highlight! CmpItemKindUnit guibg=NONE guifg=#D4D4D4
100
101   highlight DiagnosticVirtualTextHint guifg=#444444
102   highlight DiagnosticVirtualTextWarn guifg=#884400
103   highlight DiagnosticVirtualTextError guifg=#880000
104   highlight DiagnosticUnderlineHint gui=NONE
105   highlight DiagnosticUnderlineWarn cterm=undercurl ctermfg=Brown gui=undercurl guisp=#884400
106   highlight DiagnosticUnderlineError cterm=undercurl ctermfg=Red gui=undercurl guisp=#880000
107
108   sign define DiagnosticSignError text= linehl= texthl=DiagnosticSignError numhl=
109   sign define DiagnosticSignWarn text= linehl= texthl=DiagnosticSignWarn numhl=
110   sign define DiagnosticSignInfo text= linehl= texthl=DiagnosticSignInfo numhl=
111   sign define DiagnosticSignHint text=? linehl= texthl=DiagnosticSignHint numhl=
112   autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {scope = "line", focus = false})
113
114   " Undercurl speling erors in terminal and gui
115   " let &t_Cs = "\e[4:3m"
116   " let &t_Ce = "\e[4:0m"
117   highlight SpellBad   term=NONE cterm=undercurl ctermfg=Red    ctermbg=NONE guifg=NONE gui=undercurl guisp=Red
118   highlight SpellCap   term=NONE cterm=undercurl ctermfg=Yellow ctermbg=NONE guifg=NONE gui=undercurl guisp=Yellow
119   highlight SpellRare  term=NONE cterm=undercurl ctermfg=Blue   ctermbg=NONE guifg=NONE gui=undercurl guisp=Blue
120   highlight SpellLocal term=NONE cterm=undercurl ctermfg=Brown  ctermbg=NONE guifg=NONE gui=undercurl guisp=Brown
121
122   " Highlight extra whitespace in various languages
123   autocmd FileType c,cpp,rust highlight ExtraWhitespace ctermbg=DarkRed guibg=DarkRed
124 endif
125
126 " bernie: insensitive search
127 set ignorecase
128 " aleph: if pattern contains uppercase chars, the search is case _sensitive_
129 set smartcase
130
131 " bernie: horizontal and vertical scrolling
132 set nowrap
133 set sidescroll=1
134 set sidescrolloff=3
135 set scrolloff=3
136 set listchars+=extends:»,precedes:«,trail:-,nbsp:_,tab:\|_
137 " set fillchars+=vert:\▏
138 set wildmenu
139
140 " piro: fix broken Page Up/Down
141 " http://vimrc-dissection.blogspot.com/2009/02/fixing-pageup-and-pagedown.html
142 map <silent> <PageUp> 1000<C-U>
143 map <silent> <PageDown> 1000<C-D>
144 imap <silent> <PageUp> <C-O>1000<C-U>
145 imap <silent> <PageDown> <C-O>1000<C-D>
146 set nostartofline
147
148 " bernie: enter in directory browser open files in previous window
149 " let g:netrw_browse_split=4
150
151 " bernie: write on :n, :r, etc.
152 set autowriteall
153
154 " aleph: dont't break softlinks (edit destination file), but break hardlinks
155 set backupcopy=yes,breakhardlink
156
157 " bernie: mouse everywhere!
158 if has("mouse")
159   set mouse=a
160   if !has('nvim')
161     set ttymouse=xterm2
162   endif
163 endif
164
165 " bernie: do not create swap files all over the place
166 set directory-=.
167
168 " bernie: enable persistent undo
169 "if has('persistent_undo')
170 "  let &undodir=&directory
171 "  set undofile
172 "endif
173
174 " aleph: per non rompere le p*** a chi sta attorno ogni volta che si sbaglia tasto
175 set visualbell
176 " aleph: riduce al minimo la dimensione dei buffer non attivi
177 set winminheight=0
178 " aleph: dopo split e close gli altri buffer non si ridimensionano
179 set noequalalways
180 " show (partial) command in status line
181 set showcmd
182
183 " bernie: status line
184 set statusline=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P
185
186 " informs sh syntax that /bin/sh is actually bash
187 let is_bash=1
188
189 " bernie: enable loading filetype specific plugins and indendation modes
190 filetype plugin indent on
191 set smarttab
192 set matchpairs+=<:>
193 set shiftround
194 set shiftwidth=0  " 0 means same as ts
195
196 " bernie: set default indents for various languages
197 autocmd FileType c,cpp                  set ts=4|set expandtab|let c_space_errors=1
198 autocmd FileType java                   set ts=4|set expandtab|let java_space_errors=1|let java_highlight_functions=1
199 autocmd FileType rust                   set ts=4|set expandtab
200 autocmd FileType python                 set ts=4|set expandtab
201 autocmd FileType go,lua                 set ts=2|set expandtab
202 autocmd FileType html,css               set ts=2|set expandtab
203 autocmd FileType javascript,typescript  set ts=2|set expandtab
204 autocmd FileType vim                    set ts=2|set expandtab
205
206 " bernie: auxiliary named config files
207 au BufNewFile,BufRead named.conf.*,named-*.conf setf named
208
209 " piro: treat arduino projects as C++ files.
210 autocmd BufRead *.pde set filetype=cpp
211
212 " bernie: bind '#' to 'grep word under cursor' -- see: http://vim.wikia.com/wiki/Find_in_files_within_Vim
213 :map # :execute "vimgrep /" . expand("<cword>") . "/j **" <Bar> cw<CR>
214
215 " bernie: search for highlighted text -- see: http://rayninfo.co.uk/vimtips.html
216 :vmap // y/<C-R>"<CR>
217
218 " piro: no, I don't want your fucking help!
219 inoremap <F1> <ESC>
220 nnoremap <F1> <ESC>
221 vnoremap <F1> <ESC>
222
223 " what's ; for anyway?
224 noremap ; :
225
226 " w!! if you forget to sudo before saving
227 cmap w!! w !sudo tee % >/dev/null
228
229 " Repeat last command and put cursor at start of change -- http://vim.wikia.com/wiki/VimTip1142
230 map . .`[
231
232 " Go back to previous file
233 map <C-p> <esc>:bp<CR>
234
235 " bernie: see http://www.vim.org/scripts/script.php?script_id=3896
236 map <F2> :Bufferlist<CR>
237
238 " bernie: ex mode is useless and annoying
239 map Q <Nop>
240
241 " bernie: http://vim.wikia.com/wiki/Edit_gpg_encrypted_files#Comments
242 augroup encrypted
243   au!
244   " Disable swap files, and set binary file format before reading the file
245   autocmd BufReadPre,FileReadPre *.gpg
246     \ setlocal noswapfile bin
247   " Decrypt the contents after reading the file, reset binary file format
248   " and run any BufReadPost autocmds matching the file name without the .gpg
249   " extension
250   autocmd BufReadPost,FileReadPost *.gpg
251     \ execute "'[,']!gpg --decrypt --default-recipient-self" |
252     \ setlocal nobin |
253     \ execute "doautocmd BufReadPost " . expand("%:r")
254   " Set binary file format and encrypt the contents before writing the file
255   autocmd BufWritePre,FileWritePre *.gpg
256     \ setlocal bin |
257     \ '[,']!gpg --encrypt --default-recipient-self
258   " After writing the file, do an :undo to revert the encryption in the
259   " buffer, and reset binary file format
260   autocmd BufWritePost,FileWritePost *.gpg
261     \ silent u |
262     \ setlocal nobin
263 augroup END
264
265 set updatetime=1000
266 set shortmess+=c
267
268 if has('persistent_undo')
269   let &undodir=&directory
270   set undofile
271 endif
272
273 let g:plug_url_format = 'git@github.com:%s.git'
274 call plug#begin('~/.vim/plugged')
275   Plug 'wsdjeg/vim-fetch'
276   "Plug 'editorconfig/editorconfig-vim'
277   Plug 'junegunn/fzf'
278   Plug 'junegunn/fzf.vim'
279   Plug 'haya14busa/vim-asterisk'
280   Plug 'tikhomirov/vim-glsl'
281   Plug 'tpope/vim-fugitive'
282 call plug#end()
283
284 " == FZF ==
285 nmap <C-P> :FZF<CR>
286
287
288 " == vim-asterisk ==
289 let g:asterisk#keeppos = 1
290 map *  <Plug>(asterisk-*)
291 map #  <Plug>(asterisk-#)
292 map g* <Plug>(asterisk-g*)
293 map g# <Plug>(asterisk-g#)
294 map z*  <Plug>(asterisk-z*)
295 map gz* <Plug>(asterisk-gz*)
296 map z#  <Plug>(asterisk-z#)
297 map gz# <Plug>(asterisk-gz#)
298
299
300 " == rust.vim ==
301 autocmd FileType rust noremap <C-I> gq
302 autocmd FileType rust inoremap <C-K> <C-O>gq
303
304 if has('nvim')
305   set inccommand=nosplit
306   set signcolumn=number
307 endif " nvim
308
309 " source user's local configuration file if available
310 if filereadable($HOME . "/.vimrc.local")
311   source ~/.vimrc.local
312 endif