" vim: noai:ts=2:sw=2:sts=2 iskeyword+=\:,\!,\<,\>,\-,\& " scripts from the default vim installation, which do not get loaded by default, but are useful. " if filereadable($VIMRUNTIME.'/macros/editexisting.vim') " " source $VIMRUNTIME/macros/editexisting.vim " packadd! editexisting " endif "======================================================================================================================= " GENERAL: "======================================================================================================================= set textwidth=120 | " better done with modeline set ts=4 sts=4 sw=4 expandtab | " better done with a modeline set redrawtime=1000 | " Timeout in milliseconds for redrawing the display / CTRL+L to retry "======================================================================================================================= " SHELL "======================================================================================================================= if filereadable("/bin/bash") set shell=/bin/bash | " many scripts rely on bash, but its path varies why it is commented out here elseif filereadable("/usr/local/bin/bash") set shell=/usr/local/bin/bash endif "======================================================================================================================= " Persistent undo "======================================================================================================================= if has('persistent_undo') if isdirectory('/dev/shm') set undodir=/dev/shm/ | " save undo file in memory. That is volatile, but fast and we have GIT for longer lasting undos set directory=/dev/shm/ | " swap file directory to RAM set swapfile elseif isdirectory('/tmp/') set undodir=/tmp/ endif set undofile | " preserve undo history when closing and reopening buffers (see :help undo-persistenece) endif "======================================================================================================================= " multi byte "======================================================================================================================= if has("multi_byte") scriptencoding utf-8 | " tell vim that we are using utf-8 here set encoding=utf-8 | " we need default utf-8 encoding to use cool chars as line break and so on (see below) set termencoding=&encoding | " once we use special chars we assume everybody uses a terminal supporting those set fillchars+=fold:\— | " set fillchars+=vert:\│ | " cool vertical split char set fillchars+=diff:\ | " a whitespace gets used here set listchars= | " initialize empty listchars set listchars+=extends:» | " symbols used when using :set list (which displays non-printable chars) set listchars+=precedes:« | " symbols used when using :set list (which displays non-printable chars) set listchars+=tab:▏\ | " set listchars+=trail:· | " symbols used when using :set list (which displays non-printable chars) " set listchars+=eol:↲ | " symbols used when using :set list (which displays non-printable chars) " set listchars+=space:· | " symbols used when using :set list (which displays non-printable chars) set showbreak+=› | " symbol used in the beginning of a wrapped line set list " set fillchars+=stlnc:\― | " end "======================================================================================================================= " SPELL_CHECKING "======================================================================================================================= let g:spellfile_URL='http://ftp.vim.org/vim/runtime/spell' set nospell | " disable spell checker by default set spelllang=en,de | " languages for the spell checker set spellsuggest=10 | " how many words will z= suggest? set thesaurus+=~/.vim/thesaurus/php.txt set dictionary=/usr/share/dict/cracklib-small set complete+=k " make default completer respect the dictionary set complete+=i " scan current and included files set complete+=d " scan current and included files for defined name or macro "======================================================================================================================= " Cscope "======================================================================================================================= " http://vim.wikia.com/wiki/Cscope if has('cscope') " compiled with cscope support? set cscopetag " CTRL-] uses cscope first, then ctags set cscopeverbose if has('quickfix') set cscopequickfix=s+,c+,d+,i+,t+,e+ endif if has('menu') menu &Cscope.create\ and\ add\ database \ :execute '!find -regex ".*\.\(c\\|h\\|cpp\\|cxx\\|hh\\|hpp\\|hxx\)$" cscope -i- -b -q':cscope kill -1:cscope add . menu &Cscope.-Sep- \ : menu &Cscope.find.C\ symbol \ :cscope find s menu &Cscope.find.definition \ :cscope find g menu &Cscope.find.functions\ called\ by\ this \ :cscope find d menu &Cscope.find.functions\ calling\ this \ :cscope find c menu &Cscope.find.text\ string \ :cscope find t menu &Cscope.find.egrep\ pattern \ :cscope find e menu &Cscope.find.this\ file \ :cscope find f menu &Cscope.find.files\ including\ this\ file \ :cscope find i menu &Cscope.find.places\ where\ this\ symbol\ is\ assigned\ a\ value \ :cscope find a menu &Cscope.-Sep- \ : menu &Cscope.add \ :cscope add . menu &Cscope.show \ :cscope show menu &Cscope.reset \ :cscope reset endif endif " ======================================================================================================================= " GUI_VERSION " ======================================================================================================================= if has("gui_running") set guicursor=a:block-blinkon100 set browsedir=buffer set toolbar+=text set guiheadroom=0 set guioptions+=eig set guioptions-=T | " toolbar set guioptions+=c | " use console dialogs instead of popups set guioptions+=a | " autoselect: copy&paste using middleclick set guioptions+=m | " remove menu set guioptions-=e | " do not display tabs set guioptions-=L | " do not show left scrollbar set guioptions-=r | " do not show right scrollbar set winaltkeys=menu | " behave like other windows: ALT-key can be used to open the menu (and cannot be :remaped) " set selectmode=mouse,key,cmd | " enters vim's select mode when pressing shift-left or shift-END " set keymodel=startsel,stopsel | " makes shift-left, shift-right available for selecting text " its possible to define alternative fonts (order matters) set guifont= set guifont+=Dejavu\ Sans\ Mono\ for\ Powerline\ Semibold set guifont+=RobotoMono\ Nerd\ Font\ Medium\ 10 set guifont+=LiterationMono\ Nerd\ Font\ Mono\ 10 set guifont+=Source\ Code\ Pro\ Semi-Bold\ 10 set guifont+=Source\ Code\ Pro\ for\ Powerline\ SemiBold\ 10 set guifont+=Droid\ Sans\ Mono\ for\ Powerline\ 10 set guifont+=Meslo\ LG\ M\ for\ Powerline\ 10 endif " ======================================================================================================================= " SETTINGS: " ======================================================================================================================= set noautochdir | " When on, Vim will change the current working directory set breakindent | " Every wrapped line will continue visually indented set clipboard=unnamedplus | " makes copy and paste work (autoselectplus might work as well) set cmdheight=2 | " sets the command line's height set complete+=d | " scan current and included files for defined name or macro set complete+=i | " scan current and included files for completions set colorcolumn= | " not used, because we have a :match directive for textwidth set concealcursor=nc | " limits the display of concealed text to normal and command mode set conceallevel=2 | " replace escaped chars by their utf-8 representation (useful for LaTeX) set confirm | " asks 'do you want to save?' set cpoptions+=P | " makes :w filename set the current buffer to filename set hidden | " allows switiching buffers even if the current buffer contains changes (displays +) set hlsearch | " highlights all search matches (not as performant!) set ignorecase smartcase | " search with ignorecase by default, but use case sensitive search when one captical char is contained set lazyredraw | " disables redraw during macro exectution (improves performance) set linebreak | " wrap long lines at char 'breakat', not inside words set mouse=n | " allow mouse in normal mode only, so one can use the terminals c&p feature in insert mode set mousemodel=popup | " only in gvim: right click opens a popup-menu set nocursorcolumn | " turn visual cursor column off (improves performance) set nrformats+=alpha | " allows CTRL-A & CTRL-X to increment and decrement letters, not just numbers set nofoldenable | " disable folding, because we have zi to toggle foldenable :) set exrc | " enable exrc, a specific .exrc per project, which can contain usual .vimrc commands set foldmethod=syntax | " foldlevel: syntax, indent, manual set foldcolumn=0 | " I think I don't need this second indicator set foldclose=all | " automatically fold, when the cursor leaves the folded area set foldopen=block,hor,search | " when do we unfold? set foldtext=Foldtext() | " set foldnestmax=1 | " top level folding only set norelativenumber | " relative line numbers can speed up navigation, but I could not get used to it till now set noshowmode | " because we are using some powerline derivat set nostartofline | " when scrolling: do not move the cursor to column 1 set notimeout ttimeout | " improves performance but is known to cause problems on slow terminals set ttimeoutlen=50 | " set esc key timeout in ms- set nowrap | " but do not (by default) wrap long lines around set number | " turn line numbers on/off (performance decreases when they are shown) set pumheight=8 | " Determines the maximum number of items to show in the popup menu for set path+=** | " allow recursive searches for files set scrolljump=5 | " how many lines get scrolled into view when cursor reaches the screens edge set splitbelow | " open new windows below the current one (i find that more intuitive) set shiftround | " indent/unindent snaps to multiple of shiftwidths set shortmess+=I | " don't give the intro message when starting Vim |:intro|. set showcmd | " essential: show keys of combined commands in the lower right corner (BUT SLOW, makes cursor flickering) set signcolumn=yes | " auto=auto hide, yes=always, no=never show the column with error indicators set showtabline=2 | " 0: never, 1: only if there are at least two tabs, 2:always set winwidth=30 | " keep NERDTreeWindow at least this size set winminwidth=0 | " (and all other windows, so TODO: watch out) set tags+=../tags set tagcase=match | " tagcase match, because we mostly use ^] to jump around and that variant respects the upper/lower case [followscs, followic, match, ignore] set updatetime=80 | " updates the screen more often set viminfo+=% | " restore buffer list set virtualedit=all | " virtual edit should be default behaviour, because I don't see any reason against set writedelay=0 set wildmenu | " use a menu in the command line set wildmode=longest:full | " do not preselect any entry and show all possible set sessionoptions= set sessionoptions+=buffers set sessionoptions+=curdir set sessionoptions+=folds set sessionoptions+=tabpages set sessionoptions+=winpos set sessionoptions+=winsize set sessionoptions+=resize set sessionoptions+=unix set sessionoptions+=slash " set nocindent smartindent | " use smart indent rather then cindent set noautoindent set nosmartindent set cindent cinoptions+=(0 | " indent at parentheses set noshiftround | " indent/unindent sna=ps to multiple of shiftwidths set equalalways | " do not evenly size windows when opening new or closing old set nocursorline | " turn visual cursor line off (improves performance) "======================================================================================================================= " Vim8 has a terminal command... if has('terminal') " use default ESC key to leave insert mode in the internal terminal emulator tnoremap N " make terminal windows hidden by default (copied from :help terminal) autocmd BufWinEnter * if &buftype == 'terminal' | setlocal bufhidden=hide | endif endif " NEOVIM_incompatible: " if has('nvim') " Neovim? autocmd TermOpen term://* set nobuflisted " use default ESC key to leave insert mode in the internal terminal emulator tnoremap " set shada+=n~/.vim/shada | " shada file to use else " default Vim? autocmd VimLeave * call system("echo -n $'" . escape(getreg(), "'") . "' | xsel -ib") set ttymouse=xterm2 set ttyscroll=100 | " improves speed for terminal vim, incomp. with nvim set ttyfast | " improves speed for terminal vim (incomp. with nvim) set nottybuiltin | " use external termcaps " set termguicolors | " When on, uses highlight-guifg and highlight-guibg attributes in the terminal (=24bit color) incomp. with nvim set restorescreen | " restores the console after exiting vim (intentionally not in nvim) " let g:loaded_ruby_provider = 1 " disable ruby support let g:loaded_python_provider = 1 " disable pthon3 if version >= 702 " clean up (see: http://vim.wikia.com/wiki/VimTip396) autocmd BufWinLeave * call clearmatches() endif endif if has("autocmd") set modeline | " set variables specific to a file, like indentation by adding a comment " set default completion function in case YouCompleteMe cannot help " set omnifunc=syntaxcomplete#Complete augroup set_window_title " { " autocmd BufWinEnter quickfix setl statusline=%t " autocmd BufEnter * let &titlestring = hostname() . "[vim(" . expand("%:t") . ")]" autocmd CursorHold * let &titlestring = "%t %y ".$USER."@".hostname().":%{expand(\"%:~:.:h\")}" set title " autocmd CursorHold * let &titlestring = "Vim (".airline#extensions#tagbar#currenttag().")" " set window title for screen(3) if &term == "screen" set t_ts=k set t_fs=\ endif if &term == "screen" || &term == "xterm" set titlelen=40 set title endif augroup END augroup ChangeIcon "if filereadable("/usr/bin/xseticon") "if filereadable("~/.vim/nvim.png") " autocmd VimEnter * silent :execute "!xseticon -id $WINDOWID ~/.vim/nvim.png" " autocmd VimLeave * silent :execute "!xseticon -id $WINDOWID /usr/share/icons/gnome/32x32/apps/xfce-terminal.png" "endif "endif augroup END " Fix terminal title ================================================================================================= " autocmd VimEnter * let &t_EI .= "\[0 q" " autocmd VimEnter * let &t_SI = "\]12;green\x7" autocmd VimLeave * silent !echo -ne "\033]112\007" " highlight word under the cursor ==================================================================================== let w:m1 = 0 function! HighlightWordUnderCursor() if(exists('w:m1') && w:m1 > 0) silent! call matchdelete(w:m1) let w:m1 = 0 endif let l:currentword = escape(expand(''), '.') if(strlen(l:currentword) > 0) let w:m1=100 silent! call matchadd('BoldItalic', '\<'.l:currentword.'\>', -1, w:m1) endif endfunction autocmd! CursorHold,CursorHoldI * call HighlightWordUnderCursor() " hitting K over a keyword shows a help in a buffer. " Here we define the commands used to look those keywords up " as per file type... augroup filetype_specific autocmd FileType python setlocal keywordprg=pydoc autocmd FileType vim setlocal keywordprg=:help |. autocmd FileType c,cpp setlocal equalprg=clang-format autocmd FileType c,cpp setlocal breakat-=- autocmd BufWinEnter * if &previewwindow | setlocal nonumber signcolumn=no filetype=c nobuflisted | endif " autocmd FileType c,cpp setlocal iskeyword-=_ " the following helps to make file=/etc/something work with gf, but disallows filenames with an equal sign in them autocmd FileType conf setlocal isfname-== " keyboard mapping for xml alike languages " Alt-Up : Move cursor up one tag " Alt-Down: Move cursor down one tag " leader-=: tidies currently selected tag and subtags and sorts attributes by name (alphabetically) autocmd Filetype html,markdown,xml iabbrev autocmd Filetype html,htmldjango,xml \ :nnoremap \ \ :call search('^ *<', 'e'):nohlsearch| \ :nnoremap \ \ :call search('^ *<', 'eb'):nohlsearch| \ :nnoremap \ = \ vat:'<,'>!tidy -xml --wrap 0 --sort-attributes alpha 2>/dev/nullvat= augroup END " autocmd BufNewFile set nobuflisted " use the shada/viminfo file to return the cursor to where it was... function! ReturnCursor() if line("'\"") > 1 && line("'\"") <= line("$") exe "normal! g`\"" endif endfunction autocmd! BufReadPost * call ReturnCursor() augroup ToggleQuickFix function! ToggleQuickFix() if exists("g:qwindow") lclose unlet g:qwindow else try lopen 10 let g:qwindow = 1 catch echo "No Errors found!" endtry endif endfunction function! QFixToggle(forced) if exists("g:qfix_win") && a:forced == 0 cclose unlet g:qfix_win else copen 10 let g:qfix_win = bufnr("$") endif endfunction nmap