aboutsummaryrefslogtreecommitdiff
path: root/vimrc-common
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-common
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-common')
-rw-r--r--vimrc-common379
1 files changed, 0 insertions, 379 deletions
diff --git a/vimrc-common b/vimrc-common
deleted file mode 100644
index dc48045..0000000
--- a/vimrc-common
+++ /dev/null
@@ -1,379 +0,0 @@
1"=======================================================================================================================
2" GENERAL
3"=======================================================================================================================
4
5filetype on
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" ======================================================================================================================
33" SETTINGS:
34" ======================================================================================================================
35set breakindent | " Every wrapped line will continue visually indented
36set clipboard=unnamedplus | " makes copy and paste work (autoselectplus might work as well)
37set concealcursor=nc | " limits the display of concealed text to normal and command mode
38set conceallevel=2 | " replace escaped chars by their UTF-8 representation (useful for LaTeX)
39set confirm | " asks 'do you want to save?'
40set cpoptions+=P | " makes :w filename set the current buffer to filename
41set hidden | " allows switching buffers even if the current buffer contains changes (displays +)
42set linebreak | " wrap long lines at char 'breakat', not inside words
43set mousemodel=popup | " only in gvim: right click opens a pop-up-menu
44set mouse=n | " allow mouse in normal mode only, so one can use the terminals c&p feature in insert mode
45set noautochdir | " When on, Vim will change the current working directory
46set nostartofline | " when scrolling: do not move the cursor to column 1
47set nowrap | " but do not (by default) wrap long lines around
48set nrformats+=alpha | " allows CTRL-A & CTRL-X to increment and decrement letters, not just numbers
49
50if has('nvim') " Neovim?
51 set inccommand=nosplit | " preview substitute and such things in real time
52endif
53
54if exists("g:neovide")
55 set guifont=monospace:h11:b
56 let g:neovide_cursor_animation_length=0
57 let g:neovide_scroll_animation_length = 0.5
58 let g:neovide_cursor_trail_size=0.8
59 let g:neovide_cursor_vfx_mode = ""
60 let g:neovide_transparency = 0.9
61 let g:neovide_floating_blur_amount_x = 4.0
62 let g:neovide_floating_blur_amount_y = 4.0
63 let g:neovide_background_color = '#383a62'
64 let g:neovide_scale_factor = 1.0
65endif
66
67set pumheight=8 | " Determines the maximum number of items to show in the pop-up menu for
68set scrolljump=4 | " how many lines get scrolled into view when cursor reaches the screens edge
69set scrolloff=4 | " keeps cursor centered
70set shiftround | " indent/un-indent snaps to multiple of shiftwidths
71set writedelay=0
72
73" display and performance
74set lazyredraw | " disables redraw during macro execution (improves performance, but causes problems with solid backgrounds)
75set cmdheight=2 | " sets the command line's height
76set signcolumn=yes | " auto=auto hide, yes=always, no=never show the column with error indicators
77set nocursorcolumn | " turn visual cursor column off (improves performance)
78set updatetime=80 | " updates the screen more often
79set redrawtime=1500 | " Timeout in milliseconds for redrawing the screen (switches syntax off when ssh too slow) / CTRL+L to retry
80set notimeout | " improves performance but is known to cause problems on slow terminals
81set ttimeout ttimeoutlen=150 | " set Esc key timeout in ms-
82set showcmd | " essential: show keys of combined commands in the lower right corner (BUT SLOW, makes cursor flickering)
83set showtabline=2 | " 0: never, 1: only if there are at least two tabs, 2:always
84set shortmess+=I | " don't give the intro message when starting Vim |:intro|.
85set wildmenu | " use a menu in the command line
86set wildmode=longest:full | " do not preselect any entry and show all possible
87
88" code completion
89" set dictionary=/usr/share/dict/cracklib-small
90set isfname-== | " remove = as char in filenames, because most FSs do not support it
91set complete+=d | " scan current and included files for defined name or macro
92set complete+=i | " scan current and included files for completions
93set complete+=k | " make default completer <C-N> respect the dictionary
94set complete-=u | " scan current and included files
95set complete+=i | " scan current and included files
96set 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
98set completeopt+=noinsert | " Do not insert any text for a match until the user selects one
99set completeopt+=noselect | " Do not select a completion from the menu, let the user do that
100set tagcase=match | " tagcase match, because we mostly use ^] to jump around and that variant respects the upper/lower case [followscs, followic, match, ignore]
101set tags+=../tags
102
103" code folding...
104set nofoldenable | " disable folding, because we have zi to toggle foldenable :)
105set foldclose=all | " automatically fold, when the cursor leaves the folded area
106set 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
109set foldnestmax=1 | " top level folding only
110set 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'))
112set 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
116set foldexpr=!empty(filter(synstack(v:lnum,indent(v:lnum)+1),{_,val->match(synIDattr(val,'name'),'Comment')>-1}))
117
118" vim window behaviour
119set splitbelow | " open new windows below the current one (i find that more intuitive)
120set splitright | " this also works for me and makes better use of the scren space I think
121set winminwidth=0 | " (and all other windows, so TODO: watch out)
122set winwidth=30 | " keep NERDTreeWindow at least this size
123
124" vim session handling and restore behaviour
125set viminfo+=% | " restore buffer list
126set sessionoptions=
127set sessionoptions+=buffers
128set sessionoptions+=curdir
129set sessionoptions+=folds
130set sessionoptions+=resize
131set sessionoptions+=slash
132set sessionoptions+=tabpages
133set sessionoptions+=unix
134set sessionoptions+=winpos
135set sessionoptions+=winsize
136
137" set nocindent smartindent | " use smart indent rather then cindent
138set noautoindent
139set nosmartindent
140
141set noshiftround | " indent/un-indent sna=ps to multiple of shiftwidths
142set noequalalways | " do not evenly size windows when opening new or closing old
143set nocursorline | " turn visual cursor line off (improves performance)
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
227"=======================================================================================================================
228if has("autocmd")
229 " use the shada/viminfo file to return the cursor to where it was...
230 autocmd BufWinEnter * if &previewwindow | setlocal nonumber nolist signcolumn=no filetype=c nobuflisted | endif
231
232 " Workaround: Allows Vim to yank text within wayland
233 " XDG_SESSION_TYPE is only set if a login manager was used
234 " WAYLAND_DISPLAY should always work
235 " if ($XDG_SESSION_TYPE ==# 'wayland' || ! empty($WAYLAND_DISPLAY)) && !has('nvim')
236 " autocmd TextYankPost * call system("wl-copy", getreg('+'))
237 " endif
238
239 autocmd TextYankPost * echo '> text yanked to '.
240 \ (get(v:event,'regname') == ''
241 \ ? 'default register'
242 \ : 'register '.get(v:event,'regname'))
243
244
245 autocmd InsertLeave * silent! call matchadd('Convention', ' \+$', -1, 101, { 'conceal': '⟶' })
246 autocmd InsertEnter * silent! call matchdelete(101)
247
248
249 "====================================================================================================================
250 augroup FILETYPES
251 " indent within <script> and <style> (default is a zero indent)
252 let g:html_indent_script1 = "inc"
253 let g:html_indent_style1 = "inc"
254
255 " let g:loaded_ruby_provider = 1 " disable ruby support
256 " let g:loaded_python_provider = 1 " disable python 3
257
258 let g:LatexBox_latexmk_preview_continuously = 1
259 let g:LatexBox_viewer = "evince"
260
261 autocmd FileType python setlocal keywordprg=pydoc
262 autocmd FileType vim setlocal keywordprg=:help |.
263 autocmd FileType conf setlocal isfname-==
264 autocmd Filetype css command! CSSsort :g/{/+1;/}/-1 sort
265 autocmd Filetype html,markdown,xml iabbrev </ </<C-X><C-O>
266
267 autocmd Filetype html,htmldjango,xml
268 \ :nnoremap
269 \ <M-Down>
270 \ :call search('^ *<', 'e')<CR>:nohlsearch<CR>|
271 \ :nnoremap
272 \ <M-Up>
273 \ :call search('^ *<', 'eb')<CR>:nohlsearch<CR>|
274 \ :nnoremap
275 \ <leader>=
276 \ vat:'<,'>!tidy -xml --wrap 0 --sort-attributes alpha 2>/dev/null<CR>vat=
277 augroup END
278endif
279
280" ======================================================================================================================
281augroup CUSTOM_COMMANDS
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"))}') })
283 command! Ctoggle
284 \ if(get(getqflist({'winid':1}), 'winid') == win_getid())|cclose|else|botright copen|endif
285 command! Ltoggle
286 \ if(get(getloclist(0, {'winid':1}), 'winid') == win_getid())|lclose|else|lopen|endif
287 command! BuffersToArg :exec ':args '.join(map(range(0, bufnr('$')), 'fnameescape(fnamemodify(bufname(v:val), ":."))'))
288 command! BufToArg :argadd %:.
289 command! Gbranch call setqflist([], 'r', {'title':'Git branch selector','items':map(systemlist("git branch"), {_, p->{'filename':'branch','module': fnamemodify(p, ':.')}})})
290 " the following command opens a preview-window and shows the declaration of
291 " the function under the cursor. It also highlights the word to make it easier
292 " to spot within a great file
293 command! Helpme au! CursorHold * nested let @/=expand('<cword>')|exe "silent! psearch ".expand("<cword>")
294 command! FindInAllBuffers cex [] | bufdo vimgrepadd //g % | cw
295augroup END
296
297"=======================================================================================================================
298augroup KEYBOARD_MAPPING
299 " map CTRL-PageUp/Down to next/previous buffer
300 " and Shift-PageUp/Down to next/previous arglist file
301 nnoremap <C-PageUp> :bn<CR>
302 nnoremap <C-PageDown> :bp<CR>
303 nnoremap <S-PageUp> :N<CR>
304 nnoremap <S-PageDown> :n<CR>
305
306 nnoremap <F4> :wincmd c<CR>
307 nnoremap <F5> :make!<CR>
308 nnoremap <F6> :silent syntax sync fromstart<CR>:nohlsearch<CR>:silent match<CR>:silent 2match<CR>:silent 3match<CR>
309 nnoremap <F7> :Ltoggle<CR>
310 nnoremap <F8> :Ctoggle<CR>
311 nnoremap <F9> :TagbarToggle<CR>
312 "" remap <..>
313 nnoremap <F12> :Qfls<CR>:Ctoggle<CR>
314
315 " close current buffer with <leader>q...
316 nnoremap <leader>q :bp<bar>sp<bar>bn<bar>bd<CR>.
317 nnoremap <leader>r :syntax sync fromstart
318
319 nnoremap <silent> <A-Up> :wincmd k<CR>
320 nnoremap <silent> <A-Down> :wincmd j<CR>
321 nnoremap <silent> <A-Left> :wincmd h<CR>
322 nnoremap <silent> <A-Right> :wincmd l<CR>
323
324
325 inoremap <C-S> <C-O>:w<CR>
326
327 " exec current line as a command, insert output of command (from: https://youtu.be/MquaityA1SM?t=35m45s)
328 nnoremap <leader>Q !!$SHELL<CR>
329 " google the word under the cursor
330 nnoremap <leader>g :execute ":!xdg-open https://google.de/search?q=".expand("<cword>")<CR>
331 nnoremap <leader>u :execute ":!xdg-open ".expand("<cWORD>")<CR>
332 " display highlight group under the cursor
333 nnoremap <leader>h :echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')<CR>
334
335
336 " ======================================================================================================================
337 " SHORTCUTS: custom shortcuts
338 " inoremap <C-Space> <C-x><C-o>
339 " inoremap <C-@> <C-Space>
340
341 " Bind CTRL+Backspace to vim's version (CTRL+W) in " <CR> insert mode (only works with gvim)
342 inoremap <C-Backspace> <C-W>
343
344 " INDENTATION: allows un-indenting a selected block and keeps selection
345 vnoremap < <gv
346 vnoremap > >gv
347
348 " make shift-home select to the beginning of the line
349 nnoremap <s-home> v^
350 nnoremap <s-end> v$
351
352 nnoremap <s-down> vj
353 vnoremap <s-down> j
354 nnoremap <s-up> vk
355 vnoremap <s-up> k
356
357 " if the wildmenu is configured to to display suggestions vertically, then
358 " reconfigure the cursor keys to work in that direction
359 if &wildoptions =~# 'pum'
360 cnoremap <expr> <up> pumvisible() ? "<C-p>" : "\<up>"
361 cnoremap <expr> <down> pumvisible() ? "<C-n>" : "\<down>"
362 endif
363
364
365 " INSERT_MODE_MAPPINGS:
366 " default copy&paste insert key binding (just in insert mode, so it doesn't conflict
367 " with visual block mode)- would have been nice, but collides with c-w for digraphs
368 " inoremap <C-V> <C-R>+
369
370 " NEOVIM_SPECIFIC:
371 if has('nvim') " only neovim...
372 " shortcut \t opens a terminal in a horizontal split
373 nnoremap <leader>t :new +terminal<CR>
374 endif
375augroup END
376
377"=======================================================================================================================
378" v modeline, do not chnage v
379" vim: noai:ts=2:sw=2:sts=2 iskeyword+=\:,\<,\>,\-,\& number
..