Vim syntax highlighting

妖精的绣舞 提交于 2019-12-10 23:35:58

问题


Alright, this is probably a stupid question, but....

I've got a file of source code in a proprietary language. I want to edit said file with VIM, instead of their crummy editor. I'd like basic syntax highlighting of the language, but I don't want to spend a bunch of time rolling my own syntax file.

Therefore, does VIM have a basic source highlighting module? It doesn't need to be perfect, I just want it to cover simple things. Currently, my only choices are no syntax highlighting, pick a random language, or roll my own.

EDIT: Source code sample below

{
    function letter do
        gposition 0, 0
        if gender = "M" do
            if language = "SPA" OR state = "PR" do
                %male spanish letter
                gposition .26, .75
                pdfimage "MALE SPANISH.pdf", 1, .93

                setcolor truewhite
                setfillmode 1
                %whitebox
                gposition 5.25, 1.25
                rectangle 2.5, .5

回答1:


Could this be the correct language?

http://www.iml.ece.mcgill.ca/~stephan/node/17




回答2:


Rolling your own syntax highlighting is not difficult at all and it would take a few minutes.

For example, I wrote a DSL (called Konira) that uses Python for the most part, but it fails at highlighting my custom DSL statements. This is how the "extra" highlighting looks:

function! KoniraSyntax() abort
    let b:current_syntax = 'konira'
    syn match KoniraIt                   '\v^\s+it\s+'
    syn match KoniraSkipIf               '\v^\s+skip\s+if'
    syn match KoniraDescribe             '\v^describe\s+'
    syn match KoniraRaises               '\v^\s+raises\s+'
    syn match KoniraBeforeAll            '\v^\s+before\s+all'
    syn match KoniraBeforeEach           '\v^\s+before\s+each'
    syn match KoniraAfterEach            '\v^\s+after\s+each'
    syn match KoniraAfterAll             '\v^\s+after\s+all'

    hi def link KoniraSkipIf             Statement
    hi def link KoniraIt                 Statement
    hi def link KoniraDescribe           Statement
    hi def link KoniraRaises             Identifier
    hi def link KoniraBeforeAll          Statement
    hi def link KoniraBeforeEach         Statement
    hi def link KoniraAfterAll           Statement
    hi def link KoniraAfterEach          Statement
endfunction

As you can see above, I set the current syntax, then I match via regular expression those statements that I want, and the I apply the type of highlighting that I need on that match.

And you can call it as a regular function when you know (or if you able to detect) that you are editing such a source file:

call KoniraSyntax()


来源:https://stackoverflow.com/questions/6386085/vim-syntax-highlighting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!