aboutsummaryrefslogtreecommitdiff
path: root/vimrc-common
diff options
context:
space:
mode:
authorMax Christian Pohle2023-10-21 02:32:31 +0200
committerMax Christian Pohle2023-10-21 02:32:31 +0200
commit66f713050c69bf88706d8d17ed2e32c73b12ee57 (patch)
tree35976b23f2e9afd7b0c6aca389117b12ef6dfb5d /vimrc-common
parent3efb1546b256c620da3ea70c8c717e55cce0b3b2 (diff)
downloadvim-66f713050c69bf88706d8d17ed2e32c73b12ee57.tar.bz2
vim-66f713050c69bf88706d8d17ed2e32c73b12ee57.zip
Improved code folding, because tree-sitter broke it
Diffstat (limited to 'vimrc-common')
-rw-r--r--vimrc-common197
1 files changed, 97 insertions, 100 deletions
diff --git a/vimrc-common b/vimrc-common
index fb760cb..dc48045 100644
--- a/vimrc-common
+++ b/vimrc-common
@@ -1,7 +1,5 @@
1"======================================================================================================================= 1"=======================================================================================================================
2" GENERAL: 2" GENERAL
3" It is likely, that you will want to overwrite these settings with a
4" project-local .vimrc file (activated with exrc setting)
5"======================================================================================================================= 3"=======================================================================================================================
6 4
7filetype on 5filetype on
@@ -9,97 +7,28 @@ filetype plugin on
9filetype indent on 7filetype indent on
10 8
11syntax on | " enable syntax highlighting 9syntax on | " enable syntax highlighting
12syntax sync minlines=60 | " how many preceding lines will be parsed? (has performance impact) 10syntax sync minlines=60 | " how many preceding lines will be parsed? (high performance impact)
13 11
14set secure | " to ensure, that modelines do not contain executable code 12set secure | " to ensure, that modelines do not contain executable code
15set noexrc | " exrc was nice, but has too many security problems. Now using editorconfig instead (see plugins) 13set noexrc | " exrc was nice, but has too many security problems. Now using editorconfig instead (see plugins)
16set modeline | " set variables specific to a file, like indentation by adding a comment (TODO: should probably be replaced by editorconfig) 14set modeline | " set variables specific to a file, like indentation by adding a comment (TODO: should probably be replaced by editorconfig)
17set ts=4 sts=4 sw=4 expandtab textwidth=0 | " better done with a modeline or local exrc
18set virtualedit=all | " virtual edit should be default behaviour, because I don't see any reason against 15set virtualedit=all | " virtual edit should be default behaviour, because I don't see any reason against
19set nonumber norelativenumber | " do not show numbers by default, because that causes a performance loss, instead activate them on a file type basis 16set nonumber norelativenumber | " do not show numbers by default, because that causes a performance loss, instead activate them on a file type basis
20set 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) 17set 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)
21set hlsearch incsearch | " highlight pattern while entering it (performance wise this isn't that good) 18set hlsearch incsearch | " highlight pattern while entering it (performance wise this isn't that good)
22" set cindent cinoptions+=(0 | " indent at parentheses
23 19
24 20
25"======================================================================================================================= 21"=======================================================================================================================
26" PATH -- where to search for includes (e.g. `gf` or `:find`) 22" BASIC CODE STYLE
27"=======================================================================================================================
28set path+=**4 | " allow recursive searches for files (limit depth by 4)
29let &path = &path.",/usr/lib/modules/".substitute(system('uname -r'), "\n", "", "")."/build/include" | " TODO: could fail under windows (no uname)
30
31"=======================================================================================================================
32" SPELL_CHECKING:
33"=======================================================================================================================
34let g:spellfile_URL='http://ftp.vim.org/vim/runtime/spell'
35" add local user default spell file as primary source for words
36let &spellfile=fnamemodify($MYVIMRC, ":p:h")."/spell/spellfile-user.UTF-8.add"
37
38set nospell | " disable spell checker by default
39set spelllang=en,de | " languages for the spell checker
40set spellsuggest=10 | " how many words will z= suggest?
41set thesaurus+=~/.vim/thesaurus/php.txt
42
43
44"=======================================================================================================================
45" UNDO:
46" Persistent undo behaviour, also keeps undo history between starts
47"=======================================================================================================================
48if has('persistent_undo')
49 if isdirectory('/dev/shm')
50 set undodir=/dev/shm/ | " save undo file in memory. That is volatile, but fast and we have GIT for longer lasting undoes
51 set directory=/dev/shm/ | " swap file directory to RAM
52 set swapfile
53 elseif isdirectory('/tmp/')
54 set undodir=/tmp/
55 endif
56 set undofile | " preserve undo history when closing and reopening buffers (see :help undo-persistence)
57endif
58
59
60"=======================================================================================================================
61" MULTI_BYTE:
62"======================================================================================================================= 23"=======================================================================================================================
63if has("multi_byte") 24" set cindent cinoptions+=(0 | " indents at the level of parentheses -- if desired
64 scriptencoding utf-8 | " tell vim that we are using UTF-8 here 25set expandtab | " replace tabs with spaces
65 set encoding=utf-8 | " we need default UTF-8 encoding to use cool chars as line break and so on (see below) 26set textwidth=0 | " should be set file type specific, colorcolumns is there to assist anyways
66 set termencoding=utf-8 | " we just assume that this is supported. 27set tabstop=4
67 28set shiftwidth=4
68 set fillchars= | " initialize empty fillchars 29set softtabstop=4
69 set listchars= | " initialize empty listchars
70
71 if &term ==# 'linux'
72 set fillchars+=vert:\│ | " cool vertical split char
73 else
74 set fillchars+=vert:\║ | " cool vertical split char
75 endif
76
77 set fillchars+=fold:\ | "
78 set fillchars+=diff:\ | " a white space gets used here
79
80 set listchars+=extends:» | " symbols used when using :set list (which displays non-printable chars)
81 set listchars+=precedes:« | " symbols used when using :set list (which displays non-printable chars)
82
83 set listchars+=tab:▏\ | "
84 set listchars+=trail:· | " symbols used when using :set list (which displays non-printable chars)
85 " set listchars+=eol:↲ | " symbols used when using :set list (which displays non-printable chars)
86 " set listchars+=space:⸳ | " · | " symbols used when using :set list (which displays non-printable chars)
87 set showbreak+=› | " symbol used in the beginning of a wrapped line
88
89 " automatically enter list mode when going in insert mode (makes above syntax command temporarily ineffective)
90 set nolist
91
92 autocmd InsertEnter * set list
93 autocmd InsertLeave * set list&
94
95
96 autocmd InsertEnter * set colorcolumn=80,120
97 autocmd InsertLeave * set colorcolumn&
98 30
99 31
100 " set fillchars+=stlnc:\― | "
101end
102
103" ====================================================================================================================== 32" ======================================================================================================================
104" SETTINGS: 33" SETTINGS:
105" ====================================================================================================================== 34" ======================================================================================================================
@@ -144,7 +73,7 @@ set writedelay=0
144" display and performance 73" display and performance
145set lazyredraw | " disables redraw during macro execution (improves performance, but causes problems with solid backgrounds) 74set lazyredraw | " disables redraw during macro execution (improves performance, but causes problems with solid backgrounds)
146set cmdheight=2 | " sets the command line's height 75set cmdheight=2 | " sets the command line's height
147set signcolumn=auto | " auto=auto hide, yes=always, no=never show the column with error indicators 76set signcolumn=yes | " auto=auto hide, yes=always, no=never show the column with error indicators
148set nocursorcolumn | " turn visual cursor column off (improves performance) 77set nocursorcolumn | " turn visual cursor column off (improves performance)
149set updatetime=80 | " updates the screen more often 78set updatetime=80 | " updates the screen more often
150set redrawtime=1500 | " Timeout in milliseconds for redrawing the screen (switches syntax off when ssh too slow) / CTRL+L to retry 79set redrawtime=1500 | " Timeout in milliseconds for redrawing the screen (switches syntax off when ssh too slow) / CTRL+L to retry
@@ -158,6 +87,7 @@ set wildmode=longest:full | " do not preselect any entry and show all possib
158 87
159" code completion 88" code completion
160" set dictionary=/usr/share/dict/cracklib-small 89" set dictionary=/usr/share/dict/cracklib-small
90set isfname-== | " remove = as char in filenames, because most FSs do not support it
161set complete+=d | " scan current and included files for defined name or macro 91set complete+=d | " scan current and included files for defined name or macro
162set complete+=i | " scan current and included files for completions 92set complete+=i | " scan current and included files for completions
163set complete+=k | " make default completer <C-N> respect the dictionary 93set complete+=k | " make default completer <C-N> respect the dictionary
@@ -178,20 +108,19 @@ set foldcolumn=0 | " I think I don't need this second indicator
178" set foldmethod=syntax | " foldlevel: syntax, indent, manual / foldmethod=syntax makes Vim incredible slow 108" set foldmethod=syntax | " foldlevel: syntax, indent, manual / foldmethod=syntax makes Vim incredible slow
179set foldnestmax=1 | " top level folding only 109set foldnestmax=1 | " top level folding only
180set foldopen=block,hor,search | " when do we unfold? 110set foldopen=block,hor,search | " when do we unfold?
181set foldtext=printf('%*s%.*S',indent(v:foldstart),'',&textwidth-indent(v:foldstart),substitute(substitute(join(getline(v:foldstart,v:foldend),'\ '),'[[:space:]*/]\\+','\ ','g'),'^[[:space:]*]','','g')) 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'))
112set foldtext=repeat('\ ',indent(v:foldstart)-1).join(getline(v:foldstart,v:foldend))[:winwidth(0)]->substitute('[[:space:]]\\+','\ ','g')
182 113
183" works ... 114" works ...
184" set foldexpr=match(synIDattr(synID(v:lnum,indent(v:lnum)+1,0),'name'),'Comment')>-1 115" set foldexpr=match(synIDattr(synID(v:lnum,indent(v:lnum)+1,0),'name'),'Comment')>-1
185set foldexpr=!empty(filter(synstack(v:lnum,indent(v:lnum)+1),{_,val->match(synIDattr(val,'name'),'Comment')>-1})) 116set foldexpr=!empty(filter(synstack(v:lnum,indent(v:lnum)+1),{_,val->match(synIDattr(val,'name'),'Comment')>-1}))
186 117
187
188" vim window behaviour 118" vim window behaviour
189set splitbelow | " open new windows below the current one (i find that more intuitive) 119set splitbelow | " open new windows below the current one (i find that more intuitive)
190set splitright | " this also works for me and makes better use of the scren space I think 120set splitright | " this also works for me and makes better use of the scren space I think
191set winminwidth=0 | " (and all other windows, so TODO: watch out) 121set winminwidth=0 | " (and all other windows, so TODO: watch out)
192set winwidth=30 | " keep NERDTreeWindow at least this size 122set winwidth=30 | " keep NERDTreeWindow at least this size
193 123
194
195" vim session handling and restore behaviour 124" vim session handling and restore behaviour
196set viminfo+=% | " restore buffer list 125set viminfo+=% | " restore buffer list
197set sessionoptions= 126set sessionoptions=
@@ -213,6 +142,88 @@ set noshiftround | " indent/un-indent sna=ps to multiple of shiftwi
213set noequalalways | " do not evenly size windows when opening new or closing old 142set noequalalways | " do not evenly size windows when opening new or closing old
214set nocursorline | " turn visual cursor line off (improves performance) 143set nocursorline | " turn visual cursor line off (improves performance)
215 144
145
146"=======================================================================================================================
147" PATH -- where to search for includes (e.g. `gf` or `:find`)
148"=======================================================================================================================
149set path+=**4 | " allow recursive searches for files (limit depth by 4)
150if executable("uname") " does not work under Windows
151 let &path = &path.",/usr/lib/modules/".substitute(system('uname -r'), "\n", "", "")."/build/include"
152endif
153
154
155"=======================================================================================================================
156" SPELL_CHECKING:
157"=======================================================================================================================
158let g:spellfile_URL = 'http://ftp.vim.org/vim/runtime/spell'
159" add local user default spell file as primary source for words
160let &spellfile=fnamemodify($MYVIMRC, ":p:h")."/spell/spellfile-user.UTF-8.add"
161
162set nospell | " disable spell checker by default
163set spelllang=en,de | " languages for the spell checker
164set spellsuggest=10 | " how many words will z= suggest?
165set thesaurus+=~/.vim/thesaurus/php.txt
166
167
168"=======================================================================================================================
169" UNDO:
170" Persistent undo behaviour, also keeps undo history between starts
171"=======================================================================================================================
172if has('persistent_undo')
173 if isdirectory('/dev/shm')
174 set undodir=/dev/shm/ | " save undo file in memory. That is volatile, but fast and we have GIT for longer lasting undoes
175 set directory=/dev/shm/ | " swap file directory to RAM
176 set swapfile
177 elseif isdirectory('/tmp/')
178 set undodir=/tmp/
179 endif
180 set undofile | " preserve undo history when closing and reopening buffers (see :help undo-persistence)
181endif
182
183
184"=======================================================================================================================
185" DISPLAY & MULTI_BYTE
186"=======================================================================================================================
187if has("multi_byte")
188 scriptencoding utf-8 | " tell vim that we are using UTF-8 here
189 set encoding=utf-8 | " we need default UTF-8 encoding to use cool chars as line break and so on (see below)
190 set termencoding=utf-8 | " we just assume that this is supported.
191
192 set fillchars= | " initialize empty fillchars
193 set listchars= | " initialize empty listchars
194
195 if &term ==# 'linux'
196 set fillchars+=vert:\│ | " cool vertical split char
197 else
198 set fillchars+=vert:\║ | " cool vertical split char
199 endif
200
201 set fillchars+=fold:\ | "
202 set fillchars+=diff:\ | " a white space gets used here
203
204 set listchars+=extends:» | " symbols used when using :set list (which displays non-printable chars)
205 set listchars+=precedes:« | " symbols used when using :set list (which displays non-printable chars)
206
207 set listchars+=tab:▏\ | "
208 set listchars+=trail:· | " symbols used when using :set list (which displays non-printable chars)
209 " set listchars+=eol:↲ | " symbols used when using :set list (which displays non-printable chars)
210 " set listchars+=space:⸳ | " · | " symbols used when using :set list (which displays non-printable chars)
211 set showbreak+=› | " symbol used in the beginning of a wrapped line
212
213 " automatically enter list mode when going in insert mode (makes above syntax command temporarily ineffective)
214 set nolist
215
216 autocmd InsertEnter * set list
217 autocmd InsertLeave * set list&
218
219 autocmd InsertEnter * set colorcolumn=80,120
220 autocmd InsertLeave * set colorcolumn&
221 " set fillchars+=stlnc:\― | "
222end
223
224
225"=======================================================================================================================
226" AUTOCMDs and FileType specific stuff
216"======================================================================================================================= 227"=======================================================================================================================
217if has("autocmd") 228if has("autocmd")
218 " use the shada/viminfo file to return the cursor to where it was... 229 " use the shada/viminfo file to return the cursor to where it was...
@@ -263,23 +274,11 @@ if has("autocmd")
263 \ :nnoremap 274 \ :nnoremap
264 \ <leader>= 275 \ <leader>=
265 \ vat:'<,'>!tidy -xml --wrap 0 --sort-attributes alpha 2>/dev/null<CR>vat= 276 \ vat:'<,'>!tidy -xml --wrap 0 --sort-attributes alpha 2>/dev/null<CR>vat=
266
267 if filereadable("/usr/bin/vendor_perl/ack")
268 autocmd FileType c,cpp set grepprg=/usr/bin/vendor_perl/ack\ --type=cc\ --nogroup\ --column\ $*
269 autocmd FileType c,cpp set grepformat=%f:%l:%c:%m
270 endif
271 augroup END 277 augroup END
272endif 278endif
273 279
274" ====================================================================================================================== 280" ======================================================================================================================
275augroup CUSTOM_COMMANDS 281augroup CUSTOM_COMMANDS
276 command! Vimls
277 \ call setloclist(0, map(getbufinfo({'buflisted':1}),
278 \ "{'bufnr': v:val.bufnr,
279 \ 'lnum': v:val.lnum,
280 \ 'text': '='.printf('%*s, % 3d: %s [%s]', winwidth(0) / 2, '', v:val.bufnr, v:val.name, getbufvar(v:val.bufnr, '&buftype')),
281 \ 'pattern': 'not loaded'}
282 \ "))
283 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"))}') }) 282 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"))}') })
284 command! Ctoggle 283 command! Ctoggle
285 \ if(get(getqflist({'winid':1}), 'winid') == win_getid())|cclose|else|botright copen|endif 284 \ if(get(getqflist({'winid':1}), 'winid') == win_getid())|cclose|else|botright copen|endif
@@ -304,16 +303,14 @@ augroup KEYBOARD_MAPPING
304 nnoremap <S-PageUp> :N<CR> 303 nnoremap <S-PageUp> :N<CR>
305 nnoremap <S-PageDown> :n<CR> 304 nnoremap <S-PageDown> :n<CR>
306 305
307
308 nnoremap <F4> :wincmd c<CR> 306 nnoremap <F4> :wincmd c<CR>
309
310 nnoremap <F5> :make!<CR> 307 nnoremap <F5> :make!<CR>
311 nnoremap <F6> :silent syntax sync fromstart<CR>:nohlsearch<CR>:silent match<CR>:silent 2match<CR>:silent 3match<CR> 308 nnoremap <F6> :silent syntax sync fromstart<CR>:nohlsearch<CR>:silent match<CR>:silent 2match<CR>:silent 3match<CR>
312 nnoremap <F7> :Ltoggle<CR> 309 nnoremap <F7> :Ltoggle<CR>
313 nnoremap <F8> :Ctoggle<CR> 310 nnoremap <F8> :Ctoggle<CR>
314
315 nnoremap <F9> :TagbarToggle<CR> 311 nnoremap <F9> :TagbarToggle<CR>
316 nnoremap <F12> :Vimls<CR>:Ltoggle<CR> 312 "" remap <..>
313 nnoremap <F12> :Qfls<CR>:Ctoggle<CR>
317 314
318 " close current buffer with <leader>q... 315 " close current buffer with <leader>q...
319 nnoremap <leader>q :bp<bar>sp<bar>bn<bar>bd<CR>. 316 nnoremap <leader>q :bp<bar>sp<bar>bn<bar>bd<CR>.
..