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