diff options
author | Max Christian Pohle | 2018-10-14 21:33:03 +0200 |
---|---|---|
committer | Max Christian Pohle | 2018-10-14 21:33:03 +0200 |
commit | 45c3e3581b74060dae453ac097e5a4d629603393 (patch) | |
tree | 48820d3971d86187c5754729b9f4ca598f87ee77 | |
parent | c2808a2053fa4d382a1ad7edc9637951c9eefc55 (diff) | |
download | vim-45c3e3581b74060dae453ac097e5a4d629603393.tar.bz2 vim-45c3e3581b74060dae453ac097e5a4d629603393.zip |
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.
-rw-r--r-- | after/syntax/c.vim | 11 | ||||
-rw-r--r-- | 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 @@ | |||
1 | setlocal number | ||
2 | setlocal foldenable | 1 | setlocal foldenable |
3 | setlocal foldmethod=expr | 2 | setlocal foldmethod=expr |
4 | setlocal foldcolumn=0 | 3 | " setlocal foldcolumn=0 |
5 | 4 | ||
6 | " setlocal foldexpr=get(synstack(v:lnum,1),0)==hlID('cComment') | 5 | " setlocal foldexpr=get(synstack(v:lnum,1),0)==hlID('cComment') |
7 | setlocal foldexpr=index([0,hlID('cComment'),hlID('Comment')],get(synstack(v:lnum,1),0)) | 6 | " setlocal foldexpr=len(filter(synstack(v:lnum,indent(v:lnum)+1),'index([hlID(\"cComment\"),hlID(\"cCommentStart\")],v:val)!=-1'))>0 |
8 | 7 | " 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')) | |
8 | " setlocal foldexpr=index(get(synstack(v:lnum,1),0),hlID('cComment'))>0 | ||
9 | " setlocal foldexpr=index(synstack(v:lnum,indent(v:lnum)+1),hlID('cComment'))>0 | ||
10 | " setlocal signcolumn=no | ||
9 | " syntax match cType "struct\s+[A-Za-z0-9_]+\>" | 11 | " syntax match cType "struct\s+[A-Za-z0-9_]+\>" |
10 | " syn clear cStructure | 12 | " syn clear cStructure |
11 | " highlight! link defines Special | 13 | " highlight! link defines Special |
@@ -23,7 +25,6 @@ syn region cBlock start=/{/ end=/}/ transparent | |||
23 | " syn region myCComment start="/\*" end="\*/" fold keepend transparent | 25 | " syn region myCComment start="/\*" end="\*/" fold keepend transparent |
24 | 26 | ||
25 | 27 | ||
26 | |||
27 | " let b:current_syntax = "c" | 28 | " let b:current_syntax = "c" |
28 | " let g:polyglot_disabled = ['c/c++'] | 29 | " let g:polyglot_disabled = ['c/c++'] |
29 | " unlet s:ft | 30 | " unlet s:ft |
@@ -64,7 +64,7 @@ if has("multi_byte") | |||
64 | set listchars+=tab:▏\ | " | 64 | set listchars+=tab:▏\ | " |
65 | set listchars+=trail:· | " symbols used when using :set list (which displays non-printable chars) | 65 | set listchars+=trail:· | " symbols used when using :set list (which displays non-printable chars) |
66 | " set listchars+=eol:↲ | " symbols used when using :set list (which displays non-printable chars) | 66 | " set listchars+=eol:↲ | " symbols used when using :set list (which displays non-printable chars) |
67 | " set listchars+=space:· | " symbols used when using :set list (which displays non-printable chars) | 67 | set listchars+=space:· | " symbols used when using :set list (which displays non-printable chars) |
68 | set showbreak+=› | " symbol used in the beginning of a wrapped line | 68 | set showbreak+=› | " symbol used in the beginning of a wrapped line |
69 | 69 | ||
70 | " automatically enter list mode when going in insert mode (makes above syntax command temporarily ineffective) | 70 | " automatically enter list mode when going in insert mode (makes above syntax command temporarily ineffective) |
@@ -215,7 +215,7 @@ set writedelay=0 | |||
215 | " display and performance | 215 | " display and performance |
216 | set lazyredraw | " disables redraw during macro execution (improves performance) | 216 | set lazyredraw | " disables redraw during macro execution (improves performance) |
217 | set cmdheight=2 | " sets the command line's height | 217 | set cmdheight=2 | " sets the command line's height |
218 | set signcolumn=auto | " auto=auto hide, yes=always, no=never show the column with error indicators | 218 | set signcolumn=yes | " auto=auto hide, yes=always, no=never show the column with error indicators |
219 | set nocursorcolumn | " turn visual cursor column off (improves performance) | 219 | set nocursorcolumn | " turn visual cursor column off (improves performance) |
220 | set updatetime=80 | " updates the screen more often | 220 | set updatetime=80 | " updates the screen more often |
221 | set redrawtime=1500 | " Timeout in milliseconds for redrawing the screen (switches syntax off when ssh too slow) / CTRL+L to retry | 221 | 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 | |||
242 | set nofoldenable | " disable folding, because we have zi to toggle foldenable :) | 242 | set nofoldenable | " disable folding, because we have zi to toggle foldenable :) |
243 | set foldclose=all | " automatically fold, when the cursor leaves the folded area | 243 | set foldclose=all | " automatically fold, when the cursor leaves the folded area |
244 | set foldcolumn=1 | " I think I don't need this second indicator | 244 | set foldcolumn=1 | " I think I don't need this second indicator |
245 | set numberwidth=5 | 245 | " set numberwidth=5 |
246 | " set foldmethod=syntax | " foldlevel: syntax, indent, manual / foldmethod=syntax makes Vim incredible slow | 246 | " set foldmethod=syntax | " foldlevel: syntax, indent, manual / foldmethod=syntax makes Vim incredible slow |
247 | set foldnestmax=1 | " top level folding only | 247 | set foldnestmax=1 | " top level folding only |
248 | set foldopen=block,hor,search | " when do we unfold? | 248 | set foldopen=block,hor,search | " when do we unfold? |
249 | " set foldtext=Foldtext() | " | 249 | " set foldtext=Foldtext() | " |
250 | " set foldtext=v:folddashes.substitute(getline(v:foldstart),'\\v^/[/*]\','','g') | 250 | " set foldtext=v:folddashes.substitute(getline(v:foldstart),'\\v^/[/*]\','','g') |
251 | " set foldtext='⊞\ '.substitute(getline(v:foldstart),'^[\ '.printf(&cms,'').']*','','').'↵'.getline(v:foldstart+1).'↵'.getline(v:foldstart+2) | 251 | " set foldtext='⊞\ '.substitute(getline(v:foldstart),'^[\ '.printf(&cms,'').']*','','').'↵'.getline(v:foldstart+1).'↵'.getline(v:foldstart+2) |
252 | set foldtext='⊞\ '.substitute(substitute(substitute(join(getline(v:foldstart,v:foldend)),'\\s\\s\\+\\\|\[\*\/\]','\ ','g'),'\^\\s\\+','','g'),\ '\\s\\s\\+',\ '\ ',\ 'g') | 252 | " set foldtext=repeat('',indent(v:foldstart)).substitute(substitute(substitute(join(getline(v:foldstart,v:foldend)),'\\s\\s\\+\\\|\[\*\/\]','\ ','g'),'\^\\s\\+','','g'),\ '\\s\\s\\+',\ '\ ',\ 'g') |
253 | set foldtext=printf('%*s%.*S',indent(v:foldstart),'',&textwidth-indent(v:foldstart),substitute(substitute(join(getline(v:foldstart,v:foldend),'\ '),'[[:space:]]\\+','\ ','g'),'^[[:space:]]','','g')) | ||
254 | |||
255 | " works ... | ||
256 | " set foldexpr=match(synIDattr(synID(v:lnum,indent(v:lnum)+1,0),'name'),'Comment')>-1 | ||
257 | set foldexpr=!empty(filter(synstack(v:lnum,indent(v:lnum)+1),{_,val->match(synIDattr(val,'name'),'Comment')>-1})) | ||
258 | |||
259 | " 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')) | ||
253 | 260 | ||
254 | " vim window behaviour | 261 | " vim window behaviour |
255 | set splitbelow | " open new windows below the current one (i find that more intuitive) | 262 | set splitbelow | " open new windows below the current one (i find that more intuitive) |
263 | set splitright | " this also works for me and makes better use of the scren space I think | ||
256 | set winminwidth=0 | " (and all other windows, so TODO: watch out) | 264 | set winminwidth=0 | " (and all other windows, so TODO: watch out) |
257 | set winwidth=30 | " keep NERDTreeWindow at least this size | 265 | set winwidth=30 | " keep NERDTreeWindow at least this size |
258 | 266 | ||
@@ -692,11 +700,18 @@ Plug 'tpope/vim-fugitive' | " the most complete GIT integration plug | |||
692 | Plug 'godlygeek/tabular' | " align code on a sign, like :Tab/= | 700 | Plug 'godlygeek/tabular' | " align code on a sign, like :Tab/= |
693 | Plug 'tpope/vim-surround' | " plugin makes cs"' inside a line replace " with ' | 701 | Plug 'tpope/vim-surround' | " plugin makes cs"' inside a line replace " with ' |
694 | let g:signify_vcs_list = [ 'git' ] | " use signify only with git (improves speed when loading buffers, see :h signify) | 702 | let g:signify_vcs_list = [ 'git' ] | " use signify only with git (improves speed when loading buffers, see :h signify) |
695 | let g:signify_cursorhold_insert = 0 | 703 | let g:signify_cursorhold_insert = 0 |
696 | let g:signify_cursorhold_normal = 0 | 704 | let g:signify_cursorhold_normal = 0 |
697 | let g:signify_update_on_bufenter = 0 | 705 | let g:signify_update_on_bufenter = 0 |
698 | let g:signify_update_on_focusgained = 0 | 706 | let g:signify_update_on_focusgained = 0 |
699 | let g:signify_sign_show_count = 1 | 707 | let g:signify_sign_show_count = 1 |
708 | |||
709 | let g:signify_sign_add = '≫' | ||
710 | let g:signify_sign_delete = '≪' | ||
711 | let g:signify_sign_delete_first_line = '≪' | ||
712 | let g:signify_sign_change = '≶' | ||
713 | let g:signify_sign_changedelete = g:signify_sign_change | ||
714 | |||
700 | 715 | ||
701 | " NERDTree: replaces NetRW, as long as it has so many bugs | 716 | " NERDTree: replaces NetRW, as long as it has so many bugs |
702 | Plug 'scrooloose/nerdtree' | " | 717 | Plug 'scrooloose/nerdtree' | " |
@@ -995,7 +1010,12 @@ function! ExtendColorTheme() | |||
995 | highlight! link PmenuSbar Pmenu | 1010 | highlight! link PmenuSbar Pmenu |
996 | highlight! PmenuThumb cterm=inverse | 1011 | highlight! PmenuThumb cterm=inverse |
997 | highlight! MoreMsg cterm=inverse | 1012 | highlight! MoreMsg cterm=inverse |
998 | highlight! link Folded LineNr | 1013 | |
1014 | highlight! link LineNr Comment | ||
1015 | highlight! link Folded Comment | ||
1016 | highlight! link SignColumn Comment | ||
1017 | highlight! link FoldColumn Comment | ||
1018 | " highlight! Folded ctermbg=NONE | ||
999 | " highlight! Cursor guibg=#729fcf ctermbg=yellow | 1019 | " highlight! Cursor guibg=#729fcf ctermbg=yellow |
1000 | highlight! link VertSplit NonText | 1020 | highlight! link VertSplit NonText |
1001 | " highlight! SpellBad ctermbg=none | 1021 | " highlight! SpellBad ctermbg=none |
@@ -1009,6 +1029,7 @@ function! ExtendColorTheme() | |||
1009 | highlight! link WildMenu Search | 1029 | highlight! link WildMenu Search |
1010 | 1030 | ||
1011 | " generic, which should exist but don't | 1031 | " generic, which should exist but don't |
1032 | highlight! SignifySignAdd ctermbg=NONE | ||
1012 | highlight! Bold cterm=bold gui=bold | 1033 | highlight! Bold cterm=bold gui=bold |
1013 | highlight! Italic cterm=italic gui=italic | 1034 | highlight! Italic cterm=italic gui=italic |
1014 | highlight! Underline cterm=underline gui=underline | 1035 | highlight! Underline cterm=underline gui=underline |
@@ -1027,6 +1048,17 @@ function! ExtendColorTheme() | |||
1027 | 1048 | ||
1028 | highlight! link Convention Error | 1049 | highlight! link Convention Error |
1029 | 1050 | ||
1051 | |||
1052 | highlight! link SignifySignAdd LineNr | ||
1053 | highlight! link SignifySignChange LineNr | ||
1054 | highlight! link SignifySignDelete LineNr | ||
1055 | highlight! link SignifySignChangeDelete LineNr | ||
1056 | highlight! link SignifySignDeleteFirstLine LineNr | ||
1057 | |||
1058 | highlight! SpellBad ctermbg=NONE ctermfg=red cterm=NONE | ||
1059 | highlight! link YcmErrorSign SpellBad | ||
1060 | highlight! link YcmWarningSign Spellbad | ||
1061 | |||
1030 | " autocmd InsertLeave * call matchadd('Conceal', ' \+$', -1, 101, { 'conceal': '⟶' }) | 1062 | " autocmd InsertLeave * call matchadd('Conceal', ' \+$', -1, 101, { 'conceal': '⟶' }) |
1031 | autocmd InsertEnter * silent! call matchdelete(101) | 1063 | autocmd InsertEnter * silent! call matchdelete(101) |
1032 | autocmd InsertLeave * silent! call matchadd('Convention', ' \+$', -1, 101, { 'conceal': '⟶' }) | 1064 | autocmd InsertLeave * silent! call matchadd('Convention', ' \+$', -1, 101, { 'conceal': '⟶' }) |