Closed urbainvaes closed 3 years ago
Yeah, it's vimtex foldexpression, that makes commenting of folded sections painfully slow, because it get's re-evaluated on every setline()
call.
A workaround would be, to temporarily switch to a manual foldmethod, this patch should do it:
diff --git a/plugin/commentary.vim b/plugin/commentary.vim
index 862ca82..8a24497 100644
--- a/plugin/commentary.vim
+++ b/plugin/commentary.vim
@@ -33,6 +33,7 @@ function! s:go(...) abort
else
let [lnum1, lnum2] = [line("'["), line("']")]
endif
+ let [foldmethod, &fdm] = [&foldmethod, 'manual']
let [l, r] = s:surroundings()
let uncomment = 2
@@ -63,7 +64,7 @@ function! s:go(...) abort
set modelines=0
silent doautocmd User CommentaryPost
finally
- let &modelines = modelines
+ let [&modelines, &foldmethod] = [modelines, foldmethod]
endtry
return ''
endfunction
I had raised a related issue on the issue tracker of vimtex: https://github.com/lervag/vimtex/issues/944
Using the plugin https://github.com/Konfekt/FastFold or neovim helped me.
@chrisbra Thanks, this patch looks nice! It'd be great if it could be merged in the plugin! :)
My only issue with that patch is I hate to taint :verbose set foldmethod?
, but if this is a big problem for people I guess that is an acceptable trade-off.
Hi Tim,
With
vimtex
folds enabled, commenting long blocks of text withgcc
is orders of magnitude slower than a visual block selection followed byI%<esc>
. There is perhaps be a way to setfoldmethod
tomanual
before running the commenting function, and to restore the previous setting after?MWE: this tex file and this
.vimrc
: