VIM 自定义语法摇滚学派
我尝试压缩一些和弦文件,然后需要突出显示一些内容,使其更加直观。在这种语法中,和弦后面跟着一个逗号,然后是一个显示节拍数的数字,所有这些都用大括号括起来。这是您可能听过的一首经典摇滚歌曲的示例:
{Dm,4}Don't cry, don't {C/D,4}raise your eye
It's {Bb/D,2}on-ly {Am,2} teen-age {Dm,4hold}waste-land
我只想将和弦名称设置为一种颜色,将时间符号设置为另一种颜色...简而言之,这就是 { 和 next 之间的所有内容,作为一种颜色然后到下一个 } 作为第二种颜色。也许括号也应该是另一种颜色。我不擅长正则表达式,但我希望这个论坛可以为我指明正确的方向,最终掌握它们。
I try to compact some chord files and then need to highlight some stuff so it is more visual. This syntax is where chord is followed by a comma then a number showing how many beats, and all surrounded in curly brackets. Here is the example from a classic rock song you might have heard:
{Dm,4}Don't cry, don't {C/D,4}raise your eye
It's {Bb/D,2}on-ly {Am,2} teen-age {Dm,4hold}waste-land
I simply want to make the chord names one color, and the time notation another color... In a nutshell that's everything between { and next , as one color then up to the next } as a second color. Maybe the brackets should be another color too. I suck at regular expressions but this forum can point me in right direction to eventually master them I hope.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个非常简单的版本,仅突出显示整个
{...}
块。将以下内容放入${HOME}/.vim/syntax/rock.vim
中:将以下内容放入
${HOME}/.vim/ftDetect/rock.vim
中:现在,每当您打开
.rock
文件时,和弦都应该突出显示。 (如果检测不起作用,请尝试手动设置:set filetype=rock
,看看它是否会改变某些内容。)请注意,如果您从 Vim 编辑了这些文件,则可能需要重新启动它才能生效要应用的效果。这是一个较长的版本,其中和弦和时间指示以不同的颜色突出显示:
如您所见,我的和弦正则表达式有点疯狂。它支持诸如 A#m7b5/Db 之类的东西,这当然没什么意义(而且听起来很糟糕),但你明白了。
Here is a very simple version that will just highlight the whole
{...}
blocks. Put the following in${HOME}/.vim/syntax/rock.vim
:And the following in
${HOME}/.vim/ftdetect/rock.vim
:Now whenever you open a
.rock
file, the chords should be highlighted. (If detection doesn't work, try to set:set filetype=rock
manually, see if it changes something.) Note that if you edited these files from Vim, you may need to restart it for the effects to apply.Here is a longer version, where chords and time indications are highlighted in different colors:
As you can see, my regexp for chords got a little wild. It supports things like
A#m7b5/Db
, which of course makes little sense (and sounds horrible), but you get the idea.