"•••••••••••••••••••••••••••••••••••••••••••••••••••••••• " HEBRON version, [c] piotao, 20201023: revision " my VIM history config file: " 20000110 pio: first versions of vim config " 20090109 pio; version for p323 host " 20161012 pio: version for sigma host " 20191213 pio: created this configuration from scratch " 20201023 pio: reworked to new expanded needs " 20210508 pio: added opening file at previous line " GLOBAL CONFIGURATION: common for all hosts "•••••••••••••••••••••••••••••••••••••••••••••••••••••••• "[enable]------------------------------------------------- set ai " set auto intent set ar " set auto read modified file set lz " enable lazy redraw (faster!) set ml " sets modeline, for local options like vim:ts=2:ai:si, etc. set sm " show matching braces {} [] () set sr " shiftround - indents to multiply of sw set nu " set line numbers set si " set smart indent set ic " ignore case in search set is " enable incremental search during typing set tf " enable fast terminal connection set lbr " wrap on word boundary when linebreak set scs " smart case: no-ignore case when upper case in search set smd " show current mode at the bottom set rnu " relative numbering of lines "[disable]--------------------------------------------- set nocul " disable cursor line hilit (faster) set noet " NO expand tabs to spaces (infl. backspace on indents) set nowb " no write backup set nobk " disable backups set nohid " hide buffers, don't close set nohls " disable search highlighting set nowrap " disable text wrapping set noswapfile " no swap files set nocul " disable cursor line "[set]------------------------------------------------- set ts=2 " set tab stop to 2 spaces set sts=2 " set soft tab stop to 2 spaces set sw=2 " set shift width to 2 spaces set so=5 " scroll up to those lines at top/bott of scr set siso=5 " cols to scroll horiz at the boundary set sbr=¬\ " continuation mark of wrapped lines set enc=utf8 " encoding default set wmnu wim=longest:full,full " wildmode settings: match longest set undofile udir=~/.vim/undo ul=9999 " global persistent undo options set clipboard=unnamed " store everything yanked in system clipboard set path+=.,** " search down into subfolders set bs=indent,eol,start " backspace modes "set mouse=a " enable mouse support set display=lastline " properly display long lines wrapped at the bottom " COMPLEX OPTIONS for global or local settings for TOhtml " configuration for TOhtml script let g:html_use_encoding = 0 let g:html_line_ids = 0 let g:html_use_css = 1 let g:html_expand_tabs = 1 let g:html_number_lines = 0 " rust configuration let g:rust_recommended_style = 0 " complex commands: filetype plugin indent on " indent based on language " auto fill closing tag iabbrev "•••••••••••••••••••••••••••••••••••••••••••••••••••••••• " LEADER + advanced operations let mapleader=';' " leader set to tilde " ... in ~alphabetical order " d remove all HTML tags from selection vnoremap d :s/<\_.\{-1,\}>//ge:'<,'>s/</:'<,'>s/>/>/ge:'<,'>s/&/\&/ge:'<,'>s/"/"/ge " h is toggling highlight search state noremap h :set nohls! " i fix file formatting noremap i gg=G`` " j join all lines of paragraph noremap j vipJ0 " l toggles display of non-printable chars noremap l :set list! " n is toggling line numbers noremap n :set rnu!:set nu! " enable spelling in the buffer noremap S :set spell! " T converts tabs in the whole file noremap t :retab " t converts text to aligned table vmap t :%!column -t " w is toggling wrapping lines noremap w :set wrap! " disable sbr noremap s :set sbr=\ " MAPPINGS and KEYSTROKES "vmap " c""P " surrounds just selection with vmap k cpa " surrounds single WORD with (from normal mode) map viwcpa " surrounds inside "..." with using vi" map vi"cpa " add around the word "map viwcpa vmap cpa " surround with nmap viwci\P vmap c\P " trim line from white spaces and set as H3 header nmap H :.s/^\s*//e:.s/\s*$//e0v$c

pA

" quickly reload configuration map :so ~/.vimrc :echom "vimrc reloaded, for: ".v:progname." v".v:version " AUTO close nearest previous HTML tag inoremap i=get(v:completed_item,'word','>') ==# '>' ? "\c-u>" : '' " this mapping IS converting any selected code to its HTML syntax highlighting vmap :TOhtmlggV/Coded/<\/pre>dGVgg"*y:q!`>pV` noremap i#include int main(){return 0;}A " map for moving window split map < map > " go through long wrapped lines with arrows in both modes nnoremap gk nnoremap gj inoremap gk inoremap gj " switch buffers directionaly nnoremap  nnoremap  nnoremap  nnoremap  " bad habit from vscode - ctrl+s for saving inoremap :w!a nnoremap :w!a " moving line up/down like in code nnoremap ddp nnoremap ddP " compile by make map :make "•••••••••••••••••••••••••••••••••••••••••••••••••••••••• " USEFUL EXTENSIONS and HACKS "•••••••••••••••••••••••••••••••••••••••••••••••••••••••• " write current file as root (for forgotten admin operations) cnoreabbrev w!! w !sudo tee > /dev/null % cnoreabbrev W w !sudo tee > /dev/null % " GLOBAL functions and general custom extensions " find a name of current git branch in current dir or return '' func! GitBranch() return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'") endfun " returns current branch name or empty string func! StatusLineGIT() let l:branchname = GitBranch() return strlen(l:branchname) > 0 ? ' '.l:branchname.' ':'' endfun " auto compile scss files using sass and save them to ../css dir func! PiotaoSASS() let cwd = expand(':p:h') let nam = expand(':t:r') let ext = expand(':e') if ext == 'scss' if executable('/usr/bin/sassc') "call system('/usr/bin/sassc -t compressed '.cwd.'/'.nam.'.'.ext.' '.cwd.'/../css/'.nam.'.css') call system('/usr/bin/sassc -t compressed '.cwd.'/'.nam.'.'.ext.' '.cwd.'/../css/'.nam.'.css') echo "sass recompiled" endif endif endfun fun! PiotaoCBX() " auto-repair most of old HTML cbx code :%s/

/\r

/ge :%s/

    /\r
      /ge :%s/
      /\r
      /ge
      	:%s/<\/ul>/\r<\/ul>/ge
      	:%s/<\/pre>/\r<\/pre>/ge
      	:%s/\n\n<\/pre>/\r<\/pre>/ge
      	:%s/
    • /\r
    • /ge :%s/
      /\r/ge :%s/
        /
      1. /ge :%s/

        /

        /ge :%s/\n\n\n/\r\r/ge endfun " for easier color definitions func! PiotaoSetHi(what,termfg,termbg,guifg,guibg,type) let l:cmd = 'hi '.a:what let l:cmd .= a:type != '' ? ' term='.a:type.' cterm='.a:type.' gui='.a:type : '' let l:cmd .= a:termbg != '' ? ' ctermbg='.a:termbg : '' let l:cmd .= a:termfg != '' ? ' ctermfg='.a:termfg : '' let l:cmd .= a:guibg != '' ? ' guibg='.a:guibg : '' let l:cmd .= a:guifg != '' ? ' guifg='.a:guifg : '' exe l:cmd endfun " automatic commenting multiple lines depending on their file type augroup commenting_blocks_of_code autocmd! autocmd FileType c,cpp,java,scala let b:comment_leader = '// ' autocmd FileType sh,bash,ruby,csh let b:comment_leader = '# ' autocmd FileType perl,python,php let b:comment_leader = '# ' autocmd FileType conf,fstab,ini let b:comment_leader = '# ' autocmd FileType tex,bib let b:comment_leader = '% ' autocmd FileType mail,email,eml let b:comment_leader = '> ' autocmd FileType vim let b:comment_leader = '" ' augroup END noremap c :silent s/^/=escape(b:comment_leader,'\/')/:nohlsearch noremap u :silent s/^\V=escape(b:comment_leader,'\/')//e:nohlsearch " detect conky files augroup detect_conky_files autocmd! autocmd BufNewFile,BufRead *conkyrc* set ft=conkyrc autocmd BufNewFile,BufRead conky.conf set ft=conkyrc " this reloads conky after save autocmd BufWritePost *conkyrc* "!sudo killall -q -SIGUSR1 conky" augroup END "•••••••••••••••••••••••••••••••••••••••••••••••••• " MY OWN custom autocommands augroup Piotao autocmd! autocmd FileType rs ts=2:sw=2:sts=2:ai:si " auto change dir to local buffer, but not when in /tmp autocmd BufEnter * silent! lcd %:p:h " auto compile sass after save autocmd FileWritePost,BufWritePost *.scss :call PiotaoSASS() " what to do when focus is lost in some mode " autocmd FocusLost * nested :silent! wall " try to save all " return to normal mode " autocmd FocusLost * call feedkeys("\\") " words with dashes are like normal single words in CSS autocmd FileType css,scss,sass setlocal iskeyword+=- " words with :: or &, * or () [] are normal in c++ autocmd FileType c,cpp setlocal iskeyword+=38,40-42,45,91,93,58,59 "open at the same line it was closed "https://stackoverflow.com/questions/774560/in-vim-how-do-i-get-a-file-to-open-at-the-same-line-number-i-closed-it-at-last autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g'\"" | endif augroup END " VERSION SPECIFIC comfigurations "•••••••••••••••••••••••••••••••••••••••••••••••••••••••••• "•••••••••••••••••••••••••••••••••••••••••••••••••••••••••• "•••••••••••••••••••[NeoVIM]••••••••••••••••••••••••••••••• if has('nvim') " GUI/LOOK&FEEL configuration " colo wasabi256 " colo abyss colo atomdark256 syn on " toggle wrapping with Alt+Z map :set wrap! " quickly edit configuration map Q :sp ~/.vimrc "•••••••••••••••••••••••••••••••••••••••••••••••••••••••••• else "••••••••••••••••••••••••••••••[VIM + GVIM]••••••••••• "•••••••••••••••••••••••••••••••••••••••••••••••••••••••••• set ls=2 " status always visible, not for nvim set st=2 " set soft tab stop to 2 spaces (unknown for nvim!) "•••••••••••••••••••••••••••••••••••••••••••••••••••••••• if has("gui_running") "•••••••••[GVIM ONLY]••••••••••••• "•••••••••••••••••••••••••••••••••••••••••••••••••••••••• " GUI/LOOK&FEEL configuration "colo wasabi256 "colo abyss colo atomdark256 syn on " change font size for specified amount, mapped for GVIM to F12↑, S-F12↓ fun! ChangeFontSize(df) let l:prevsize = matchstr(&guifont,'\( \)\@<=\d\+$') let &guifont = substitute(&guifont,' \d\+$',' '.(l:prevsize+a:df),'') endfun " toggle wrapping with Alt+Z in gvim map ú :set wrap! " open gui window with font selection map :set guifont=* " setting narrower font with F4 map :set guifont=Iosevka\ Light\ 14 map :set guifont=Iosevka\ Light\ Expanded\ 14 map :call ChangeFontSize(+1) map :call ChangeFontSize(-1) " for hi-dpi displays set toolbariconsize=giant "set guifont=Iosevka\ Light\ Expanded\ 15 "set guifont=Iosevka\ Light\ 14 "set guifont=Hasklig\ 15 "set guifont=JetBrains\ Mono\ 17 set go-=m " hide menubar set go-=T " hide toolbar set toolbar= " empty toolbar "•••••••••••••••••••••••••••••••••••••••••••••••••••••••• else "•••••••••••••••••••••••••••••[VIM ONLY]•••••••••••• "•••••••••••••••••••••••••••••••••••••••••••••••••••••••• " GUI/LOOK&FEEL configuration "colo wasabi256 "colo abyss colo atomdark256 syn on " toggle wrapping with Alt+Z in vim (terminal) map z :set wrap! set t_Co=256 " 256-color term, nvim ignores this map 1 @q map 2 @w endif endif " end of separate configuration for [ng]vim " --------------------------------------------------------- " nice info about program version, welcome if argc() == 0 autocmd VimEnter * echo v:progname.' '.v:version.' loaded.' endif " fixes and repairs of color system hi vimOption term=standout ctermfg=172 guifg=#aa66dd "•••••••••••••••••••••••••••••••••••••••••••••••••• "•••••••••••••••••••••••••••••••••••••••••••••••••• "••••••••• END OF CONFIG ••••••••••••••••••••••••• "•••••••••••••••••••••••••••••••••••••••••••••••••• "•••••••••••••••••••••••••••••••••••••••••••••••••• " everything below is just test/development "•••••••••••••••••••••••••••••••••••••••••••••••••••••••••• "••• lots of hacks, code and functions, in global scope " Ctrl-Space for completions. Heck Yeah! " inoremap pumvisible() \|\| &omnifunc == '' ? " \ "\C-n>" : " \ "\C-x>\C-o>=pumvisible() ?" . " \ "\"\\c-n>\\c-p>\\c-n>\" :" . " \ "\" \\bs>\\C-n>\"\" " imap "autocmd FileType html,php so ~/.vim/ftplugin/html_autoclosetag.vim hi VertSplit term=bold guifg=#223344 guibg=#080808 " define :HI colors: name Tfg Tbg guiFG guiBG bold? call PiotaoSetHi('StatusLine', 250, 17, '#ccddee', '#334455', 'none') call PiotaoSetHi('StatusLineNC', 245, 234, '#8899aa', '#112233', 'none') call PiotaoSetHi('PioHLS', 10, 236, '#88ff88', '#334455', '') call PiotaoSetHi('PioMOD', 1, 236, '#aabbcc', '', '') call PiotaoSetHi('PioRO', 1, 236, '#ccbbaa', '', '') call PiotaoSetHi('PioUTF', 63, 236, '#5555cc', '', '') call PiotaoSetHi('PioBOM', 1, 236, '#55bb00', '', '') call PiotaoSetHi('PioFiT', 151, 237, '#89ccbb', '', '') call PiotaoSetHi('PioFiF', 180, 236, '#aa9933', '', '') call PiotaoSetHi('PioLNG', 146, 236, '#8a55af', '', '') call PiotaoSetHi('User1', 33, 18, '#9494ff', '#223344', 'bold') " mode indicator color call PiotaoSetHi('User2', 81, '', '#789abc', '#223344', '') " line number color call PiotaoSetHi('User3', 96, '', '#987654', '#203040', '') " buffer color fun! PiotaoHLS() return (&hls ? '[hls]' : '') endfunction fun! PiotaoMOD() return (&modified ? '[mod]' : '') endfun fun! PiotaoRO() return (&readonly ? '[ro]' : '') endfun fun! PiotaoBOM() return (&bomb ? '[bom]' : '') endfun fun! PiotaoFiF() return (&ff != '' ? '['.&ff.']' : '[txt]') endfun fun! PiotaoUTF() return (&fenc!='' ? (&fenc=='utf-8'?'[u8]':'['.&fenc.']') : (&enc=='utf-8'?'[u8]':'['.&enc.']')) endfun fun! PiotaoLNG() return '['.&spelllang.']' endfun fun! PiotaoFiT() return (&filetype != '' ? '['.&filetype.']' : '[?]') endfun set statusline=%<%F%=\ set statusline+=%1*%{GetStatusLineMode()}%#PioHLS#%{PiotaoHLS()} set statusline+=%#PioFiT#%{PiotaoFiT()} set statusline+=%#PioFiF#%{PiotaoFiF()} set statusline+=%#PioMOD#%{PiotaoMOD()} set statusline+=%#PioRO#%{PiotaoRO()} set statusline+=%#PioUTF#%{PiotaoUTF()} set statusline+=%#PioLNG#%{PiotaoLNG()} set statusline+=%#PioBOM#%{PiotaoBOM()} set statusline+=%2*\ %l/%L:%04c\ %3*≡%n%* fun! PiotaoRetSet(ind,name,cf,cb,gf,gb,mo) call PiotaoSetHi(a:name,a:cf,a:cb,a:gf,a:gb,a:mo) return a:ind endfun fun! GetStatusLineMode() let ms=mode() if ms == 'n' return PiotaoRetSet(' N ','User1', 69, 18,'#9494ff','#223344','bold') elseif ms == 'i' return PiotaoRetSet(' I ','User1', 46, 28,'#9494ff','#223344','bold') elseif ms == 'v' || ms == 'V' return PiotaoRetSet(' V ','User1', 11, 94,'#ffa239','#223344','') elseif ms == 's' || ms == 'S' return PiotaoRetSet(' S ','User1', 11, 54,'#ffa239','#223344','') elseif ms == 'R' || ms == 'Rv' return PiotaoRetSet(' R ','User1',202, 88,'#a683ff','#223344','') elseif ms == 'c' hi User1 guifg=#a683ff gui=bold guibg=#223344 return ' C ' else hi User1 guifg=#00ffff guibg=#334455 gui=bold return '['.ms.']' endif endfunction