Community
    • Login

    Show count of occurrences of a selected string

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 5.3k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • bob bobB Offline
      bob bob
      last edited by

      Hello,
      I’d like to know the number of occurence of a word
      (When you double click on a word or select a specfic string) updated in real time and shown in the information bar (like sel, Ln, Col,…).
      The ctrl+f + count option allows you to count but it is too many operations.

      Can I design a plugin to achieve this purpose ?

      Thanks !

      Bob

      Scott SumnerS 1 Reply Last reply Reply Quote 0
      • Scott SumnerS Offline
        Scott Sumner @bob bob
        last edited by

        @bob-bob

        You could do a plugin to get this behavior, or you could script it. Here’s an example (may not be fully rounded out) in Pythonscript, I call it SelectedTextCountIntoStatusBar.py; you would run it once per Notepad++ session:

        def callback_sci_UPDATEUI(args):
            if args['updated'] & UPDATE.SELECTION:
                matches = []
                if editor.getTextLength() < 100000:  # don't search "big" files
                    if editor.getSelections() == 1 and not editor.getSelectionEmpty():
                        try:
                            editor.research(r'\Q' + editor.getSelText() + r'\E', lambda m: matches.append(1))
                        except:
                            matches = []
                l = len(matches)
                notepad.setStatusBar(STATUSBARSECTION.DOCTYPE, ' ' if l == 0 else '{} occurrence(s) of selected text'.format(l))
        
        editor.callback(callback_sci_UPDATEUI, [SCINTILLANOTIFICATION.UPDATEUI])
        
        1 Reply Last reply Reply Quote 2

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors