Create your own syntax highlighting

    A bit of background. Not so long ago, I decided to join the w3af (Web Application Attack and Audit Framework) project . In this application, it is possible to automate repetitive actions using command scripts (such an analog of batch files and shell scripts). Constantly working with them, I thought, why did it all fade? And the idea was born to make a simple syntax highlighting for w3af scripts. Of course, you need to start by reading mana (: h syntax). In general, even at this moment, the depth of the WIM settings is pronounced. You can make your own syntax highlighting file. You can override an existing one and so on. To begin with, we will be interested in the MAKING YOUR OWN SYNTAX FILES section there. 1. If you don’t have one yet, create the ~ / .vim / syntax directory

    # This is a test for the 404 fingerprinting of the core
    plugins
    output console,textFile
    output
    output config textFile
    set fileName output-w3af.txt
    set verbose True
    back
    output config console
    set verbose False
    back
    discovery pykto,serverHeader

    discovery config pykto
    #set mutateTests True
    back

    back
    target
    set target localhost/w3af
    back
    start







    2. Here I liked the approach in mana the most:

    Write the Vim syntax file. Or download one from the internet. Then write it in your syntax directory.

    Well, that is, I kind of got it in mans to find out how to write such files, but here it is :) Well, okay, I took the Python syntax highlighting file as the basis. After we remove everything superfluous from there, save: w ~ / .vim / syntax / w3af.vim
    3. Hurray, now you can use your own highlighting scheme:: set syntax = mine

    Let us dwell on 2 points :)

    " Vim syntax file
    " Language: w3af file
    " Maintainer: Pento
    " Last change: 2008 Oct 12

    if version < 600
    syntax clear
    elseif exists("b:current_syntax")
    finish
    endif

    syntax sync fromstart

    syn keyword w3afStatement set back start assert plugins exploit profiles exit help
    syn match w3afComment "#.*$"

    if version >= 508 || !exists("did_w3af_syn_inits")
    if version <= 508
    let did_w3af_syn_inits = 1
    command -nargs=+ HiLink hi link
    else
    command -nargs=+ HiLink hi def link
    endif

    " The default methods for highlighting. Can be overridden later
    HiLink w3afStatement Statement
    HiLink w3afComment Comment
    delcommand HiLink
    endif

    let b:current_syntax = 'w3af'

    Statement - these are tokens common to all programming languages ​​(if I use this term correctly) like Function, Comment, etc. That is, in the end, you will operate with these general groups when coloring your file (see: h syntax section NAMING CONVENTIONS) keyword - syntax entity. Vim understands 3 such entities:

    1. keyword - ordinary keywords. No more and no less :) (: h syn-keyword)
    2. match - match the regular expression (: h syn-match). Conveniently, use this for example to define comments.
    3. region - the region between two “tags” (also reg. Expressions) (: h syn-region). In a python file, this is used to define strings.

    There is a nesting of these entities. You can also combine them into groups. After that, we already highlight a set of keywords:

    image

    Now it remains to set a new file type. To do this, add to ~ / .vimrc (or use modeline ...: h modeline):

    "Filetypes
    au BufRead, BufNewFile * .w3af set filetype = w3af

    Then, by analogy with the Python file, I added other highlighting rules. Actually , the number of different settings and tricks described in: h syntax is amazing, but what could you expect from an editor like Vim? =)
    Cross-post with Everything about Vim

    Also popular now: