vim
vim copied to clipboard
reStructuredText Syntax Highlighting on macOS
Steps to reproduce
The bug can be reproduced with the following command using macOS's builtin Vim.
echo "syntax on" > vimrc
echo "hello CONFIG_SAMPLE_BT_USE_AUTHENTICATION" > test.rst
vim -u vimrc test.rst
This results in 'redrawtime' exceeded, syntax highlighting disabled
.
It's hard to say how much of this is a Vim bug and not a macOS issue since I haven't been able to reproduce with similar Vim versions on Debian/etc.
Expected behaviour
Syntax highlighting should work
Version of Vim
9.0.2018
Environment
Operating System: macOS 14.2.1
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Nov 12 2023 01:16:04) macOS version - arm64 Included patches: 1-2018
Logs and stack traces
No response
Hm, I cannot reproduce but then I do not have a mac. Two things:
If you compile your own version (e.g. using homebrew), does it show the same issue? What is your option 'redrawtime'
value? Can you use :syntime report
and check if there are slow queries (See :h syntime
) ? Also, can you please post the full :version
output?
I have the default redrawtime=2000
. syntime
unfortunately isn't available in the OS Vim.
I will look into trying a custom compiled Vim but I suspect it's due to the way Apple is compiling it. The issue is present with the default Vim on macOS 12 and macOS 14 but I haven't been able to reproduce the issue on any of my Linux boxes running a variety of Vim versions.
:version
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Nov 12 2023 01:16:04)
macOS version - arm64
Included patches: 1-2018
Compiled by [email protected]
Normal version without GUI. Features included (+) or not (-):
+acl +cmdline_hist +ex_extra +jumplist +mouse_dec -perl -sodium +textobjects +wildmenu
-arabic +cmdline_info +extra_search -keymap -mouse_gpm +persistent_undo -sound +textprop +windows
+autocmd +comments -farsi +lambda -mouse_jsbterm +popupwin +spell +timers +writebackup
+autochdir +conceal +file_in_path -langmap +mouse_netterm +postscript +startuptime +title -X11
-autoservername +cryptv +find_in_path +libcall +mouse_sgr +printer +statusline -toolbar -xattr
-balloon_eval +cscope +float +linebreak -mouse_sysmouse -profile -sun_workshop +user_commands -xfontset
-balloon_eval_term +cursorbind +folding +lispindent +mouse_urxvt -python +syntax -vartabs -xim
-browse +cursorshape -footer +listcmds +mouse_xterm -python3 +tag_binary +vertsplit -xpm
++builtin_terms +dialog_con +fork() +localmap +multi_byte +quickfix -tag_old_static +vim9script -xsmp
+byte_offset +diff -gettext -lua +multi_lang +reltime -tag_any_white +viminfo -xterm_clipboard
+channel +digraphs -hangul_input +menu -mzscheme -rightleft -tcl +virtualedit -xterm_save
+cindent -dnd +iconv +mksession +netbeans_intg -ruby +termguicolors +visual
-clientserver -ebcdic +insert_expand +modify_fname +num64 +scrollbind +terminal +visualextra
+clipboard -emacs_tags +ipv6 +mouse +packages +signs +terminfo +vreplace
+cmdline_compl +eval +job -mouseshape +path_extra +smartindent +termresponse +wildignore
system vimrc file: "$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: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -L/usr/local/lib -o vim -lm -lncurses -liconv -framework Cocoa
I did a bit more investigation and the issue disappears if I remove these two lines: https://github.com/vim/vim/blob/d887fb81b6d419d035629f06b918b054d30c5fab/runtime/syntax/rst.vim#L169-L170
\=
seems to be responsible part - issue also goes away if I remove that.
My initial guess is that there's some difference between how regular expressions are handled on macOS vs Linux.
I am not familiar enough with these syntax files to know what can be safely removed.
I have no idea, why this goes away once you remove the \=
. This is used to match the _
optionally at. I don't know the RST markup language, so cannot say what will break.
A few things to try:
- Try if it changes with
:set re=1
or:set re=2
? - Can you generate the
:syntime report
(see:help syntime
)
Also pinging @marshallward perhaps he know what this change above would mean to the RST highlighting.
Single and double underscores should both be recognized. The double underscore indicates an anonymous hyperlink. (.. __: https:/...
)
https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#hyperlink-targets
This section predates me, and I'm not in a position this week to test anything, so I'm unsure what could be causing the problem. But I don't think that the \=
should just be dropped.
@chrisbra thanks for the suggestion.
Syntax highlighting works on macOS without any runtime changes if I set :set re=0
and :set re=2
.
Additionally, I'm able to reproduce the issue on all my machines with :set re=1
:
echo "hello CONFIG_SAMPLE_BT_USE_AUTHENTICATION" > test.rst
vim --clean -c ":set re=1" -c ":syntax on" test.rst
It seems like re=1
is the default on macOS but :verbose set re?
doesn't show anything not sure why it's different.
Result of :syntime report
: syntime-report.txt