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