changeset 463:1d2e33dfe0c6

Clean up folding and foldtexts
author zegervdv <zegervdv@me.com>
date Fri, 24 Sep 2021 10:03:31 +0200
parents 676d7ef5fecb
children 48521caaf918
files .chezmoitemplates/config.vim .chezmoitemplates/init.lua
diffstat 2 files changed, 8 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/.chezmoitemplates/config.vim	Fri Sep 24 09:44:17 2021 +0200
+++ b/.chezmoitemplates/config.vim	Fri Sep 24 10:03:31 2021 +0200
@@ -240,25 +240,6 @@
 augroup END
 "
 
-" Custom folding by Steve Losh
-function! MyFoldText() "
-  let line = getline(v:foldstart)
-
-  let nucolwidth = &fdc + &number * &numberwidth
-  let windowwidth = winwidth(0) - nucolwidth - 3
-  let foldedlinecount = v:foldend - v:foldstart
-
-  " expand tabs into spaces
-  let onetab = strpart('          ', 0, &tabstop)
-  let line = substitute(line, '\t', onetab, 'g')
-
-  let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
-  let fillcharcount = windowwidth - len(line) - len(foldedlinecount)
-  return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' '
-endfunction "
-set foldtext=MyFoldText()
-set foldopen+=jump
-
 " Detect Filetype from content if file has no extension
 augroup newFileDetection
   au!
@@ -649,7 +630,6 @@
   au!
   au FileType systemverilog setlocal suffixesadd+=.sv,.v
   au FileType systemverilog setlocal foldmethod=expr
-  au FileType systemverilog setlocal foldexpr=nvim_treesitter#foldexpr()
   au FileType systemverilog,verilog call SVAlign()
   au FileType systemverilog,verilog let b:delimitMate_quotes = "\""
   au FileType systemverilog,verilog set iskeyword+='
--- a/.chezmoitemplates/init.lua	Fri Sep 24 09:44:17 2021 +0200
+++ b/.chezmoitemplates/init.lua	Fri Sep 24 10:03:31 2021 +0200
@@ -565,6 +565,14 @@
   c = true, -- Commandline mode
 }
 
+opt.foldmethod = 'expr'
+opt.foldexpr = 'nvim_treesitter#foldexpr()'
+opt.foldnestmax = 3
+opt.foldminlines = 1
+opt.foldtext =
+  [[substitute(getline(v:foldstart),'\\t',repeat('\ ',&tabstop),'g').'...'.trim(getline(v:foldend)) . ' (' . (v:foldend - v:foldstart + 1) . ' lines)']]
+opt.foldenable = false
+
 -- LSP config
 local lsp = require 'lspconfig'
 local null_ls = require 'null-ls'