14

I have a vim 8.2 on a Gentoo Linux running on a more or less 8 years old PC.

I almost never have a performance issue with vim, unless you open a one-line huge xml oder json file, but those are vary rare cases.

My team has started using typescript and so many of our javascript files have been transformed to ts. I use vim-plug for plugging management and I added the HerringtonDarkholme/yats.vim plugin.

However if I open a typescript file, even smaller ones, vim starts normally but after a few seconds it gets very unresponsive, if I scroll down the syntax highlight is also gone and eventually vim hangs. Looking at the process with htop I can see that the process is constantly running at 100% CPU. The only thing I can do is a kill -9.

Vim 8.2 (or at least the Gentoo version) has support for typescript in the default installation, looking at the files in /usr/share/vim/vim82 the provided files seems to be the same as the ones from the yats plugin.

So to be sure that I don't have other plugins interfering, I made a backup of my vim config and remove it from my HOME directory.

The yats github page says to explitly set set re=1, so I created a new ~/.vimrc file and added this line to it. When I open the typescript file, I get the same result, so my other plugins didn't affect it at all.

So the set re=1 made me curious and if I set it instead to 2 or 0 (the default), then opening the same typescript file does not lead vim to hang.

So, did I understand the warning on the github page correctly and I should add set re=1? If so, why is it worse for me?

How can you check what exactly in a plugin is making vim go crazy?

In case this is somehow important:

$ vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Apr  4 2020 16:30:54)
Included patches: 1-360
Modified by Gentoo-8.2.0360
Compiled by shaoran@gallifrey
Huge version without GUI.  Features included (+) or not (-):
+acl               -farsi             -mouse_sysmouse    -tag_old_static
+arabic            +file_in_path      +mouse_urxvt       -tag_any_white
+autocmd           +find_in_path      +mouse_xterm       -tcl
+autochdir         +float             +multi_byte        +termguicolors
-autoservername    +folding           +multi_lang        -terminal
-balloon_eval      -footer            -mzscheme          +terminfo
+balloon_eval_term +fork()            +netbeans_intg     +termresponse
-browse            +gettext           +num64             +textobjects
++builtin_terms    -hangul_input      +packages          +textprop
+byte_offset       +iconv             +path_extra        +timers
+channel           +insert_expand     -perl              +title
+cindent           +job               +persistent_undo   -toolbar
+clientserver      +jumplist          +popupwin          +user_commands
+clipboard         +keymap            +postscript        +vartabs
+cmdline_compl     +lambda            +printer           +vertsplit
+cmdline_hist      +langmap           +profile           +virtualedit
+cmdline_info      +libcall           -python            +visual
+comments          +linebreak         +python3           +visualextra
+conceal           +lispindent        +quickfix          +viminfo
+cryptv            +listcmds          +reltime           +vreplace
-cscope            +localmap          +rightleft         +wildignore
+cursorbind        -lua               +ruby              +wildmenu
+cursorshape       +menu              +scrollbind        +windows
+dialog_con        +mksession         +signs             +writebackup
+diff              +modify_fname      +smartindent       +X11
+digraphs          +mouse             -sound             +xfontset
-dnd               -mouseshape        +spell             -xim
-ebcdic            +mouse_dec         +startuptime       -xpm
+emacs_tags        +mouse_gpm         +statusline        +xsmp_interact
+eval              -mouse_jsbterm     -sun_workshop      +xterm_clipboard
+ex_extra          +mouse_netterm     +syntax            -xterm_save
+extra_search      +mouse_sgr         +tag_binary        
   system vimrc file: "/etc/vim/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: x86_64-pc-linux-gnu-gcc -c -I. -Iproto -DHAVE_CONFIG_H     -O2 -pipe -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: x86_64-pc-linux-gnu-gcc   -L. -Wl,-O1 -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,--no-undefined -Wl,-O1 -L/usr/local/lib -Wl,--as-needed -o vim    -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lelf -lnsl   -lacl -lattr -lgpm -ldl     -lpython3.6m -lpthread -ldl -lutil -lm  -lruby24 -lpthread -lgmp -ldl -lcrypt -lm

My vim configuration

2 Answers 2

19
+50

tldr; Add set re=2 into .vimrc prevents the issue on mac. I'm not sure why.

8
  • 9
    Welcome! It would be great if you could explain why this works for you.
    – Biggybi
    Commented Jan 12, 2021 at 6:35
  • 3
    Echoing Biggybi's sentiments, welcome to Vi and Vim! Please consider taking a few minutes to complete the tour. Given that OP already mentions that re=2 works, I'm not sure this truly qualifies as an answer to the question "should I use re=1 and why is it worse than alternatives?"
    – D. Ben Knoble
    Commented Jan 12, 2021 at 16:33
  • 3
    Environment: MacBook Pro (15-inch, 2018) iTerm, and the .vimrc only one line: syntax enable. open a typescript file, like: github.com/codex-team/editor.js/blob/next/src/codex.ts and press Control+f and Control+b, the screen is hangs. add set re=1, same the hangs. change to set re=2, ok~
    – mrjarone
    Commented Apr 15, 2021 at 10:33
  • 3
    I don't know the reason, but it is true.
    – mrjarone
    Commented Apr 15, 2021 at 10:40
  • 4
    Sad that people downvoted you when this does in fact resolve the issue. Commented Mar 21, 2022 at 20:34
11

From :help 're':

                        *'regexpengine'* *'re'*
'regexpengine' 're' number  (default 0)
            global
    This selects the default regexp engine. |two-engines|
    The possible values are:
        0   automatic selection
        1   old engine
        2   NFA engine
    Note that when using the NFA engine and the pattern contains something
    that is not supported the pattern will not match.  This is only useful
    for debugging the regexp engine.
    Using automatic selection enables Vim to switch the engine, if the
    default engine becomes too costly.  E.g., when the NFA engine uses too
    many states.  This should prevent Vim from hanging on a combination of
    a complex pattern with long text.

This "old" engine supports everything but uses backtracking (which can be very slow in some patterns). The new engine is NFA-based, and may be slower or faster depending on the pattern. See :help two-engines. You can actually force a given pattern to use a different engine with the atom \%#=0 (or 1 or 2).

The best seems to be the default (0) which allows vim to decide.

You should probably talk to the yats people about why they "need" regexpengine=1...

2
  • 1
    Yeah, I read the documentation as well, but in my case the opposite happened, with re=1 the whole process hangs. I think I'll post an issue there.
    – Pablo
    Commented May 5, 2020 at 0:35
  • I think the root of the problem is the use of the \K\k* pattern in /usr/share/vim/vim82/syntax/typescriptcommon.vim. In the vim doc \K and \k are keyword matches, but they are backreferences in the perl doc. Adding set regexpengine=0 to ~/.vimrc worked for me.
    – pbatey
    Commented Jul 28, 2021 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.