From 45c3e3581b74060dae453ac097e5a4d629603393 Mon Sep 17 00:00:00 2001 From: Max Christian Pohle Date: Sun, 14 Oct 2018 21:33:03 +0200 Subject: Improved code folding and tidied up The new foldexpr hides everything if its highlight group has 'comment' to it. The foldtext has also been improved and now shows textwidth characters. By now also 0 is allowed, but then it is as if foldtext would be empty. I will probably remove this. --- after/syntax/c.vim | 11 ++++++----- vimrc-full | 52 ++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/after/syntax/c.vim b/after/syntax/c.vim index 49e96f0..72136f6 100644 --- a/after/syntax/c.vim +++ b/after/syntax/c.vim @@ -1,11 +1,13 @@ -setlocal number setlocal foldenable setlocal foldmethod=expr -setlocal foldcolumn=0 +" setlocal foldcolumn=0 " setlocal foldexpr=get(synstack(v:lnum,1),0)==hlID('cComment') -setlocal foldexpr=index([0,hlID('cComment'),hlID('Comment')],get(synstack(v:lnum,1),0)) - +" setlocal foldexpr=len(filter(synstack(v:lnum,indent(v:lnum)+1),'index([hlID(\"cComment\"),hlID(\"cCommentStart\")],v:val)!=-1'))>0 +" setlocal foldtext=printf('%*s%.'.eval(&textwidth-indent(v:foldstart)).'S',indent(v:foldstart),'',substitute(substitute(substitute(join(getline(v:foldstart,v:foldend)),'\\s\\s\\+\\\|\[\*\/\]','\ ','g'),'\^\\s\\+','','g'),\ '\\s\\s\\+',\ '\ ',\ 'g')) +" setlocal foldexpr=index(get(synstack(v:lnum,1),0),hlID('cComment'))>0 +" setlocal foldexpr=index(synstack(v:lnum,indent(v:lnum)+1),hlID('cComment'))>0 +" setlocal signcolumn=no " syntax match cType "struct\s+[A-Za-z0-9_]+\>" " syn clear cStructure " highlight! link defines Special @@ -23,7 +25,6 @@ syn region cBlock start=/{/ end=/}/ transparent " syn region myCComment start="/\*" end="\*/" fold keepend transparent - " let b:current_syntax = "c" " let g:polyglot_disabled = ['c/c++'] " unlet s:ft diff --git a/vimrc-full b/vimrc-full index cc7cce0..468c505 100644 --- a/vimrc-full +++ b/vimrc-full @@ -64,7 +64,7 @@ if has("multi_byte") 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 listchars+=space:· | " symbols used when using :set list (which displays non-printable chars) set showbreak+=› | " symbol used in the beginning of a wrapped line " automatically enter list mode when going in insert mode (makes above syntax command temporarily ineffective) @@ -215,7 +215,7 @@ set writedelay=0 " display and performance set lazyredraw | " disables redraw during macro execution (improves performance) set cmdheight=2 | " sets the command line's height -set signcolumn=auto | " auto=auto hide, yes=always, no=never show the column with error indicators +set signcolumn=yes | " auto=auto hide, yes=always, no=never show the column with error indicators set nocursorcolumn | " turn visual cursor column off (improves performance) set updatetime=80 | " updates the screen more often set redrawtime=1500 | " Timeout in milliseconds for redrawing the screen (switches syntax off when ssh too slow) / CTRL+L to retry @@ -242,17 +242,25 @@ set tags+=../tags set nofoldenable | " disable folding, because we have zi to toggle foldenable :) set foldclose=all | " automatically fold, when the cursor leaves the folded area set foldcolumn=1 | " I think I don't need this second indicator -set numberwidth=5 +" set numberwidth=5 " set foldmethod=syntax | " foldlevel: syntax, indent, manual / foldmethod=syntax makes Vim incredible slow set foldnestmax=1 | " top level folding only set foldopen=block,hor,search | " when do we unfold? " set foldtext=Foldtext() | " " set foldtext=v:folddashes.substitute(getline(v:foldstart),'\\v^/[/*]\','','g') " set foldtext='⊞\ '.substitute(getline(v:foldstart),'^[\ '.printf(&cms,'').']*','','').'↵'.getline(v:foldstart+1).'↵'.getline(v:foldstart+2) -set foldtext='⊞\ '.substitute(substitute(substitute(join(getline(v:foldstart,v:foldend)),'\\s\\s\\+\\\|\[\*\/\]','\ ','g'),'\^\\s\\+','','g'),\ '\\s\\s\\+',\ '\ ',\ 'g') +" set foldtext=repeat('',indent(v:foldstart)).substitute(substitute(substitute(join(getline(v:foldstart,v:foldend)),'\\s\\s\\+\\\|\[\*\/\]','\ ','g'),'\^\\s\\+','','g'),\ '\\s\\s\\+',\ '\ ',\ 'g') +set foldtext=printf('%*s%.*S',indent(v:foldstart),'',&textwidth-indent(v:foldstart),substitute(substitute(join(getline(v:foldstart,v:foldend),'\ '),'[[:space:]]\\+','\ ','g'),'^[[:space:]]','','g')) + +" works ... +" set foldexpr=match(synIDattr(synID(v:lnum,indent(v:lnum)+1,0),'name'),'Comment')>-1 +set foldexpr=!empty(filter(synstack(v:lnum,indent(v:lnum)+1),{_,val->match(synIDattr(val,'name'),'Comment')>-1})) + +" set foldtext=printf('%*s%.'.eval(&textwidth-indent(v:foldstart)).'S',indent(v:foldstart),'',substitute(substitute(substitute(join(getline(v:foldstart,v:foldend)),'\\s\\s\\+\\\|\[\*\/\]','\ ','g'),'\^\\s\\+','','g'),\ '\\s\\s\\+',\ '\ ',\ 'g')) " vim window behaviour set splitbelow | " open new windows below the current one (i find that more intuitive) +set splitright | " this also works for me and makes better use of the scren space I think set winminwidth=0 | " (and all other windows, so TODO: watch out) set winwidth=30 | " keep NERDTreeWindow at least this size @@ -692,11 +700,18 @@ Plug 'tpope/vim-fugitive' | " the most complete GIT integration plug Plug 'godlygeek/tabular' | " align code on a sign, like :Tab/= Plug 'tpope/vim-surround' | " plugin makes cs"' inside a line replace " with ' let g:signify_vcs_list = [ 'git' ] | " use signify only with git (improves speed when loading buffers, see :h signify) -let g:signify_cursorhold_insert = 0 -let g:signify_cursorhold_normal = 0 -let g:signify_update_on_bufenter = 0 -let g:signify_update_on_focusgained = 0 -let g:signify_sign_show_count = 1 +let g:signify_cursorhold_insert = 0 +let g:signify_cursorhold_normal = 0 +let g:signify_update_on_bufenter = 0 +let g:signify_update_on_focusgained = 0 +let g:signify_sign_show_count = 1 + +let g:signify_sign_add = '≫' +let g:signify_sign_delete = '≪' +let g:signify_sign_delete_first_line = '≪' +let g:signify_sign_change = '≶' +let g:signify_sign_changedelete = g:signify_sign_change + " NERDTree: replaces NetRW, as long as it has so many bugs Plug 'scrooloose/nerdtree' | " @@ -995,7 +1010,12 @@ function! ExtendColorTheme() highlight! link PmenuSbar Pmenu highlight! PmenuThumb cterm=inverse highlight! MoreMsg cterm=inverse - highlight! link Folded LineNr + + highlight! link LineNr Comment + highlight! link Folded Comment + highlight! link SignColumn Comment + highlight! link FoldColumn Comment + " highlight! Folded ctermbg=NONE " highlight! Cursor guibg=#729fcf ctermbg=yellow highlight! link VertSplit NonText " highlight! SpellBad ctermbg=none @@ -1009,6 +1029,7 @@ function! ExtendColorTheme() highlight! link WildMenu Search " generic, which should exist but don't + highlight! SignifySignAdd ctermbg=NONE highlight! Bold cterm=bold gui=bold highlight! Italic cterm=italic gui=italic highlight! Underline cterm=underline gui=underline @@ -1027,6 +1048,17 @@ function! ExtendColorTheme() highlight! link Convention Error + + highlight! link SignifySignAdd LineNr + highlight! link SignifySignChange LineNr + highlight! link SignifySignDelete LineNr + highlight! link SignifySignChangeDelete LineNr + highlight! link SignifySignDeleteFirstLine LineNr + + highlight! SpellBad ctermbg=NONE ctermfg=red cterm=NONE + highlight! link YcmErrorSign SpellBad + highlight! link YcmWarningSign Spellbad + " autocmd InsertLeave * call matchadd('Conceal', ' \+$', -1, 101, { 'conceal': '⟶' }) autocmd InsertEnter * silent! call matchdelete(101) autocmd InsertLeave * silent! call matchadd('Convention', ' \+$', -1, 101, { 'conceal': '⟶' }) -- cgit v1.2.3