improve vi syntax highlighting - #4222
Conversation
|
But isn't that heresy to edit Vi(m) files with |
I don't think so. What other editor could you possibly use to edit them? 🤪 |
Could you share an example file to reproduce this? |
The one in the PR description is the simplest one -- Here's a small file that demonstrates " these are all supposed to be highlighted as comments, we only get the first one correct
set ai " comment
set ai "comment
set ai "comment"
" strings
let s = "string"
exec "!micro -version"
" in this context the " is neither a string nor comment but a keypress
nnoremap <A-y> "ayy
nnoremap <A-p> "ap
" and @" is a register
let l:saved_reg = @" |
|
Ah, ok. I thought So, I'm not sure this PR actually makes things better. Comments are still incorrectly highlighted as strings, and worse, incomplete (unclosed) strings are incorrectly and confusingly highlighted as complete strings, as if vimscript syntax allowed them. (Your PR genuinely made me think that in vimscript |
That's fair. The other option would be to remove string highlighting and only highlight comments when we are sure they are comments (when
It is definitely not worse than highlighting them as multiline strings as vimscript does not allow those either. Expressions can't span multiple lines without the explicit line continuation syntax. At least this way the next line is still highlighted correctly even when we fail to handle the previous line correctly (which happens at least a couple times in most real vimrc files I've looked at). Here's a patch to remove string regions if that's preferable: diff --git a/runtime/syntax/vi.yaml b/runtime/syntax/vi.yaml
index b45f7027..3c2df549 100644
--- a/runtime/syntax/vi.yaml
+++ b/runtime/syntax/vi.yaml
@@ -18,20 +18,10 @@ rules:
rules: []
- comment:
- start: "(^\"|[ \t]+\" |[ \t]+\"$)"
+ start: "^[ \t]*\""
end: "$"
rules: []
- - constant.string:
- start: "\""
- end: "\"|$"
- skip: "\\\\."
- rules:
- - constant.specialChar: "\\\\."
-
- - constant.string:
- start: "'"
- end: "'|$"
- skip: "\\\\."
- rules:
- - constant.specialChar: "\\\\."
+ - constant.string: '"[^"]*"'
+ - constant.string: "'[^']*'"
+ - constant.char: "\\\\." |
|
This ambiguity of |
|
Another option is to do nothing. Any "improvement" here would have pretty bad side effects, status quo is pretty bad too, but this is not a mission-critical functionality after all, it's just stupid syntax highlighting, it's just colors. |
|
Anyway, if we consider the last suggestion the least of the evils, I'm probably ok with it.
You probably meant |
* simplify string highlighting to reduce likelihood of false positive matches * highlight registers * support more keywords
c4cf040 to
955d8e5
Compare
@"/@'starting new strings)Known issue: Always ending strings at the end of line means we no longer properly highlight strings spanning multiple lines using line continuations. I don't think our syntax highlighting system is sophisticated enough to implement line continuations properly: without the backslashes you'd get syntax errors so it wouldn't make sense to highlight it as string. Doing multiline strings with line continuations seems to be quite rare in practice so I'm comfortable making this tradeoff to improve highlighting in the more common cases (the other parts are real examples from a popular vimrc repository).
Test file
before:
after: