往 vim 粘贴大段文本会卡顿的问题

0x0 问题

用 vim 编辑文件时,发现粘贴大段文本时会变得很卡,有时候几百行的文本,需要花几十秒甚至更长时间。

0x1 解决办法

这里有个方法,可以对 vim 进行 profile,用来分析哪些操作占用了时间。

:profile start profile.log
:profile func *
:profile file *
" At this point do slow actions
:profile pause
:noautocmd qall!

以下是运行结果的部分内容:

FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
1682770 161.034552 159.048132  Foldexpr_markdown()
 7296   1.986420             <SNR>102_is_mkdCode()
 ...

FUNCTIONS SORTED ON SELF TIME
count  total (s)   self (s)  function
1682770 161.034552 159.048132  Foldexpr_markdown()
 7296              1.986420  <SNR>102_is_mkdCode()
 ...

看到这个结果,问题就清楚了,是 folding 功能引起的开销。

0x2 参考资料

  • https://stackoverflow.com/questions/12213597/how-to-see-which-plugins-are-making-vim-slow
  • https://stackoverflow.com/questions/1687799/profiling-vim-startup-time

Read More: