0

I'm trying to replace an entire nav menu section of a website which means there's multiple files that need to change and there isn't a multi-line "find and replace" inside atom editor which works across multiple files. I have tried the suggestion of Ctrl+E that I found on stack exchange but the shortcut is not working for me.

Is there a plugin or something that will let me do this? If not then can someone suggest a free text editor that will. I've tried it on Notepad++ with a multi-line replacement plugin that I found but that keeps crashing for me and also doesn't replace across multiple files. Edit: ie. the plugin doesn't replace across multiple files, not Notepad++

Thanks in advance.

Edit for Toto: I'm trying to replace and entire navigation menu on about 77 webpages.

       <div class="inner-nav desktop-nav">
        <ul class="clearlist">
            <!-- Item-->
                            <!-- End Item -->
            <!-- Item-->
            <li>
                <a href="index.html#main-slider" class="">Home</a>
            </li>
            <!-- End Item -->
            <!-- Item-->
            <li>
                <a href="about.html">About us</a>
            </li>
            <!-- End Item -->
            <!-- Item-->
            <li>
                <a href="index.html#news" class="">News</a>
            </li>
            <!-- End Item -->
            <!-- Item-->
            <li>
                <a href="products.html">Products</a>
            </li>
            <!-- End Item -->
            <!-- Item-->
            <li>
                <a href="career.html"> </a>
            </li>
            <!-- End Item -->
            <!-- Item-->
            <li>
                <a id="menu-contact" href="index.html&contact=true#contact">Contact us</a>
            </li>
            <!-- End Item -->
            <!-- Item-->
                            <!-- End Item -->
            <!-- Divider -->
            <li><a>&nbsp;</a></li>
            <!-- End Divider -->
            <!-- Search -->
            <!--<li>
              <a href="#" class="mn-has-sub"><i class="fa fa-search"></i> Search</a>
              <ul class="mn-sub">
                <li>
                  <div class="mn-wrap">
                    <form method="post" class="form">
                      <div class="search-wrap">
                        <button class="search-button animate" type="submit" title="Start Search">
                        <i class="fa fa-search"></i>
                        </button>
                        <input type="text" class="form-control search-field" placeholder="Search...">
                      </div>
                    </form>
                  </div>
                </li>
              </ul>
            </li>-->
            <!-- End Search -->
        </ul>
    </div>

Trying to replace the above code with the below.

   <div class="inner-nav desktop-nav">
        <ul class="clearlist">
            <li>
                <a href="index.html#main-slider" class="">Home</a>
            </li>
            <li>
                <a href="about.html">About us</a>
            </li>
            <li>
                <a href="index.html#news" class="">News</a>
            </li>
            <li>
                <a href="products.html">Products</a>
            </li>
            <li>
                <a id="menu-contact" href="index.html#contact">Contact us</a>
            </li>
        </ul>
    </div>
1
  • Notepad++ works on multiple files. Could you explain what you are trying to do with examples? Actual content of files and expected result.
    – Toto
    Commented Apr 3, 2021 at 13:28

2 Answers 2

1

As far as I understand, you want to remove comments and some specific <li>.

  • Ctrl+Shift+F
  • Find what: \s*<!--[\s\S]+?-->\s*(?=\R)|<li>\s+<a href="career.html">[\s\S]+?</li>|<li><a>&nbsp;</a></li>
  • Replace with: 0
  • Filters: Whatever you want
  • Directory: Path\where\your\files\are
  • Replace with: LEAVE EMPTY
  • CHECK Match case
  • CHECK Regular expression
  • UNCHECK . matches newline
  • Replace in Files

Explanation:

\s*                 # 0 or more spaces including linebreak
<!--[\s\S]+?-->     # a block of comments
\s*                 # 0 or more spaces including linebreak
(?=\R)              # positive lookahead, any kind of linebreak
|                   # OR
<li>\s+<a href="career.html">[\s\S]+?</li>      # specific <li>
|                   # OR
<li><a>&nbsp;</a></li>      # specific <li>

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

1
  • Thank you so much for this. Unfortunately there's a line that says "<a id='menu-contact' href='index.html&contact=true#contact'>Contact Us</a>" that needs to change to "<a id='menu-contact' href='index.html#contact'>Contact Us</a>" Thanks for the solution though, it's brilliant.
    – Chamkey
    Commented Apr 3, 2021 at 16:09
0

I found a solution: Sublime Text, even the "Unregistered", has this functionality.

  1. Download and install Sublime Text
  2. Once installed, open Sublime Text
  3. Open the folder that you would like to replace all text within, in Sublime Text
  4. Open the find menu in the context strip at the top of Sublime Text.
  5. Go to "Find in Files" in the drop down menu of the context strip menu item that you just opened
  6. Click on "Find in Files"
  7. At the bottom of the file that's currently open, a find and replace menu opens up
  8. Copy the thing that you want to replace into the find text box
  9. Copy the thing that you want in its place into the replace text box
  10. Click on the "Replace" button at the bottom right of the Sublime Text window
3
  • Can you provide specifics to your solution?
    – Ramhound
    Commented Apr 3, 2021 at 15:33
  • @Ramhound note that I've answered my own question.
    – Chamkey
    Commented Apr 3, 2021 at 15:38
  • It wasn't immediately apparent you were the question author when I reviewed your answer.
    – Ramhound
    Commented Apr 3, 2021 at 15:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .