Show count of occurrences when smart highlighting

2019-03-23 03:31发布

问题:

Is it possible to show the number of occurrences of words which are smart highlighted? I mean when you double click on a word.

In Matlab e.g. smart highlighting is activated by having the cursor touching a word and in the tool bar it instantly says for instance 4 usages of "weight" found.

Doing a search for the word/phrase will give you the same information, but how about having the count directly be shown somewhere?

BTW: Can smart highlighting be activated in a different manner than double clicking?

回答1:

You can get counts of words or matches in other ways.

The normal Find window has a Count button. If you press it, it will display the total number of items found in the status bar of the find window.

Also the Mark tab of the Find window shows the number of items found when Mark all is pressed. In addition, the items found by this kind of search are highlighted permanently.



回答2:

Found the answer here.

  • Download and install the python script plugin
  • Plugins --> Python script --> New script
  • Name it SelectedTextCountIntoStatusBar.py
  • Paste this, save and quit:

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])

  • Plugins --> Python script --> Scripts --> SelectedTextCountIntoStatusBar
  • Double-click on a word
  • The number of occurrences is in the status bar.


回答3:

As of now, Notepad++ does not show the count for smart highlighting (i.e. highlighting words by double-clicking on one occurrence).

... but how about having the count directly be shown somewhere?

As an alternative:

  • open the Find window (Search > Find...)
  • Navigate to the Mark tab
  • Type the word in the Find What: input area
  • Click Mark All

This will mark all the occurrences as well show the count of matches in the status bar.

BTW: Can smart highlighting be activated in a different manner than double clicking?

There is another alternative for smart highlighting using Style Token which is available from the right-click context menu. Watch the animated tutorial below: