TextFX and word count
-
First of all, I just noticed that the TextFX plugin is gone, as though I removed it, but I didn’t. And it isn’t listed among the available titles in the Plugin Admin. Did I miss something in that last few days?
The two main features I used in TextFX:
- Word count, particularly the ability to report the number of words in selected text
- Line sorting that eliminates duplicates
Are these things available in other plugins?
-
See this FAQ
-
@PeterJones Thanks. I know about the View > Summary for whole-file word counts, but it doesn’t count the words in selected text. If you know how to do that, or know of another plugin that does it, I’d appreciate it.
-
Simple Pythonscript, called
WordCountInSelectedText.py
:# -*- coding: utf-8 -*- from __future__ import print_function from Npp import * import inspect import os #------------------------------------------------------------------------------- class WCIST(object): def __init__(self): self.this_script_name = inspect.getframeinfo(inspect.currentframe()).filename.split(os.sep)[-1].rsplit('.', 1)[0] self.total = 0 def match_found(m): self.total += 1 editor.research(r'\w+', match_found, 0, editor.getSelectionStart(), editor.getSelectionEnd()) self.mb('Words in selected text = {}'.format(self.total)) def mb(self, msg, flags=0, title=''): # a message-box function return notepad.messageBox(msg, title if title else self.this_script_name, flags) #------------------------------------------------------------------------------- if __name__ == '__main__': WCIST()
-
@Alan-Kilborn Thank you! Running such a script is something I’ve never done in NPP. Can you point me to a section of the manual or give me simple instructions?
-
-
@PeterJones @Alan-Kilborn Thank you both
-
Of course, it is arguably even easier to just set up a search and press the Count button in the Find window, like this:
The result is shown in the status bar of the Find window.
This can be macro-recorded for easy running; the downside is that to see the result, the Find window has to be open.
-
There’s also a way to put a selection’s word-count in the status bar; see HERE for that.