Menu

Copy found lines to clipboard

Grindax
2014-08-02
2015-06-01
  • Grindax

    Grindax - 2014-08-02

    In several jobs I've worked in, I've had the need to copy groups of lines to the clipboard that contain certain words/characters. For example, copying FIX messages that contain a certain tag or value. This is how I've been doing it:

    Using the Find dialog, specify the text I'm searching for, then go to the 'Mark' tab, enable 'Bookmark line', then click 'Mark All', then click the 'Close' button. After that, use the menu option 'Search -> Bookmarks -> Copy Bookmarked Lines'.

    Going through all of these steps many times every day is very time consuming. I propose it would be much better if it were possible to do this:

    Use the Find dialog to specify the text I'm searching for, and then click either 'Find All in Current Document' or 'Find All in All Opened Documents'. Then in the Find result pane at the bottom, simply right click on the header (e.g. on either the '5 hits in 2 files' or the 'filename (3 hits)') and choose to copy those lines to the clipboard.

     
  • Justin Dailey

    Justin Dailey - 2014-08-04

    I can also suggest a slightly easier solution for the time being. Install the LineFilter2 plugin (available through the Plugin Manager). It filters lines that match a keyword or regular expression and creates a new tab with all the lines that matched. You can then copy that text. Not fully automated but still slightly faster.

    You might also be able to accomplish your goal through using something like the Python Script plugin which can probably fully automate searching and saving it to the clipboard, but would require some knowledge of Python.

     
  • THEVENOT Guy

    THEVENOT Guy - 2014-08-04

    Hello Grindax,

    May be, we don't think about the same feature and, although the dail8859's solution, using the Linefilter2 plugin is quite pertinent, it's just simple to obtain, that you would like to, with N++ only !

    For example, with the last 6.6.8 version :

    • Open the 6.6.8 change.log file

    • Open the Search dialog ( CTRL + F )

    • Type, for example, the string fix in the Find what zone

    • Click on the Fin All in Current Document button

    => The Fin Result pane opens and displays the 9 lines, that contain the string "fix"

    • Select some lines or the totality of the Find result window

    • Right click on the selection, in the Find result window

    • Select the Copy sub-menu

    • Hit the F7 key, to get, again, the focus on the main editor window

    • Open a new tab ( CTRL + N )

    • Paste your selection in this new document ( CTRL + V )

    ( To that purpose, see, below, the attached picture Grindax.png )

    An other possibility :

    • Select some text, in the Find result window

    • Drag and drop this text from the Find result window to the main editor window

    So, in all cases, nothing that would be complicated :-)

    Cheers,

    guy038

     

    Last edit: THEVENOT Guy 2014-08-04
  • Grindax

    Grindax - 2014-08-05

    Thanks THEVENOT, however I don't think you've understood what I'm looking for. I don't want to copy the 'Line 8' or 'Line 13' text, or any of the other whitespace and other stuff in the search results pane. Just the contents of the actual lines that match. And with the flexibility to copy to clipboard the results from a single file or all files, depending on which heading I right click on.

    My example use case was for FIX (Financial Information eXchange) messages, where I'd want to paste the results into a FIX parser, and it's important that just the pure contents go into the parser, not lots of other surrounding stuff.

     
  • Al Le

    Al Le - 2014-08-05

    Then I'd suggest to use the Python Script plugin. Using it, you can implement any logig you wish. And it's not complicated at all. Putting every single use case into NP++ core would make it too big.

     
  • THEVENOT Guy

    THEVENOT Guy - 2014-08-05

    Hi Grindax,

    OK, as I guessed, my solution was, obviously, too simple !

    If I understand you fully, I suppose that, regarding the example of my previous post, You would like that the stuff "Line ### : ", in the result pane, was always deleted, for all the lines, wouldn't you ?

    If so, a first and simple approach would be to use a search/replacement, in regular expression mode.

    Then, once you get back all the lines, that contain your matched expression, in a new tab :

    • Open the search/replacement dialog ( CTRL + H )

    • Type the expression .*?: in the Find what : field ( There is a space, AFTER the colon)

    • Leave the Replace with : field empty

    • Check the Wrap around and the Regular expresion square boxes

    • Click on the Replace All button

    Et voilà :-)

    But, preferably, and, as dail8859 suggested in his post, it would be worth to install the python plugin, that is very well integrated to Notepad++ !

    Then, you'll just have to write a simple script that, in one go, would, automatically, search and extract only the contents of the lines, containing your matched expression, from the current edited file or from all the opened files.

    Although installed in my configuration, I haven't begin to study this powerful plugin, yet :-((, I know : I need to do it, very soon ! So, for the moment, I can't help you, on that matter !

    But, I suppose that Dave Brotherstone ( The author of this plugin ), Loreia2 ( a definitive Python's fan ! ) or other guys will be able to give you some hints or, even better, give you a complete and "ready to use" python script !

    Best regards,

    guy038

    P.S. :

    In my previous post, when I decided to search for the example string "fix", in the change.log file, I didn't even notice that you also spoke about the same string FIX ( as "Financial Information eXchange" ) !

    Quite funny, isn't it !?

     

    Last edit: THEVENOT Guy 2014-08-05
  • Loreia2

    Loreia2 - 2014-08-07

    Hi guys,

    this looks like a good candidate for a small python script. Dave wrote an excellent documentation, that you can find here: http://npppythonscript.sourceforge.net/

    Essentially this what you need to do:

    1. create two scripts, and assign different shortcuts to them, one is for search in active file, the other will search in all opened tabs, the only difference is that the second one loops through notepad.getFiles()
    2. collect user input with notepad.prompt method, input can be in regex format
    3. this is an example of search that you need to perform:
    import re
    m = re.findall("ab", "ab cd ab")
    result = "\n".join(m)
    editor.copyText(result)
    

    I've put each result to its own line, you might decide to join with another string.
    Obviously, "ab" string is user input, and "ab cd ab" string is buffer text that you get with editor.getText()

    Regards,
    Loreia

     

    Last edit: Loreia2 2014-08-07
  • Grindax

    Grindax - 2014-08-07

    Thanks all, I'll take a look at the Python option in the meantime. I do still think it would make a lot of sense to have this as native functionality build in to Notepad++ though, for several reasons:

    1. The current behavior of the Find Result pane, which allows copying all, is less useful than being able to copy the actual contents that were found, for the purpose of pasting elsewhere. There are several use cases where just the matching lines themselves are needed, but I can't really think of many cases where one would instead want all the surrounding text (line numbers, headings of searches, etc) to go on the clipboard as well.

    2. The Find Result pane is useful because it gives a graphical display of the matched lines, allowing you to see right away whether the matched lines are what you need to paste elsewhere. Therefore it makes sense to be able to copy the matched lines right from this interface.

    3. Various other text editors, e.g. EditPad, do already have built-in functionality that allows copying matched lines to the clipboard (similar to what the proposed Python script would do), but what they're missing is the Find Result pane to see beforehand what you're going to copy. Since Notepad++ does have this way to graphically display the search results, it would be able to one-up those other text editors in this area.

    Simply having the context menu in the Find Result pane allow copying of just the contents would make a lot of sense because it wouldn't take up any extra space in the UI, it would provide a much more useful function, and it would combine this function with the convenience already afforded by the graphical display of results in this pane.

     
  • Grindax

    Grindax - 2014-09-08

    Hi Don, do you have any thoughts on this?

     
  • Grindax

    Grindax - 2014-12-22

    bump

     
  • Grindax

    Grindax - 2015-03-11

    bump. Please, Don, could this be implemented.

     
  • Grindax

    Grindax - 2015-05-14

    Don, I took the time to explain my suggestion in great detail and to give examples of how it would be useful. I wonder why you won't reply.

     
  • Andreas Jonsson

    Andreas Jonsson - 2015-05-14

    Fixed here: https://github.com/donho/notepad-plus-plus/pull/68

    You have to remember that everyone here is a volunteer. It's possible that Don simply doesn't have time to even read all messages posted.

     
  • Grindax

    Grindax - 2015-05-14

    Wow, that is awesome Andreas, thanks a lot! I hope it gets accepted and merged into the product!

     
  • Grindax

    Grindax - 2015-06-01

    Yay, I'm very glad to see that it just got merged into the main codebase! This will make working with Notepad++ much more convenient.

    Now there is just the matter that after copying content (or doing anything in the Find Result pane), if you want to paste the contents into a new tab you can't just double-click the tab bar and hit Paste because the focus doesn't move correctly to the new tab. See my other post:
    https://sourceforge.net/p/notepad-plus/discussion/331753/thread/6959d093/