Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3595236
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:49:32+00:00 2026-05-18T19:49:32+00:00

Is it possible to comment a macro and replay it. Example instead of dddwj

  • 0

Is it possible to comment a macro and replay it.

Example

instead of

  dddwj

I would like to comment and execute following fragment

  dd # Delete line
  dw # Delete word
  j  # Move to next line

Some background

We use PICT to generate testcase inputs (All Pair testing). As this is an iterative process, the macro for generating code needs tweaking between subsequent runs. It’s hard to modify a macro when everything is on one line, without comments.

The output of a PICT run might be something like this:

1 cInstallationX Pu380
2 cInstallationY U400

wich can be converted to testcases with a macro

procedure TWatchIntegrationTests.Test1;
begin
  //***** Setup
  builder
    .withInstallation(cInstallationX)
    .withIsotope(Pu380)
  .Build;

  //***** Execute
  CreateAndCollectWatches;

  //***** Verify
  VerifyThat
    .toDo;
end;

procedure TWatchIntegrationTests.Test2;
begin
  //***** Setup
  builder
    .withInstallation(cInstallationY)
    .withIsotope(U400)
  .Build;

  //***** Execute
  CreateAndCollectWatches;

  //***** Verify
  VerifyThat
    .toDo;
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T19:49:33+00:00Added an answer on May 18, 2026 at 7:49 pm

    I don’t know a good way of doing this with macros, but there are a few options that I can see that might help:

    Heavy use of ‘normal’

    This is the closest to your macro option, but not very nice: make your saved file look like this:

    " Delete line
    normal dd
    " Delete word
    normal dw
    " Move to next line
    normal j
    

    Complicated Substitution

    This makes use of regular expressions, but makes those regular expressions be well commented (this is based on your actual example).

    let pattern  = '^'              " Start of line
    let pattern .= '\(\d\+\)'       " One or more digits (test number)
    let pattern .= '\s\+'           " Space or tab as delimiter
    let pattern .= '\(\k\+\)'       " Installation name
    let pattern .= '\s\+'           " Space or tab as delimiter
    let pattern .= '\(\a\+\d\+\)'   " One or more alphabetic characters, then one or more spaces (isotope)
    let pattern .= '\s*$'           " Any spaces up to the end of the line
    
    let result  = 'procedure TWatchIntegrationTests.Test\1;\r'
    let result .= 'begin\r'
    let result .= '  //***** Setup\r'
    let result .= '  builder\r'
    let result .= '    .withInstallation(\2)\r'
    let result .= '    .withIsotope(\3)\r'
    let result .= '  .Build;\r'
    let result .= '\r'
    let result .= '  //***** Execute\r'
    let result .= '  CreateAndCollectWatches;\r'
    let result .= '\r'
    let result .= '  //***** Verify\r'
    let result .= '  VerifyThat\r'
    let result .= '    .toDo;\r'
    let result .= 'end;\r'
    
    exe '%s!' . pattern . '!' . result . '!'
    

    Stick it in a function

    Given that this is getting rather complicated, I’d probably do it this way as it gives more room for adjustment. As I see it, you want to split the line on white space and use the three fields, so something like this:

    " A command to make it easier to call
    " (e.g. :ConvertPICTData or :'<,'>ConvertPICTData)
    command! -range=% ConvertPICTData <line1>,<line2>call ConvertPICTData()
    
    " Function that does the work
    function! ConvertPICTData() range
        " List of lines producing the required template
        let template = [
                    \ 'procedure TWatchIntegrationTests.Test{TestNumber};',
                    \ 'begin',
                    \ '  //***** Setup',
                    \ '  builder',
                    \ '    .withInstallation({Installation})',
                    \ '    .withIsotope({Isotope})',
                    \ '  .Build;',
                    \ '',
                    \ '  //***** Execute',
                    \ '  CreateAndCollectWatches;',
                    \ '',
                    \ '  //***** Verify',
                    \ '  VerifyThat',
                    \ '    .toDo;',
                    \ 'end;',
                    \ '']
    
        " For each line in the provided range (default, the whole file)
        for linenr in range(a:firstline,a:lastline)
            " Copy the template for this entry
            let this_entry = template[:]
    
            " Get the line and split it on whitespace
            let line = getline(linenr)
            let parts = split(line, '\s\+')
    
            " Make a dictionary from the entries in the line.
            " The keys in the dictionary match the bits inside
            " the { and } in the template.
            let lookup = {'TestNumber': parts[0], 
                        \ 'Installation': parts[1],
                        \ 'Isotope': parts[2]}
    
            " Iterate through this copy of the template and 
            " substitute the {..} bits with the contents of
            " the dictionary
            for template_line in range(len(this_entry))
                let this_entry[template_line] = 
                            \ substitute(this_entry[template_line], 
                            \   '{\(\k\+\)}', 
                            \   '\=lookup[submatch(1)]', 'g')
            endfor
    
            " Add the filled-in template to the end of the range
            call append(a:lastline, this_entry)
        endfor
    
        " Now remove the original lines
        exe a:firstline.','.a:lastline.'d'
    endfunction
    

    Do it in python

    This is the sort of task that is probably easier to do in python:

    import sys
    
    template = '''
    procedure TWatchIntegrationTests.Test%(TestNumber)s;
    begin
      //***** Setup
      builder
        .withInstallation(%(Installation)s)
        .withIsotope(%(Isotope)s)
      .Build;
    
      //***** Execute
      CreateAndCollectWatches;
    
      //***** Verify
      VerifyThat
        .toDo;
    end;
    '''
    
    input_file = sys.argv[1]
    output_file = input_file + '.output'
    
    keys = ['TestNumber', 'Installation', 'Isotope']
    
    fhIn = open(input_file, 'r')
    fhOut = open(output_file, 'w')
    
    for line in fhIn:
        parts = line.split(' ')
        if len(parts) == len(keys):
            fhOut.write(template % dict(zip(keys, parts)))
    fhIn.close()
    fhOut.close()
    

    To use this, save it as (e.g.) pict_convert.py and run:

    python pict_convert.py input_file.txt
    

    It will produce input_file.txt.output as a result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to comment some lines in my Zend application.ini file. Is it possible
Is it possible with ASDoc to include example MXML code in your comment? /**
Is it possible to add a metadata-like description or comments to a table in
Is it possible to do something like this #ifdef SOMETHING #define foo // #else
I would like some tool, preferably one that plugs into VS 2008/2010, that will
I would like to have my scripts keep track of thier last date of
I have a messages page where it is possible to comment on every message.
Possible Duplicate: Why are Hexadecimal Prefixed as 0x? I just saw a comment a
I was curious if it is possible to add a SQL header comment to
as per the title; is it possible to have nested comments in valid HTML?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.