0

我已经使用 vim 几个月了,我仍然在尝试改善我对这个伟大编辑器的体验。

我尝试做的是为香料网表(电子资料)创建一个语法高亮文件。

我试图强调以下模式:

.SUBCKT or_gate AB OUT

(*or_gate* 是该单元的单元
ABOUT bieng 引脚的名称)

我尝试做的是用 3 种不同的颜色突出显示它:

  • 一个用于 .SUBCKT
  • 一个用于 or_gate (单元格)
  • 一个用于 A、B 和 OUT(引脚)

所以我正在查看以 .SUBCKT 开头的行,并试图找到一种方法来匹配该行的不同单词。

我尝试了很多不同的syn match组合或嵌套syn region但我只是觉得我做错了。

这是我尝试之一的示例:

syn region spiceCKT start ="\.SUBCKT" end ="$"包含=spiceCell,spicePins

syn region spiceCell start ="\.SUBCKT"rs=e end ="$"包含

syn region spicePins start ="\.SUBCKT\s\S*"rs=e end ="$"包含

I tried to play with the pattern (\s\S*), to add/remove the rs=e parts, or even to define the start or end patterns adding \zs and \ze.

In the end I did not manage to make it work and I just feel like I'm making it way more complicated that it should be.

Anyone could help me figuring out what are my mistakes and how to handle such pattern highlighting?

4

2 回答 2

2

You could try syn match with look-behind:

syn match spiceCKT /^\s*\.SUBCKT/
syn match spiceCell /\v(^\s*\.SUBCKT\s+)@<=or_gate/
syn match spicePins /\v(^\s*\.SUBCKT\s+or_gate\s+)@<=A B OUT/

I just did a small test. I don't have your syntax groups, I just tried with default groups, it looks like this:

enter image description here

于 2013-03-30T20:47:49.917 回答
0

Thank you for your answer! It does work. Thank you for the tip.

The only drawback is that it's a bit slow when the file has to load complete lines.

I complete your code to fit my needs:

syn match spiceCKT /^\s*.SUBCKT/

syn match spiceCell /\v(^\s*.SUBCKT\s+)@<=\S*\s+/

syn match spicePins /\v(^\s*.SUBCKT\s+or_gate\s+)@<=(\s*\S*)*/

The lines with @<= are making the screen a bit laggy when I scroll down. I'm still trying to work on it.

于 2013-04-02T20:43:27.023 回答