How to word count?

I’ve looked for a way (built in) to perform a word count on a selection but cannot find one. So I looked for a macro and found none. I know I’m not the only one who uses Komodo for writing as well as coding. Can someone point me in the right direction?

I need to select a quantity of text and perform an estimated word count (much like the despised MSWord does).

TIA

Give me a minute and I’ll write you a simple macro.

Create a macro with the following content:

alert(require("ko/editor").getSelection().split(" ").filter(function(w){return w.replace(" ", "").length > 0}).length + " words in the selection");

Save it, create a selection and run it. It will count “a”, “or” and other conjunctions.

Defman: tip - use regex to do your split, so you can account for repeat whitespace:

alert(require("ko/editor").getSelection().split(/\s+/).length + " words in the selection");

Note that does not address whitespace in front or at the end of the selection, its not a reliable way of giving the word count. Better would be something like:

alert(require("ko/editor").getSelection().match(/\w+/g).length)
1 Like