简体   繁体   中英

converting vim syntax highlighting into vscode syntax highlighting

I've looked around - and could not find a way to automatically do this. so:

I have some syntax highlighting I built in vim I want to transfer over to vscode. and I'm getting stuck on at least 2 parts.

so far here's where I'm at: I've build a vscode language extension - set up some basic syntax rules, and have that copied over to the vscode config folder.

the parts I'm having trouble with - I could use some clarity in what some fields mean - naming conventions.

and nested parsing of syntax, things only appearing in other elements.

below is the bit I added on top of the vim-markdown syntax.

syntax region spokenWord start=/\v"/ skip=/\v\\./ end=/\v"/ contained
syntax region thoughtWord start=/\v'/ skip=/\v\\./ end=/\v'/ contained
syntax region codeWord start=/\v`/ skip=/\v\\./ end=/\v`/ contained contains=objkw,spokenWord,thoughtWord,action,description,executekw
syntax region action start=/\v*/ skip=/\v\\./ end=/\v*/ contained
syntax region description start=/\~/ skip=/\v\\./ end=/\~/ contained

syntax match executekw "[e][x][e]\s" contained
syntax match objkw "[.][\w]+" contained
syntax region BLOCK start=/{/ skip=/\s+/ end=/}/ contains=spokenWord,thoughtWord,codeWord,action,description

highlight link spokenWord String
hi thoughtWord ctermfg=red
hi codeWord ctermfg=gray
highlight link action function
highlight link description Statement
hi BLOCK guibg=#FF00FF ctermfg=magenta cterm=bold guifg=#00FF00
hi exepm ctermfg=green
hi objP ctermfg=red
hi fntk ctermfg=blue
hi fnnm ctermfg=130
hi executekw ctermfg=130
hi objkw ctermfg=130

which results in this look: 配色方案

what I have so far for the vs code syntax is as follows:

{
    "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
    "name": "MDX",
    "patterns": [
        {
            "include": "#keywords"
        },
        {
            "include": "#strings"
        },
        {
            "include":"#thought"
        },
        {
            "include":"#action"
        },
        {
            "include":"#description"
        },
        {
            "include":"#code"
        },
        {
            "include":"#block"

        },
        {
            "include":"#object"
        }
    ],
    "repository": {
        "keywords": {
            "patterns": [{
                "name": "keyword.control.markdownextened",
                "match": "\\b(EXE|IF|WHILE|FOR|RETURN)\\b"
            }]
        },
        "strings": {
            "name": "string.quoted.double.markdownextened",
            "begin": "\"",
            "end": "\"",
            "patterns": [
                {
                    "name": "constant.character.escape.markdownextened",
                    "match": "\\\\."
                }
            ]
        },
        "thought":{
            "name": "thought.quoted.single.markdownextened",
            "begin": "'",
            "end": "'",
            "patterns": [
                {
                    "name": "constant.character.escape.markdownextened",
                    "match": "\\\\."
                }
            ]
        },
        "action":{
            "name": "action.asterisk.markdownextened",
            "begin": "*",
            "end": "*",
            "patterns": [
                {
                    "name": "constant.character.escape.markdownextened",
                    "match": "\\\\."
                }
            ]
        },
        "description":{
            "name": "action.tilde.markdownextened",
            "begin": "~",
            "end": "~",
            "patterns": [
                {
                    "name": "constant.character.escape.markdownextened",
                    "match": "\\\\."
                }
            ]
        
        },
        "code":{
            "name": "action.grave.markdownextened",
            "begin": "`",
            "end": "`",
            "patterns": [
                {
                    "name": "constant.character.escape.markdownextened",
                    "match": "\\\\."
                }
            ]
        
        },
        "block":{
            "name": "action.braces.markdownextened",
            "begin": "{",
            "end": "}",
            "patterns": [
                {
                    "name": "constant.character.escape.markdownextened",
                    "match": "\\\\."
                }
            ]
        },
        "object":{
            "name": "action.object.markdownextened",
            "patterns": [
                {
                    "name": "action.object.markdownextened",
                    "match": "/[.][\\w]/"
                }
            ]
        }
    },
    "scopeName": "source.markdown"
}

I could not find a guide anywhere on converting vim syntax highlighting into vscode syntax highlighting. I'll be reading though the documentation until I figure this out - but would love some help!

Are you wanting to do a one off conversion
or a tool to continuously convert a large amount of highlighters?

I doubt there will be many, if at all any, large public vim to vscode converters tools

I am going to assume your vscode example above is working
and you have read up on pages like

Your First Extension Visual Studio Code Extension

Syntax Highlight Guide Visual Studio Code Extension

Writing a TextMate Grammar Some Lessons Learned
oniguruma/RE at master kkos/oniguruma

I would highly suggest looking at other people's highlighters Where are extensions installed?
and download a TextMate syntax highlighter
TextMate Languages or (my own) Text Mate Language Syntax Highlighter

Colours are defined by your current theme
Your theme defines colours based on the scopename that you give to each token in your highlighter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM