Windows – How to select everything between tags in Notepad++

keyboard shortcutsnotepadwindows

I am doing some langauge translations of an old HTML website so I am just pasting the new translations from a Word document into the old files.

So I have to select everything between the tags (h2, p, li, etc.) and then paste the new text in – from a Word file. For selecting everything in between p tags I have to select one side of the inside tag, then hold Shift, then select the next side to highlight everything… my fingers are getting really tired, and I got 40 files (pages) total with 3 languages to do.

Is there a shortcut in Notepad++ to select everything between two tags (excluding the tags; like when you double click a word it selects the whole word).

<p>This is some English that needs to be translated here. 
I want to just click in this area to select all of this 
text between these two paragraph tags.</p>
<p>This would be another block of translation to do</p>
    <li>I want to click here and select everything between the li tags</li>

Best Answer

Direct answer:: No.

Can it be made? Yes.
Simply? Yes.
Into a single shortcut? Yes

What's needed? N++ PythonScript and HTML Tag plugins.

Why? We are going to use the HTML Tag's Select Tag and Contents from a python script that will adjust the selection made by HTML Tag by moving the start to just after the first '>' and the end to just before the last '<'.

After installing the N++ PythonScript plugin create a new script with this code::

# Reduce selection to omit the outer most tags selected by the 'HTML Tag' plugin.

from Npp import *

def omit_tag( args ):
    SelText = editor.getSelText()

    if SelText:
        orig_Start = editor.getSelectionStart()
        new_Start = orig_Start + SelText.find(">")

        orig_End = editor.getSelectionEnd()
        new_End = orig_Start + SelText.rfind("<")

        if new_Start > orig_Start and new_End < orig_End:
            editor.setSel( new_Start + 1, new_End )

def main():
    editor.callback( omit_tag, [SCINTILLANOTIFICATION.UPDATEUI] )
    notepad.runMenuCommand("HTML Tag", "Select Tag and Contents")


After creating the script, use the PythonScript configuration dialog to add the script to the 'Menu Items' list (which will allow us to assign the shortcut). Restart, then use the Settings->Shortcut Mapper::Plugins dialog, add a Shift+Alt+T shoftcut to the new entry for the script you just created. Restart again to write out the new shortcut entry the N++ config.

So now (using your sample text), from the line where you wanted to click::

CTRL+T to jump to the other tag.
CTRL+Shift+T to select the whole tag block.
Shift+Alt+T to select the inner text.

If you attempt to select the 'content' portion of the block you'll notice the line endings are captured too. This could be seen as either a plus or minus depending on your viewpoint...

One recommendation, make use of SCI_SWAPMAINANCHORCARET to allow you to adjust either end of your selection using the normal movement and selection modifiers. You can set it from the shortcut mapper on the Scintilla panel (near the bottom). I've set mine to CTRL+Shift. which works great, since when already modifying a selection Shift is usually already pressed.

Hopefully that helps. Have fun!