Vim 打开 JS 文件时 CPU 使用率高

Vim 打开 JS 文件时 CPU 使用率高

Vim,尤其是 Gvim 在打开大 .js 文件(1000 多行)时停止响应并使用 100% 的 CPU。按 停止Ctrlc该过程。无论 Vim 尝试打开文件做什么,它都会显示文件内容(全部折叠成一个折叠),并且在插入模式下输入的每个字符都需要几分钟才能显示在屏幕上。然后我必须重新启动 Vim,才能编辑文件。

即使对于相同的文件,这种情况也不会每次都会发生,但每天会发生 3-5 次。

使用时strace -p PID我看到以下消息不断重复

poll([{fd=7, events=POLLIN}, {fd=6, events=POLLIN}, {fd=3, events=POLLIN}, {fd=4, events=POLLIN}, {fd=8, events=POLLIN}], 5, 0) = 0 (Timeout)
read(7, 0x7fffc4477280, 16)             = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(6, 0x21848f4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=7, events=POLLIN}, {fd=6, events=POLLIN}, {fd=3, events=POLLIN}, {fd=4, events=POLLIN}, {fd=8, events=POLLIN}], 5, 0) = 0 (Timeout)
read(7, 0x7fffc4477280, 16)             = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(6, 0x21848f4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=7, events=POLLIN}, {fd=6, events=POLLIN}, {fd=3, events=POLLIN}, {fd=4, events=POLLIN}, {fd=8, events=POLLIN}], 5, 0) = 0 (Timeout)
read(7, 0x7fffc4477280, 16)             = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(6, 0x21848f4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
...

我已经尝试过vim --noplugin,但出现了同样的问题。我在 Ubuntu 12.04.1 x64 上运行自编译的 Vim。vim :version给出以下信息:

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Aug 15 2012 17:16:57)
Included patches: 1-631
Huge version with GTK2 GUI.  Features included (+) or not (-):
+arabic +autocmd +balloon_eval +browse ++builtin_terms +byte_offset +cindent    +clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments +conceal +cryptv +cscope +cursorbind
+cursorshape +dialog_con_gui +diff +digraphs +dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path +find_in_path +float +folding -footer +fork() +gettext -hangul_input
+iconv +insert_expand +jumplist +keymap +langmap +libcall +linebreak +lispindent +listcmds +localmap -lua +menu +mksession +modify_fname +mouse +mouseshape +mouse_dec -mouse_gpm -mouse_jsbterm
+mouse_netterm -mouse_sysmouse +mouse_xterm +mouse_urxvt +multi_byte +multi_lang -mzscheme +netbeans_intg +path_extra -perl +persistent_undo +postscript +printer +profile +python -python3
+quickfix +reltime +rightleft +ruby +scrollbind +signs +smartindent -sniff +startuptime +statusline -sun_workshop +syntax +tag_binary +tag_old_static -tag_any_white -tcl +terminfo +termresponse
+textobjects +title +toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo +vreplace +wildignore +wildmenu +windows +writebackup +X11 -xfontset +xim +xsmp_interact
+xterm_clipboard -xterm_save
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I /usr/include/libpng12   -I/usr/local/include  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L.  -rdynamic -Wl,-export-dynamic  -L/usr/local/lib -Wl,--as-needed -o vim   -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0   -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -lnsl   -ldl     -L/usr/lib/python2.7/config -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions   -lruby-1.9.1 -lpthread -lrt -ldl -lcrypt -lm  -L/usr/lib

我的设置有什么问题吗?可能是什么问题?

答案1

尝试删除用于编辑 JS 文件的所有额外插件或语法文件。写得不好的 vim 脚本或语法文件(基本上是一堆正则表达式)会让 Vim 瞬间吃掉所有 CPU 周期。

相关内容