Alt + Left Click to select specifc text within a column.



  • Hi,

    When I use Alt + Left click to select a specific block of text within a column I wish to use find/replace to replace specific text within that selection. The issue is that when you do this the “In Selection” tick box in find / replace is now greyed out. Is there anyway to get around this without taking the text out of Notepad++ making the changes and then putting back into Notepad++?

    Many thanks,



  • @Matt-Barwick Short of editing the program’s source code, I don’t think so.

    Kudos on coming up with a smart work-around, however!



  • Thanks for the response Jim, I have fortunately been able to do this outside of Notepad++ with TextPad.



  • … without taking the text out of Notepad++…then putting back into Notepad++

    I suggest the following workflow:

    1. Select Column (Alt + LeftClick)
    2. Copy
    3. New Tab (Ctrl + N)
    4. Paste in new tab
    5. Search and Replace
    6. Select Column from the new tab
    7. Switch back to original tab
    8. (In my experiment, the column was still highlighted in the original; if not highlighted for you, reselect the column in the original)
    9. Paste
    10. Close the new tab without saving

    That prevents you from having to use a separate application for the search-and-replace… though it does require you to take the text out of the original document.



  • @PeterCJ-AtWork many thanks for the input Peter this works well if I make sure I Alt+LC to select the data in the new tab that I am going to paste back into the original.

    If you manually select using LC only or do select all in the new tab you end up with the below:

    Example:
    Data:
    A B
    A B
    A B
    A B
    A B
    A B
    A B
    A B

    Alt+LC to select all A’s in column 1.
    CTRL+C to copy
    CTRL+N to open new tab
    CTRL+V to paste
    Search and Replace criteria: Replace A with C.
    Data in new tab now looks like(as A has been replaced by C):
    C
    C
    C
    C
    C
    C
    C
    C
    SELECT ALL(this is where you actually need to use ALT+LC again)
    CTRL+C to copy
    Back to previous tab(data is indeed still highlighted)
    CTRL+V to paste to highlighted area(column 1)
    Data now looks like:
    C
    C
    C
    C
    C
    C
    C
    C B
    C
    C
    C
    C
    C
    C
    C
    C B
    C
    C
    C
    C
    C
    C
    C
    C B
    C
    C
    C
    C
    C
    C
    C
    C B
    C
    C
    C
    C
    C
    C
    C
    C B
    C
    C
    C
    C
    C
    C
    C
    C B
    C
    C
    C
    C
    C
    C
    C
    C B
    C
    C
    C
    C
    C
    C
    C
    C B

    I will ensure I use ALT+LC only for this exercise.

    Many thanks again for the input,

    Matt



  • Hello Matt, PeterCJ AtWork and All,

    In your post, Matt, it seems, that you copied a normal selection in the new tab that gave you, once pasted in the original tab, the result exposed in your last post.

    But, if you copy the replaced text, of the new tab, with a rectangular selection, it, then, will overwrite correctly the rectangular selection, of your original text !

    So, to sum up :

    • Select a rectangular area, in your text, which needs replacement(s), with, either :

      • The ALT key and the arrow keys ( up, down, left and right )

      • The mouse gesture ALT + a moving left click

    • Copy that selection ( CTRL + C )

    • Open a new tab ( CTRL + N )

    • Paste the selection in that new tab ( CTRL + V )

    • Perform classical replacement(s) on the text of this new tab

    • Select, again, in the new tab, a rectangular selection, which contains all the replaced text

    • Switch back to your original text, which, normally, should have kept the original rectangular selection

    • Just paste the contents of the clipboard ( CTRL + V )

    => The contents of the rectangular selection, of the replaced text, will overwrite the original rectangular selection, of the text that was to be changed :-)


    However, if your text contains numerous lines, it’s not very easy to build the exact rectangular selection needed :-(( So I’m going to explain a general method, in order to change text, ONLY between two columns c1 and c2 and between two lines n1 and n2 !

    This method, of course :-), uses regular expressions and needs two symbol characters, NOT USED, YET, in your file, to simulate :

    • The zero length position, between the column c1 - 1 and the column c1

    • The zero length position, between the column c2 and the column c2 + 1

    I chose the # character, for the former and the @ character, for the later. Of course, any symbol can be chosen !

    But, if you choose a meta-character of regular expressions ( the 13 characters . , [ , {, } , ( , ) , \ , * , + , ? , ^ , $ and | ), you’ll have to escape each of them with an antislash \, in the search regex, in order to consider this symbol as a literal symbol !


    We’ll work with the 6 lines example text, below :

    1234567890ABC456789012345678901234567DEF1234567890
    12345678901234567ABCDEF4567ABC1DEF
    1234567890ABC45678901DEF5678901234567ABC12ABC6DEF0
    
    1234ABC89012345678901234ABC89012DEF678901234567890
    123456ABC01DEF5ABC9012345678DEF234567ABC1DEF567890
    

    In this example :

    • The lines 1, 3, 5 and 6 contain, each, 50 characters
    • The line 2 is, only, 34 characters long
    • The line 4 is an empty line

    Let’s suppose that we would like to get a rectangular selection, between the columns 11 and 40, over these 6 lines. In that case :

    • Select your rectangular selection, between the columns 11 and 40, on the 6 lines

    • First, copy that rectangular selection, with CTRL + C

    • Type in the two characters #@

    • Hit the left arrow key => your cursor should be on the line 1 , between the two characters # and @

    • Paste your rectangular selection, with CTRL + V

    Now, your text should be changed into the text, below :

    1234567890#ABC456789012345678901234567DEF@1234567890
    1234567890#1234567ABCDEF4567ABC1DEF@
    1234567890#ABC45678901DEF5678901234567ABC@12ABC6DEF0
              #@
    1234ABC890#12345678901234ABC89012DEF67890@1234567890
    123456ABC0#1DEF5ABC9012345678DEF234567ABC@1DEF567890
    

    Globally, the general syntax of my regex is (?!.*#)Regex(?=.*@).

    Notes :

    • In the Replace dialog ( CTRL + H ) :

      • Set the regular expression search mode ( IMPORTANT )

      • Fill in the two zones Find what and Replace with ( See, below ! )

      • Check the options, Match case and/or Wrap around, as you like

    • To do the search/replacement, between lines n1 and n2 :

      • Create a NORMAL selection of all the concerned lines, from line n1 to line n2, included

      • Open the Replace dialog

      • If necessary, check the In selection option

    • Regex may, also, represent a simple literal string, even a single character !

    • Regex is taken in account, ONLY IF :

      • a # character is NEVER found, further on, in the current line

      • a @ character is ALWAYS found, further on, in the current line

    As you can imagine, to obey, simultaneously, these two conditions, means, automatically, that the regex engine will match text only found, between these two boundaries # and @ :-)) Nice !

    • The negative look-ahead (?!.*#) and the positive look-ahead (?=.*@) generate these two conditions, which have to be true to get a positive match, although they never participate to the final match

    To end with, three REAL examples :

    A) Let’s suppose that you’re looking for the smallest string, beginning with the 3 upper letters ABC and ending with the 3 upper letters DEF. A corresponding regex could be (?-i)ABC.*?DEF

    Then, embedded in my regex, we obtain the final search regex :(?!.*#)(?-i)ABC.*?DEF(?=.*@). If the replacement regex is, for instance, the range of lower letters ghijklnopqrs, we’ll obtain the replaced text, below :

    1234567890#ghijklnopqrs@1234567890
    1234567890#1234567ghijklnopqrs4567ghijklnopqrs@
    1234567890#ghijklnopqrs5678901234567ABC@12ABC6DEF0
              #@
    1234ABC890#12345678901234ghijklnopqrs67890@1234567890
    123456ABC0#1DEF5ghijklnopqrs234567ABC@1DEF567890
    

    You, easily, notice that if a range ABC.....DEF, begins before the # character and/or ends after the @ character, it is NOT replaced. Quite logical, as it’s partially or totally, outside the wanted area column 11 - column 40

    B) A second example : you want to catch any integer number, without sign, as 12, 7895 or 0. Easily done with the simple regex \d+ or [0-9]+ !

    Therefore, the final search regex is, simply, (?!.*#)\d+(?=.*@). Now, let’s suppose that we want to surround these numbers by two square brackets []. A possible replacement regex could be [$0]

    This time, the replaced text will be, as below :

    1234567890#ABC[456789012345678901234567]DEF@1234567890
    1234567890#[1234567]ABCDEF[4567]ABC[1]DEF@
    1234567890#ABC[45678901]DEF[5678901234567]ABC@12ABC6DEF0
              #@
    1234ABC890#[12345678901234]ABC[89012]DEF[67890]@1234567890
    123456ABC0#[1]DEF[5]ABC[9012345678]DEF[234567]ABC@1DEF567890
    

    Again, the numbers, that have been changed, surrounded by square brackets, are located, ONLY, between the columns 11 and 40 !

    C) If you would like to perform the two searches, above, simultaneously, just add an alternative, as below :

    (?!.*#)((?-i)ABC.*?DEF|\d+)(?=.*@)

    Remark :

    Note that switching the two parts of the alternative, would, in most cases, completely, change the search and the replacement processes !!


    Finally, once the search/replacement done, we, simply, have to delete the two boundary characters @ and @ with the simple regex, below :

    Find what : [#@]

    Replace with : Leave EMPTY

    Enjoy N++

    Best Regards

    guy038



  • Many thanks for the input @guy038 it is most appreciated.

    Matt


Log in to reply