Update duplicate blocks of text in multiple files from Visual Studio 2012/2010 with Sync Block Edit extension

It is undesirable, but often necessary to have duplicate blocks of text in multiple files. For example, Google Analytics tracking code in html files or copyright notices in code files. When you need to update this text, sometime you can do it with a simple search and replace. But when you want to make sure no other text is changed or when you want to add or remove lines, multiline search and replace is necessary. Sync Block Edit hides all the complexity of writing multiline find and replace patterns from you.

If your text is already enclosed with distinct begin and end signature lines, just make your changes in one of the files, select the block and click the Sync Update Block button from the Sync Block Edit toolbar:

Update text with Sync Block Edit

Update text with Sync Block Edit

In the Update Text dialog, begin and end lines are automatically filled. You select which files you want to update and click Update. In all files the text between the begin and end lines will be replaced with the selected text from the active document.

If your block in not yet enclosed, it is recommended to add distinct begin and end signature lines before modification. Select the block in one of the files and click the Sync Create Block button from the Sync Block Edit toolbar:

Create block with Sync Block Edit

Create block with Sync Block Edit

In the Create Block dialog enter begin and end lines. Select which files you want to update and click Create. In all files this text block will be enclosed with the begin and end lines. After that you can update the block as described above.

You can download the free Sync Block Edit extension for Visual Studio 2010 and Visual Studio 2012 from the Sync Block Edit homepage.

This entry was posted in Vlasov Studio tools and tagged , , . Bookmark the permalink.

5 Responses to Update duplicate blocks of text in multiple files from Visual Studio 2012/2010 with Sync Block Edit extension

  1. Arthur says:

    Hi Sergei,
    Did you submit this as an extension to the Visual Studio gallery? I did not find it by name ‘Sync Update Block’, but thinking it would help developers to discover it and you also promote TabsStudio.

  2. arthurz says:

    Agree, I was able to find it.
    And now as a test I did this: I opened a Database project in VS 2012 and created a block inside a stored procedure, e.g.
    // test start – generated by tool
    — group by begin
    replace this
    — group by end
    // test end – generated by tool

    I had two files open, one is abc.sql, another xyz.sql, these blocks exist in both of them with the only difference being in the text ‘replace me too’ versa ‘ must be replaced.
    I made the choice in update – “All Open Documents”. I then ran the tool, but the 2nd file was not chosen for updates. I expected it to,
    In the Find Results 1 I see:
    Replace all “^// test start\r?\n(.|\r?\n)*?^// test end\r?\n”, “// test start
    — group by begin
    replace me too
    — group by end
    // test end
    “, Match case, Regular expressions, Find Results 1, All Open Documents
    C:\Users\Test\Documents\Visual Studio 2012\Projects\SandBoxDatabaseProject\SandBoxDatabaseProject\dbo\Stored Procedures\AvailLog_bk_Delete.sql(20,1):// test start
    AvailLog_bk_Delete.sql is listed but not AvailLog_bk_Load.sql that is open alongside.
    What am I doing wrong?

    • Arthur,

      I can reproduce this problem with a Database project. Looks like VS doesn’t consider .sql files as part of open documents.

      If I select target Solution, update works.
      If I have only two sql files opened and open VS Find and Replace dialog, it doesn’t offer Look in All Open Documents at all.
      If I open an additional .cs file and then try to replace something in .sql as All Open Documents (in VS Find and Replace), it replaces only in the current .sql file.

  3. arthurz says:

    Sergei:
    I posted a MS Connect item https://connect.microsoft.com/VisualStudio/feedback/details/774024/all-open-documents-option-in-find-repace-dialog-does-not-work-for-sql-documents-database-projects asking to resolve this nuance, please feel free to vote, but until it is fixed perhaps this extension needs to be disabled when a developer is in a Database project.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s