diff options
Diffstat (limited to 'vimrc')
-rw-r--r--[l---------] | vimrc | 392 |
1 files changed, 391 insertions, 1 deletions
@@ -1 +1,391 @@ | |||
1 | vimrc-full \ No newline at end of file | 1 | "======================================================================================================================= |
2 | " GENERAL | ||
3 | "======================================================================================================================= | ||
4 | set termguicolors | ||
5 | |||
6 | filetype on | ||
7 | filetype plugin on | ||
8 | filetype indent on | ||
9 | |||
10 | syntax on | " enable syntax highlighting | ||
11 | syntax sync minlines=60 | " how many preceding lines will be parsed? (high performance impact) | ||
12 | |||
13 | set secure | " to ensure, that modelines do not contain executable code | ||
14 | set noexrc | " exrc was nice, but has too many security problems. Now using editorconfig instead (see plugins) | ||
15 | set modeline | " set variables specific to a file, like indentation by adding a comment (TODO: should probably be replaced by editorconfig) | ||
16 | set virtualedit=all | " virtual edit should be default behaviour, because I don't see any reason against | ||
17 | set nonumber norelativenumber | " do not show numbers by default, because that causes a performance loss, instead activate them on a file type basis | ||
18 | set ignorecase smartcase | " search with ignore case by default, but use case sensitive search when one capital char is contained and highlight while typing (even though its slower) | ||
19 | set hlsearch incsearch | " highlight pattern while entering it (performance wise this isn't that good) | ||
20 | |||
21 | |||
22 | "======================================================================================================================= | ||
23 | " BASIC CODE STYLE | ||
24 | "======================================================================================================================= | ||
25 | " set cindent cinoptions+=(0 | " indents at the level of parentheses -- if desired | ||
26 | set expandtab | " replace tabs with spaces | ||
27 | set textwidth=0 | " should be set file type specific, colorcolumns is there to assist anyways | ||
28 | |||
29 | set tabstop=2 | " I am sorry, but 2 is simply better | ||
30 | set shiftwidth=2 | " . | ||
31 | set softtabstop=2 | " . | ||
32 | |||
33 | "======================================================================================================================= | ||
34 | " PATH -- where to search for includes (e.g. `gf` or `:find`) | ||
35 | "======================================================================================================================= | ||
36 | set path+=**4 | " allow recursive searches for files (limit depth by 4) | ||
37 | if executable("uname") " does not work under Windows | ||
38 | let &path = &path.",/usr/lib/modules/".substitute(system('uname -r'), "\n", "", "")."/build/include" | ||
39 | endif | ||
40 | |||
41 | if filereadable("/bin/bash") | ||
42 | set shell=/bin/bash | ||
43 | elseif filereadable("/usr/local/bin/bash") | ||
44 | set shell=/usr/local/bin/bash | ||
45 | elseif has("win32") | ||
46 | set shell="cmd.exe" | ||
47 | endif | ||
48 | |||
49 | " ====================================================================================================================== | ||
50 | " SETTINGS: | ||
51 | " ====================================================================================================================== | ||
52 | set breakindent | " Every wrapped line will continue visually indented | ||
53 | set clipboard=unnamedplus | " makes copy and paste work (autoselectplus might work as well) | ||
54 | set concealcursor=nc | " limits the display of concealed text to normal and command mode | ||
55 | set conceallevel=2 | " replace escaped chars by their UTF-8 representation (useful for LaTeX) | ||
56 | set confirm | " asks 'do you want to save?' | ||
57 | set cpoptions+=P | " makes :w filename set the current buffer to filename | ||
58 | set hidden | " allows switching buffers even if the current buffer contains changes (displays +) | ||
59 | set linebreak | " wrap long lines at char 'breakat', not inside words | ||
60 | set mousemodel=popup | " only in gvim: right click opens a pop-up-menu | ||
61 | set mouse=n | " allow mouse in normal mode only, so one can use the terminals c&p feature in insert mode | ||
62 | set noautochdir | " When on, Vim will change the current working directory | ||
63 | set nostartofline | " when scrolling: do not move the cursor to column 1 | ||
64 | set nowrap | " but do not (by default) wrap long lines around | ||
65 | set nrformats+=alpha | " allows CTRL-A & CTRL-X to increment and decrement letters, not just numbers | ||
66 | |||
67 | set pumheight=8 | " Determines the maximum number of items to show in the pop-up menu for | ||
68 | set scrolljump=4 | " how many lines get scrolled into view when cursor reaches the screens edge | ||
69 | set scrolloff=4 | " keeps cursor centered | ||
70 | set shiftround | " indent/un-indent snaps to multiple of shiftwidths | ||
71 | set writedelay=0 | ||
72 | |||
73 | " display and performance | ||
74 | set lazyredraw | " disables redraw during macro execution (improves performance, but causes problems with solid backgrounds) | ||
75 | set cmdheight=2 | " sets the command line's height | ||
76 | set signcolumn=yes | " auto=auto hide, yes=always, no=never show the column with error indicators | ||
77 | set nocursorcolumn | " turn visual cursor column off (improves performance) | ||
78 | set updatetime=80 | " updates the screen more often | ||
79 | set redrawtime=1500 | " Timeout in milliseconds for redrawing the screen (switches syntax off when ssh too slow) / CTRL+L to retry | ||
80 | set notimeout | " improves performance but is known to cause problems on slow terminals | ||
81 | set ttimeout ttimeoutlen=150 | " set Esc key timeout in ms- | ||
82 | set showcmd | " essential: show keys of combined commands in the lower right corner (BUT SLOW, makes cursor flickering) | ||
83 | set showtabline=2 | " 0: never, 1: only if there are at least two tabs, 2:always | ||
84 | set shortmess+=I | " don't give the intro message when starting Vim |:intro|. | ||
85 | set wildmenu | " use a menu in the command line | ||
86 | set wildmode=longest:full | " do not preselect any entry and show all possible | ||
87 | |||
88 | " code completion | ||
89 | " set dictionary=/usr/share/dict/cracklib-small | ||
90 | set isfname-== | " remove = as char in filenames, because most FSs do not support it | ||
91 | set complete+=d | " scan current and included files for defined name or macro | ||
92 | set complete+=i | " scan current and included files for completions | ||
93 | set complete+=k | " make default completer <C-N> respect the dictionary | ||
94 | set complete-=u | " scan current and included files | ||
95 | set complete+=i | " scan current and included files | ||
96 | set complete+=d | " scan current and included files for defined name or macro | ||
97 | " set complete=d | " scan current and included files for defined name or macro | ||
98 | set completeopt+=noinsert | " Do not insert any text for a match until the user selects one | ||
99 | set completeopt+=noselect | " Do not select a completion from the menu, let the user do that | ||
100 | set tagcase=match | " tagcase match, because we mostly use ^] to jump around and that variant respects the upper/lower case [followscs, followic, match, ignore] | ||
101 | set tags+=../tags | ||
102 | |||
103 | " code folding... | ||
104 | set nofoldenable | " disable folding, because we have zi to toggle foldenable :) | ||
105 | set foldclose=all | " automatically fold, when the cursor leaves the folded area | ||
106 | set foldcolumn=0 | " I think I don't need this second indicator | ||
107 | " set numberwidth=5 | ||
108 | " set foldmethod=syntax | " foldlevel: syntax, indent, manual / foldmethod=syntax makes Vim incredible slow | ||
109 | set foldnestmax=1 | " top level folding only | ||
110 | set foldopen=block,hor,search | " when do we unfold? | ||
111 | " set foldtext=printf('%*s%.*S',indent(v:foldstart),'',&textwidth-indent(v:foldstart),substitute(substitute(join(getline(v:foldstart,v:foldend),'\ '),'[[:space:]*/]\\+','\ ','g'),'^[[:space:]*]','','g')) | ||
112 | set foldtext=repeat('\ ',indent(v:foldstart)-1).join(getline(v:foldstart,v:foldend))[:winwidth(0)]->substitute('[[:space:]]\\+','\ ','g') | ||
113 | |||
114 | " works ... | ||
115 | " set foldexpr=match(synIDattr(synID(v:lnum,indent(v:lnum)+1,0),'name'),'Comment')>-1 | ||
116 | set foldexpr=!empty(filter(synstack(v:lnum,indent(v:lnum)+1),{_,val->match(synIDattr(val,'name'),'Comment')>-1})) | ||
117 | |||
118 | " vim window behaviour | ||
119 | set splitbelow | " open new windows below the current one (i find that more intuitive) | ||
120 | set splitright | " this also works for me and makes better use of the scren space I think | ||
121 | set winminwidth=0 | " (and all other windows, so TODO: watch out) | ||
122 | set winwidth=30 | " keep NERDTreeWindow at least this size | ||
123 | |||
124 | " vim session handling and restore behaviour | ||
125 | set viminfo+=% | " restore buffer list | ||
126 | set sessionoptions= | ||
127 | set sessionoptions+=buffers | ||
128 | set sessionoptions+=curdir | ||
129 | set sessionoptions+=folds | ||
130 | set sessionoptions+=resize | ||
131 | set sessionoptions+=slash | ||
132 | set sessionoptions+=tabpages | ||
133 | set sessionoptions+=unix | ||
134 | set sessionoptions+=winpos | ||
135 | set sessionoptions+=winsize | ||
136 | |||
137 | " set nocindent smartindent | " use smart indent rather then cindent | ||
138 | set noautoindent | ||
139 | set nosmartindent | ||
140 | |||
141 | set noshiftround | " indent/un-indent sna=ps to multiple of shiftwidths | ||
142 | set noequalalways | " do not evenly size windows when opening new or closing old | ||
143 | set nocursorline | " turn visual cursor line off (improves performance) | ||
144 | |||
145 | "======================================================================================================================= | ||
146 | " SPELL_CHECKING: | ||
147 | "======================================================================================================================= | ||
148 | let g:spellfile_URL = 'http://ftp.vim.org/vim/runtime/spell' | ||
149 | " add local user default spell file as primary source for words | ||
150 | let &spellfile=fnamemodify($MYVIMRC, ":p:h")."/spell/spellfile-user.UTF-8.add" | ||
151 | |||
152 | set nospell | " disable spell checker by default | ||
153 | set spelllang=en,de | " languages for the spell checker | ||
154 | set spellsuggest=10 | " how many words will z= suggest? | ||
155 | set thesaurus+=~/.vim/thesaurus/php.txt | ||
156 | |||
157 | if &diff " only for diff mode/vimdiff | ||
158 | set diffopt=filler,context:1000000 " filler is default and inserts empty lines for sync | ||
159 | set foldmethod=syntax | ||
160 | endif | ||
161 | |||
162 | "======================================================================================================================= | ||
163 | " UNDO: | ||
164 | " Persistent undo behaviour, also keeps undo history between starts | ||
165 | "======================================================================================================================= | ||
166 | if has('persistent_undo') | ||
167 | if isdirectory('/dev/shm') | ||
168 | set undodir=/dev/shm/ | " save undo file in memory. That is volatile, but fast and we have GIT for longer lasting undoes | ||
169 | set directory=/dev/shm/ | " swap file directory to RAM | ||
170 | set swapfile | ||
171 | elseif isdirectory('/tmp/') | ||
172 | set undodir=/tmp/ | ||
173 | endif | ||
174 | set undofile | " preserve undo history when closing and reopening buffers (see :help undo-persistence) | ||
175 | endif | ||
176 | |||
177 | |||
178 | "======================================================================================================================= | ||
179 | " DISPLAY & MULTI_BYTE | ||
180 | "======================================================================================================================= | ||
181 | if has("multi_byte") | ||
182 | scriptencoding utf-8 | " tell vim that we are using UTF-8 here | ||
183 | set encoding=utf-8 | " we need default UTF-8 encoding to use cool chars as line break and so on (see below) | ||
184 | set termencoding=utf-8 | " we just assume that this is supported. | ||
185 | |||
186 | set fillchars= | " initialize empty fillchars | ||
187 | set listchars= | " initialize empty listchars | ||
188 | |||
189 | if &term ==# 'linux' | ||
190 | set fillchars+=vert:\│ | " cool vertical split char | ||
191 | else | ||
192 | set fillchars+=vert:\║ | " cool vertical split char | ||
193 | endif | ||
194 | |||
195 | set fillchars+=fold:\ | " | ||
196 | set fillchars+=diff:\ | " a white space gets used here | ||
197 | |||
198 | set listchars+=extends:» | " symbols used when using :set list (which displays non-printable chars) | ||
199 | set listchars+=precedes:« | " symbols used when using :set list (which displays non-printable chars) | ||
200 | |||
201 | set listchars+=tab:▏\ | " | ||
202 | set listchars+=trail:· | " symbols used when using :set list (which displays non-printable chars) | ||
203 | " set listchars+=eol:↲ | " symbols used when using :set list (which displays non-printable chars) | ||
204 | " set listchars+=space:⸳ | " · | " symbols used when using :set list (which displays non-printable chars) | ||
205 | set showbreak+=› | " symbol used in the beginning of a wrapped line | ||
206 | |||
207 | " automatically enter list mode when going in insert mode (makes above syntax command temporarily ineffective) | ||
208 | set nolist | ||
209 | |||
210 | autocmd InsertEnter * set list | ||
211 | autocmd InsertLeave * set list& | ||
212 | |||
213 | autocmd InsertEnter * set colorcolumn=80,120 | ||
214 | autocmd InsertLeave * set colorcolumn& | ||
215 | " set fillchars+=stlnc:\― | " | ||
216 | end | ||
217 | |||
218 | |||
219 | "======================================================================================================================= | ||
220 | " AUTOCMDs and FileType specific stuff | ||
221 | "======================================================================================================================= | ||
222 | if has("autocmd") | ||
223 | " use the shada/viminfo file to return the cursor to where it was... | ||
224 | autocmd BufWinEnter * if &previewwindow | setlocal nonumber nolist signcolumn=no filetype=c nobuflisted | endif | ||
225 | |||
226 | " Workaround: Allows Vim to yank text within wayland | ||
227 | " XDG_SESSION_TYPE is only set if a login manager was used | ||
228 | " WAYLAND_DISPLAY should always work | ||
229 | " if ($XDG_SESSION_TYPE ==# 'wayland' || ! empty($WAYLAND_DISPLAY)) && !has('nvim') | ||
230 | " autocmd TextYankPost * call system("wl-copy", getreg('+')) | ||
231 | " endif | ||
232 | |||
233 | autocmd TextYankPost * echo '> text yanked to '. | ||
234 | \ (get(v:event,'regname') == '' | ||
235 | \ ? 'default register' | ||
236 | \ : 'register '.get(v:event,'regname')) | ||
237 | |||
238 | |||
239 | autocmd InsertLeave * silent! call matchadd('Convention', ' \+$', -1, 101, { 'conceal': '⟶' }) | ||
240 | autocmd InsertEnter * silent! call matchdelete(101) | ||
241 | |||
242 | |||
243 | "==================================================================================================================== | ||
244 | augroup FILETYPES | ||
245 | " indent within <script> and <style> (default is a zero indent) | ||
246 | let g:html_indent_script1 = "inc" | ||
247 | let g:html_indent_style1 = "inc" | ||
248 | |||
249 | " let g:loaded_ruby_provider = 1 " disable ruby support | ||
250 | " let g:loaded_python_provider = 1 " disable python 3 | ||
251 | |||
252 | let g:LatexBox_latexmk_preview_continuously = 1 | ||
253 | let g:LatexBox_viewer = "evince" | ||
254 | |||
255 | autocmd FileType python setlocal keywordprg=pydoc | ||
256 | autocmd FileType vim setlocal keywordprg=:help |. | ||
257 | autocmd FileType conf setlocal isfname-== | ||
258 | autocmd Filetype css command! CSSsort :g/{/+1;/}/-1 sort | ||
259 | autocmd Filetype html,markdown,xml iabbrev </ </<C-X><C-O> | ||
260 | |||
261 | autocmd Filetype html,htmldjango,xml | ||
262 | \ :nnoremap | ||
263 | \ <M-Down> | ||
264 | \ :call search('^ *<', 'e')<CR>:nohlsearch<CR>| | ||
265 | \ :nnoremap | ||
266 | \ <M-Up> | ||
267 | \ :call search('^ *<', 'eb')<CR>:nohlsearch<CR>| | ||
268 | \ :nnoremap | ||
269 | \ <leader>= | ||
270 | \ vat:'<,'>!tidy -xml --wrap 0 --sort-attributes alpha 2>/dev/null<CR>vat= | ||
271 | augroup END | ||
272 | endif | ||
273 | |||
274 | " ====================================================================================================================== | ||
275 | augroup CUSTOM_COMMANDS | ||
276 | command! Qfls call setqflist([],'r',{ 'title':'listed buffers', 'items':map(getbufinfo({"buflisted":1}), '{"bufnr":get(v:val,"bufnr"),"lnum":get(v:val,"lnum"),"module":printf("%-*s",winwidth(0)-4,fnamemodify(get(v:val,"name"),":t"))}') }) | ||
277 | command! Ctoggle | ||
278 | \ if(get(getqflist({'winid':1}), 'winid') == win_getid())|cclose|else|botright copen|endif | ||
279 | command! Ltoggle | ||
280 | \ if(get(getloclist(0, {'winid':1}), 'winid') == win_getid())|lclose|else|lopen|endif | ||
281 | command! BuffersToArg :exec ':args '.join(map(range(0, bufnr('$')), 'fnameescape(fnamemodify(bufname(v:val), ":."))')) | ||
282 | command! BufToArg :argadd %:. | ||
283 | command! Gbranch call setqflist([], 'r', {'title':'Git branch selector','items':map(systemlist("git branch"), {_, p->{'filename':'branch','module': fnamemodify(p, ':.')}})}) | ||
284 | " the following command opens a preview-window and shows the declaration of | ||
285 | " the function under the cursor. It also highlights the word to make it easier | ||
286 | " to spot within a great file | ||
287 | command! Helpme au! CursorHold * nested let @/=expand('<cword>')|exe "silent! psearch ".expand("<cword>") | ||
288 | command! FindInAllBuffers cex [] | bufdo vimgrepadd //g % | cw | ||
289 | augroup END | ||
290 | |||
291 | "======================================================================================================================= | ||
292 | augroup KEYBOARD_MAPPING | ||
293 | " map CTRL-PageUp/Down to next/previous buffer | ||
294 | " and Shift-PageUp/Down to next/previous arglist file | ||
295 | nnoremap <C-PageUp> :bn<CR> | ||
296 | nnoremap <C-PageDown> :bp<CR> | ||
297 | nnoremap <S-PageUp> :N<CR> | ||
298 | nnoremap <S-PageDown> :n<CR> | ||
299 | |||
300 | nnoremap <F4> :wincmd c<CR> | ||
301 | nnoremap <F5> :make!<CR> | ||
302 | nnoremap <F6> :silent syntax sync fromstart<CR>:nohlsearch<CR>:silent match<CR>:silent 2match<CR>:silent 3match<CR> | ||
303 | nnoremap <F7> :Ltoggle<CR> | ||
304 | nnoremap <F8> :Ctoggle<CR> | ||
305 | nnoremap <F9> :TagbarToggle<CR> | ||
306 | "" remap <..> | ||
307 | nnoremap <F12> :Qfls<CR>:Ctoggle<CR> | ||
308 | |||
309 | " close current buffer with <leader>q... | ||
310 | nnoremap <leader>q :bp<bar>sp<bar>bn<bar>bd<CR>. | ||
311 | nnoremap <leader>r :syntax sync fromstart | ||
312 | |||
313 | nnoremap <silent> <A-Up> :wincmd k<CR> | ||
314 | nnoremap <silent> <A-Down> :wincmd j<CR> | ||
315 | nnoremap <silent> <A-Left> :wincmd h<CR> | ||
316 | nnoremap <silent> <A-Right> :wincmd l<CR> | ||
317 | |||
318 | |||
319 | inoremap <C-S> <C-O>:w<CR> | ||
320 | |||
321 | " exec current line as a command, insert output of command (from: https://youtu.be/MquaityA1SM?t=35m45s) | ||
322 | nnoremap <leader>Q !!$SHELL<CR> | ||
323 | " google the word under the cursor | ||
324 | nnoremap <leader>g :execute ":!xdg-open https://google.de/search?q=".expand("<cword>")<CR> | ||
325 | nnoremap <leader>u :execute ":!xdg-open ".expand("<cWORD>")<CR> | ||
326 | " display highlight group under the cursor | ||
327 | nnoremap <leader>h :echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')<CR> | ||
328 | |||
329 | |||
330 | " ====================================================================================================================== | ||
331 | " SHORTCUTS: custom shortcuts | ||
332 | " inoremap <C-Space> <C-x><C-o> | ||
333 | " inoremap <C-@> <C-Space> | ||
334 | |||
335 | " Bind CTRL+Backspace to vim's version (CTRL+W) in " <CR> insert mode (only works with gvim) | ||
336 | inoremap <C-Backspace> <C-W> | ||
337 | |||
338 | " INDENTATION: allows un-indenting a selected block and keeps selection | ||
339 | vnoremap < <gv | ||
340 | vnoremap > >gv | ||
341 | |||
342 | " make shift-home select to the beginning of the line | ||
343 | nnoremap <s-home> v^ | ||
344 | nnoremap <s-end> v$ | ||
345 | |||
346 | nnoremap <s-down> vj | ||
347 | vnoremap <s-down> j | ||
348 | nnoremap <s-up> vk | ||
349 | vnoremap <s-up> k | ||
350 | |||
351 | " if the wildmenu is configured to to display suggestions vertically, then | ||
352 | " reconfigure the cursor keys to work in that direction | ||
353 | if &wildoptions =~# 'pum' | ||
354 | cnoremap <expr> <up> pumvisible() ? "<C-p>" : "\<up>" | ||
355 | cnoremap <expr> <down> pumvisible() ? "<C-n>" : "\<down>" | ||
356 | endif | ||
357 | |||
358 | |||
359 | " INSERT_MODE_MAPPINGS: | ||
360 | " default copy&paste insert key binding (just in insert mode, so it doesn't conflict | ||
361 | " with visual block mode)- would have been nice, but collides with c-w for digraphs | ||
362 | " inoremap <C-V> <C-R>+ | ||
363 | |||
364 | " NEOVIM_SPECIFIC: | ||
365 | if has('nvim') " only neovim... | ||
366 | " shortcut \t opens a terminal in a horizontal split | ||
367 | nnoremap <leader>t :new +terminal<CR> | ||
368 | endif | ||
369 | augroup END | ||
370 | |||
371 | augroup NETRW | ||
372 | " Deprecated with this configuration, but still useful when deactivating some Plugins | ||
373 | " NETRW: obsolete with NERDTree | ||
374 | let g:netrw_alto = 0 | " open files on the right | ||
375 | let g:netrw_altv = 1 | " open files on the right | ||
376 | let g:netrw_banner = 0 | " display help messages? | ||
377 | let g:netrw_browse_split = 4 | " 4=open in previous window | ||
378 | let g:netrw_fastbrowse = 2 | " manually refresh direcory list (avoids display errors) | ||
379 | let g:netrw_hide = 1 | " show not-hidden files only | ||
380 | let g:netrw_keepdir = 1 | " because that works better, when gf finds a path name | ||
381 | let g:netrw_list_hide = '^\..*' | " Explore mode: hide files starting with dot | ||
382 | let g:netrw_liststyle = 3 | " 3=tree | ||
383 | let g:netrw_preview = 0 | " | ||
384 | let g:netrw_winsize = 20 | " window size in percent | ||
385 | " let s:treedepthstring = "│ " | " this is not going to work, but left here for documentation | ||
386 | augroup END | ||
387 | |||
388 | |||
389 | "======================================================================================================================= | ||
390 | " v modeline, do not chnage v | ||
391 | " vim: noai:ts=2:sw=2:sts=2 iskeyword+=\:\<,\>,\-,\& number | ||