<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically?]]></title><description><![CDATA[<p dir="auto">Greetings! I mainly use Notepad++ to make my writing faster through autocompletion. I recently noticed that the results of the autocomplete are sorted alphabetically and I would prefer them to be sorted based on the frequency of repetition because it makes more sense when writing. Are there any plugins or fixes for this?<br />
Thank you!!</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/24518/how-can-i-get-autocomplete-to-be-sorted-by-frequency-of-repetition-instead-of-alphabetically</link><generator>RSS for Node</generator><lastBuildDate>Wed, 17 Jun 2026 13:40:27 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/24518.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 02 Jun 2023 13:24:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically? on Fri, 09 Jun 2023 21:54:57 GMT]]></title><description><![CDATA[<p dir="auto">Disregard the version I posted in my previous post. It is bugged and does not work.</p>
<p dir="auto">This version contains a proper working implementation of a feature in which the current word is boosted to the top if it previously occurred and is otherwise not shown.</p>
<pre><code>from Npp import *

# BEGIN SETTINGS
AUTOCOMPLETION_MIN_LEN = 2 # min length of word to trigger autocompletion
CHARS_TO_MATCH = r'[\w_-]' # characters that can be in "words" (by default most letters, digits, underscores, and dashes)
USE_LANGUAGE_IGNORECASE = True # use the document's lexer language setting for ignoring case
DEFAULT_IGNORECASE = False # should case be ignored if not using language ignorecase?
ENABLED_EXTENSIONS = {
    '', # files with no extension yet
    'csv',
    'txt',
    'md',
    'xml',
    'json',
    'tsv',
    'log',
    'dump',
    'yaml',
    'yml',
} # only use for files with these extensions
MAX_FILE_SIZE = 200_000 # do not try autocompleting for files with more bytes than this
CURRENT_WORD_ONLY_IF_IN_TEXT = True
# END_SETTINGS

def on_match(m, ctr, ignorecase):
    '''increase the count of the current word by 1
    if ignorecase, store only the uppercase version of each word'''
    word = m.group(0)
    if ignorecase:
        word = word.upper()
    ctr.setdefault(word, 0)
    ctr[word] += 1

def getWordRangeUnderCaret():
    '''get the start and end of the word under the caret'''
    pos            = editor.getCurrentPos()
    word_start_pos = editor.wordStartPosition(pos, True)
    word_end_pos   = editor.wordEndPosition(pos, True)
    return word_start_pos, word_end_pos
    
def getExtension(fname):
    for ii in range(len(fname) - 1, -1, -1):
        if fname[ii] == '.':
            break
    if ii == 0:
        return ''
    return fname[ii + 1:]

def onCharInsert(notif):
    '''Find all words in the document prefixed by the word under the caret
        and show those words for autocompletion sorted by their frequency.
        Ignore words with length less than AUTOCOMPLETION_MIN_LEN.
    May ignore the case of words based on the lexer language
        (e.g., will ignore case in SQL but not in Python)'''
    if editor.getLength() &gt; MAX_FILE_SIZE:
        return
    ext = getExtension(notepad.getCurrentFilename())
    if ext not in ENABLED_EXTENSIONS:
        return
    word_start_pos, word_end_pos = getWordRangeUnderCaret()
    word_length    = word_end_pos - word_start_pos
    word = editor.getRangePointer(word_start_pos, word_length).strip()
    if word_length &lt; AUTOCOMPLETION_MIN_LEN:
        return
    ctr = {}
    # anything preceded by a non-word-char and starting with the current word
    match_pat = '(?&lt;!{0}){1}({0}*)'.format(CHARS_TO_MATCH, word)
    ignorecase = DEFAULT_IGNORECASE
    if USE_LANGUAGE_IGNORECASE:
        ignorecase = editor.autoCGetIgnoreCase()
    else:
        editor.autoCSetIgnoreCase(ignorecase)
    if ignorecase:
        # match case-insenstively if that's the language default
        match_pat = '(?i)' + match_pat
    editor.research(match_pat, lambda m: on_match(m, ctr, ignorecase))
    if CURRENT_WORD_ONLY_IF_IN_TEXT:
        if ignorecase:
            upword = word.upper()
            if upword in ctr:
                if ctr[upword] &gt; 1: # word earlier in text, move to front
                    ctr[upword] = 10_000_000_000
                else:
                    del ctr[upword] # word not in text, remove
        elif word in ctr:
            if ctr[word] &gt; 1:
                ctr[word] = 10_000_000_000
            else:
                del ctr[word]
    autocomp = sorted(ctr, key = lambda x: ctr[x], reverse=True)
    autocomp_str = ' '.join(autocomp)
    editor.autoCShow(word_length, autocomp_str)


if __name__ == '__main__':
    try:
        CALLBACK_ADDED
    except NameError:
        CALLBACK_ADDED = 1
        editor.callback(onCharInsert, [SCINTILLANOTIFICATION.CHARADDED])
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/86957</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86957</guid><dc:creator><![CDATA[Mark Olson]]></dc:creator><pubDate>Fri, 09 Jun 2023 21:54:57 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically? on Fri, 09 Jun 2023 16:36:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-olson" aria-label="Profile: Mark-Olson">@<bdi>Mark-Olson</bdi></a> This is brilliant! Thank you Mark, I truly appreciate your effort &lt;3</p>
]]></description><link>https://community.notepad-plus-plus.org/post/86940</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86940</guid><dc:creator><![CDATA[asadMarmash]]></dc:creator><pubDate>Fri, 09 Jun 2023 16:36:44 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically? on Fri, 09 Jun 2023 14:24:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/asadmarmash" aria-label="Profile: asadMarmash">@<bdi>asadMarmash</bdi></a> said in <a href="/post/86931">How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically?</a>:</p>
<blockquote>
<p dir="auto">But I have a question, how can I get it to suggest me the word I am currently writing at the top of the suggestions only if it is present in the text.<br />
So for example if I have a file than contains this:</p>
</blockquote>
<p dir="auto">New setting.<br />
With setting on and word present in text:<br />
<img src="/assets/uploads/files/1686320391849-27d84825-b79c-4f61-8370-65f7de0166a1-image.png" alt="27d84825-b79c-4f61-8370-65f7de0166a1-image.png" class=" img-fluid img-markdown" /><br />
With setting on and word absent in preceding text:<br />
<img src="/assets/uploads/files/1686320576099-9a3f4c7b-68ef-40b7-9d6b-66a6d582cc57-image.png" alt="9a3f4c7b-68ef-40b7-9d6b-66a6d582cc57-image.png" class=" img-fluid img-markdown" /><br />
So if the setting is on, the current word is absent from the autocompletion if the current word is its only occurrence, and it shows up first if the current word is present in the preceding text.</p>
<pre><code>from Npp import *

# BEGIN SETTINGS
AUTOCOMPLETION_MIN_LEN = 2 # min length of word to trigger autocompletion
CHARS_TO_MATCH = r'[\w_-]' # characters that can be in "words" (by default most letters, digits, underscores, and dashes)
USE_LANGUAGE_IGNORECASE = True # use the document's lexer language setting for ignoring case
DEFAULT_IGNORECASE = False # should case be ignored if not using language ignorecase?
ENABLED_EXTENSIONS = {
    '', # files with no extension yet
    'csv',
    'txt',
    'md',
    'xml',
    'json',
    'tsv',
    'log',
    'dump',
    'yaml',
    'yml',
} # only use for files with these extensions
MAX_FILE_SIZE = 200_000 # do not try autocompleting for files with more bytes than this
CURRENT_WORD_ONLY_IF_IN_TEXT = True
# END_SETTINGS

def on_match(m, ctr, ignorecase):
    '''increase the count of the current word by 1
    if ignorecase, store only the uppercase version of each word'''
    word = m.group(0)
    if ignorecase:
        word = word.upper()
    ctr.setdefault(word, 0)
    ctr[word] += 1

def getWordRangeUnderCaret():
    '''get the start and end of the word under the caret'''
    pos            = editor.getCurrentPos()
    word_start_pos = editor.wordStartPosition(pos, True)
    word_end_pos   = editor.wordEndPosition(pos, True)
    return word_start_pos, word_end_pos
    
def getExtension(fname):
    for ii in range(len(fname) - 1, -1, -1):
        if fname[ii] == '.':
            break
    if ii == 0:
        return ''
    return fname[ii + 1:]

def onCharInsert(notif):
    '''Find all words in the document prefixed by the word under the caret
        and show those words for autocompletion sorted by their frequency.
        Ignore words with length less than AUTOCOMPLETION_MIN_LEN.
    May ignore the case of words based on the lexer language
        (e.g., will ignore case in SQL but not in Python)'''
    if editor.getLength() &gt; MAX_FILE_SIZE:
        return
    ext = getExtension(notepad.getCurrentFilename())
    if ext not in ENABLED_EXTENSIONS:
        return
    word_start_pos, word_end_pos = getWordRangeUnderCaret()
    word_length    = word_end_pos - word_start_pos
    word = editor.getRangePointer(word_start_pos, word_length).strip()
    if word_length &lt; AUTOCOMPLETION_MIN_LEN:
        return
    ctr = {}
    # anything preceded by a non-word-char and starting with the current word
    match_pat = '(?&lt;!{0}){1}({0}*)'.format(CHARS_TO_MATCH, word)
    ignorecase = DEFAULT_IGNORECASE
    if USE_LANGUAGE_IGNORECASE:
        ignorecase = editor.autoCGetIgnoreCase()
    else:
        editor.autoCSetIgnoreCase(ignorecase)
    if ignorecase:
        # match case-insenstively if that's the language default
        match_pat = '(?i)' + match_pat
    editor.research(match_pat, lambda m: on_match(m, ctr, ignorecase))
    word_was_in_text = False
    if ignorecase:
        word_was_in_text = ctr[word.upper()] &gt; 1
    else:
        word_was_in_text = ctr[word] &gt; 1
    if CURRENT_WORD_ONLY_IF_IN_TEXT:
        del ctr[word]
    autocomp = sorted(ctr, key = lambda x: ctr[x], reverse=True)
    if CURRENT_WORD_ONLY_IF_IN_TEXT and word_was_in_text:
        if ignorecase:
            autocomp.insert(0, word.upper())
        else:
            autocomp.insert(0, word)
    autocomp_str = ' '.join(autocomp)
    editor.autoCShow(word_length, autocomp_str)


if __name__ == '__main__':
    try:
        CALLBACK_ADDED
    except NameError:
        CALLBACK_ADDED = 1
        editor.callback(onCharInsert, [SCINTILLANOTIFICATION.CHARADDED])
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/86936</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86936</guid><dc:creator><![CDATA[Mark Olson]]></dc:creator><pubDate>Fri, 09 Jun 2023 14:24:12 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically? on Fri, 09 Jun 2023 13:03:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/asadmarmash" aria-label="Profile: asadMarmash">@<bdi>asadMarmash</bdi></a> said in <a href="/post/86931">How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically?</a>:</p>
<blockquote>
<p dir="auto">and not truely a “autocomplete”.</p>
</blockquote>
<p dir="auto">Exactly.  It’s not an autocomplete.  If you want to exit out of the auto-complete interface and just accept the word as-is, hit the ESC key.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/86933</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86933</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Fri, 09 Jun 2023 13:03:15 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically? on Fri, 09 Jun 2023 12:38:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-olson" aria-label="Profile: Mark-Olson">@<bdi>Mark-Olson</bdi></a> I honestly didn’t expect someone to write me a plugin, so thanks a lot dude!</p>
<p dir="auto">But I have a question, how can I get it to suggest me the word I am currently writing at the top of the suggestions only if it is present in the text.<br />
So for example if I have a file than contains this:</p>
<pre><code>abc
abc
abcd
</code></pre>
<p dir="auto">Writing “abc” will only suggest “abcd”. While the native autocomplete returns both “abc” and “abcd”. I think it would be appropriate to return “abc” first regardless of the frequency of repetition, this is because it was found in the text, and not truely a “autocomplete”.<br />
I tried coding this myself and failed :(</p>
]]></description><link>https://community.notepad-plus-plus.org/post/86931</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86931</guid><dc:creator><![CDATA[asadMarmash]]></dc:creator><pubDate>Fri, 09 Jun 2023 12:38:47 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically? on Sat, 03 Jun 2023 04:14:07 GMT]]></title><description><![CDATA[<p dir="auto">OK, (probably) final update to my little script.<br />
Since programmers don’t want their default autocompletions to be overriden for programming languages, and I’m concerned about it being a bit too CPU-hungry for very large files, I’ve added two new settings so that it doesn’t work on very big files and it only autocompletes for files with extensions from a predetermined list.</p>
<p dir="auto">I’ve tried this version out on a decently large (90 kb) JSON file I got from an API, and I was pretty pleased with the results.</p>
<pre><code>from Npp import *

# BEGIN SETTINGS
AUTOCOMPLETION_MIN_LEN = 2 # min length of word to trigger autocompletion
CHARS_TO_MATCH = r'[\w_-]' # characters that can be in "words" (by default most letters, digits, underscores, and dashes)
USE_LANGUAGE_IGNORECASE = True # use the document's lexer language setting for ignoring case
ENABLED_EXTENSIONS = {
    '', # files with no extension yet
    'csv',
    'txt',
    'md',
    'xml',
    'json',
    'tsv',
    'log',
    'dump',
    'yaml',
    'yml',
} # only use for files with these extensions
MAX_FILE_SIZE = 200_000 # do not try autocompleting for files with more bytes than this
# END_SETTINGS

def on_match(m, ctr, ignorecase):
    '''increase the count of the current word by 1
    if ignorecase, store only the uppercase version of each word'''
    word = m.group(0)
    if ignorecase:
        word = word.upper()
    ctr.setdefault(word, 0)
    ctr[word] += 1

def getWordRangeUnderCaret():
    '''get the start and end of the word under the caret'''
    pos            = editor.getCurrentPos()
    word_start_pos = editor.wordStartPosition(pos, True)
    word_end_pos   = editor.wordEndPosition(pos, True)
    return word_start_pos, word_end_pos
    
def getExtension(fname):
    for ii in range(len(fname) - 1, -1, -1):
        if fname[ii] == '.':
            break
    if ii == 0:
        return ''
    return fname[ii + 1:]

def onCharInsert(notif):
    '''Find all words in the document prefixed by the word under the caret
        and show those words for autocompletion sorted by their frequency.
        Ignore words with length less than AUTOCOMPLETION_MIN_LEN.
    May ignore the case of words based on the lexer language
        (e.g., will ignore case in SQL but not in Python)'''
    if editor.getLength() &gt; MAX_FILE_SIZE:
        return
    ext = getExtension(notepad.getCurrentFilename())
    if ext not in ENABLED_EXTENSIONS:
        return
    word_start_pos, word_end_pos = getWordRangeUnderCaret()
    word_length    = word_end_pos - word_start_pos
    word = editor.getRangePointer(word_start_pos, word_length).strip()
    if word_length &lt; AUTOCOMPLETION_MIN_LEN:
        return
    ctr = {}
    # anything preceded by a non-word-char and starting with the current word
    match_pat = '(?&lt;!{0}){1}({0}+)'.format(CHARS_TO_MATCH, word)
    ignorecase = USE_LANGUAGE_IGNORECASE and editor.autoCGetIgnoreCase()
    if ignorecase:
        # match case-insenstively if that's the language default
        match_pat = '(?i)' + match_pat
    editor.research(match_pat, lambda m: on_match(m, ctr, ignorecase))
    autocomp = sorted(ctr, key = lambda x: ctr[x], reverse=True)
    autocomp_str = ' '.join(autocomp)
    editor.autoCShow(word_length, autocomp_str)


if __name__ == '__main__':
    try:
        CALLBACK_ADDED
    except NameError:
        CALLBACK_ADDED = 1
        editor.callback(onCharInsert, [SCINTILLANOTIFICATION.CHARADDED])
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/86770</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86770</guid><dc:creator><![CDATA[Mark Olson]]></dc:creator><pubDate>Sat, 03 Jun 2023 04:14:07 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically? on Fri, 02 Jun 2023 22:59:48 GMT]]></title><description><![CDATA[<p dir="auto">One thing I should note about my scripts that I don’t think anyone has mentioned: <strong>there is no way to intercept Scintilla’s default autocompletion list (which includes language keywords) between when it is generated and when it is shown to the user.</strong> Thus, my script overrides the default autocompletions and I have no (easy) way to avoid this.</p>
<p dir="auto">The upshot of this would seem to be (if I read the <a href="https://www.scintilla.org/ScintillaDoc.html#SCI_AUTOCGETIGNORECASE" rel="nofollow ugc">relevant docs</a> correctly) that this is more of a job for the Scintilla devs than the Notepad++ devs.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/86766</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86766</guid><dc:creator><![CDATA[Mark Olson]]></dc:creator><pubDate>Fri, 02 Jun 2023 22:59:48 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically? on Fri, 02 Jun 2023 22:53:06 GMT]]></title><description><![CDATA[<p dir="auto">This new version now may ignore case for autocompletions depending on the lexer language setting (e.g., will ignore case for SQL but not Python)</p>
<p dir="auto"><em>I would not particularly recommend this version</em> because it <em>may</em> ignore case in some situations where I think it’s rather inappropriate (e.g., text documents) and because of how the algorithm works, the autocompletions it produces are always in all caps. The version in my previous post may be more intuitive and useful.</p>
<pre><code>from Npp import *

# BEGIN SETTINGS
AUTOCOMPLETION_MIN_LEN = 2 # min length of word to trigger autocompletion
CHARS_TO_MATCH = r'[\w_-]' # characters that can be in "words" (by default most letters, digits, underscores, and dashes)
USE_LANGUAGE_IGNORECASE = True # use the document's lexer language setting for ignoring case
# END_SETTINGS

def on_match(m, ctr, ignorecase):
    '''increase the count of the current word by 1
    if ignorecase, store only the uppercase version of each word'''
    word = m.group(0)
    if ignorecase:
        word = word.upper()
    ctr.setdefault(word, 0)
    ctr[word] += 1

def getWordRangeUnderCaret():
    '''get the start and end of the word under the caret'''
    pos            = editor.getCurrentPos()
    word_start_pos = editor.wordStartPosition(pos, True)
    word_end_pos   = editor.wordEndPosition(pos, True)
    return word_start_pos, word_end_pos

def onCharInsert(notif):
    '''Find all words in the document prefixed by the word under the caret
        and show those words for autocompletion sorted by their frequency.
        Ignore words with length less than AUTOCOMPLETION_MIN_LEN.
    May ignore the case of words based on the lexer language
        (e.g., will ignore case in SQL but not in Python)'''
    word_start_pos, word_end_pos = getWordRangeUnderCaret()
    word_length    = word_end_pos - word_start_pos
    word = editor.getRangePointer(word_start_pos, word_length).strip()
    if word_length &lt; AUTOCOMPLETION_MIN_LEN:
        return
    ctr = {}
    # anything preceded by a non-word-char and starting with the current word
    match_pat = '(?&lt;!{0}){1}({0}+)'.format(CHARS_TO_MATCH, word)
    ignorecase = USE_LANGUAGE_IGNORECASE and editor.autoCGetIgnoreCase()
    if ignorecase:
        # match case-insenstively if that's the language default
        match_pat = '(?i)' + match_pat
    editor.research(match_pat, lambda m: on_match(m, ctr, ignorecase))
    autocomp = sorted(ctr, key = lambda x: ctr[x], reverse=True)
    autocomp_str = ' '.join(autocomp)
    editor.autoCShow(word_length, autocomp_str)


if __name__ == '__main__':
    try:
        CALLBACK_ADDED
    except NameError:
        CALLBACK_ADDED = 1
        editor.callback(onCharInsert, [SCINTILLANOTIFICATION.CHARADDED])
</code></pre>
<p dir="auto"><strong>Edit: added a setting to choose whether to use lexer language to decide whether to ignore case</strong></p>
]]></description><link>https://community.notepad-plus-plus.org/post/86765</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86765</guid><dc:creator><![CDATA[Mark Olson]]></dc:creator><pubDate>Fri, 02 Jun 2023 22:53:06 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically? on Fri, 02 Jun 2023 22:11:02 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a><br />
Here’s a simple way to sort autocompletions by frequency.</p>
<p dir="auto">Fair warning: this script engages in some heavy computation <em>every time a char is added</em>, and the amount of computation and memory consumption scales with the size of the file. Since this is Python and not C++, you shouldn’t be surprised if it’s quite a bit slower than normal autocompletion, and it’s probably unusable for files over a kilobytes.</p>
<p dir="auto">There is definitely room for efficiency gains. I wrote this using a very simple, obvious algorithm because I didn’t want to fuss. I can try to implement this more efficiently within my dictionary autocompletion plugin, but it’s a nontrivial task.</p>
<p dir="auto"><img src="/assets/uploads/files/1685743341075-a0829b5d-319e-4cbe-8762-9f501be1f6f8-image.png" alt="a0829b5d-319e-4cbe-8762-9f501be1f6f8-image.png" class=" img-fluid img-markdown" /></p>
<pre><code>from Npp import *

# BEGIN SETTINGS
AUTOCOMPLETION_MIN_LEN = 2 # min length of word to trigger autocompletion
CHARS_TO_MATCH = r'[\w_-]' # characters that can be in "words" (by default most letters, digits, underscores, and dashes)
# END_SETTINGS

def on_match(m, ctr, startswith):
    word = m.group(0)
    if not word.startswith(startswith):
        return
    ctr.setdefault(word, 0)
    ctr[word] += 1

def getWordRangeUnderCaret():
    pos            = editor.getCurrentPos()
    word_start_pos = editor.wordStartPosition(pos, True)
    word_end_pos   = editor.wordEndPosition(pos, True)
    return word_start_pos, word_end_pos

def onCharInsert(notif):
    word_start_pos, word_end_pos = getWordRangeUnderCaret()
    word_length    = word_end_pos - word_start_pos
    word = editor.getRangePointer(word_start_pos, word_length).strip()
    if word_length &lt; AUTOCOMPLETION_MIN_LEN:
        return
    ctr = {}
    editor.research('(%s+)' % CHARS_TO_MATCH,
        lambda m: on_match(m, ctr, word))
    autocomp = sorted(ctr, key = lambda x: ctr[x], reverse=True)
    autocomp_str = ' '.join(autocomp)
    editor.autoCShow(word_length, autocomp_str)


if __name__ == '__main__':
    try:
        CALLBACK_ADDED
    except NameError:
        CALLBACK_ADDED = 1
        editor.callback(onCharInsert, [SCINTILLANOTIFICATION.CHARADDED])
</code></pre>
<p dir="auto"><strong>Edits after initial post:</strong></p>
<ol>
<li>Add setting to customize what are considered word chars</li>
<li>Get rid of f-string syntax in onCharInsert function to make it (hopefully) compatible with the Python2 version of PythonScript.</li>
</ol>
]]></description><link>https://community.notepad-plus-plus.org/post/86764</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86764</guid><dc:creator><![CDATA[Mark Olson]]></dc:creator><pubDate>Fri, 02 Jun 2023 22:11:02 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically? on Fri, 02 Jun 2023 16:52:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/asadmarmash" aria-label="Profile: asadMarmash">@<bdi>asadMarmash</bdi></a> said in <a href="/post/86754">How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically?</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> I have no experience with C++, but <a href="https://github.com/bruderstein/PythonScript" rel="nofollow ugc">I found a way to create a “plugin” using python</a>. I may look into creating one in the near future.</p>
</blockquote>
<p dir="auto">Indeed.</p>
<p dir="auto">For some examples that will give you ideas:</p>
<ul>
<li><a href="https://community.notepad-plus-plus.org/topic/24409/dictionary-autocompletion">this discussion</a>  led to <a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-olson" aria-label="Profile: Mark-Olson">@<bdi>Mark-Olson</bdi></a> creating a script for PythonScript that uses the dictionary from the DSpellCheck plugin for populating the auto-complete (it thus shows how to do a custom auto-complete, which will be helpful to you)</li>
<li>you can search the forum for “frequency” or maybe better “pythonscript frequency”, and may find scripts that help with finding the frequency of words in your document.</li>
</ul>
]]></description><link>https://community.notepad-plus-plus.org/post/86756</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86756</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Fri, 02 Jun 2023 16:52:04 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically? on Fri, 02 Jun 2023 16:29:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> I have no experience with C++, but <a href="https://github.com/bruderstein/PythonScript" rel="nofollow ugc">I found a way to create a “plugin” using python</a>. I may look into creating one in the near future.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/86754</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86754</guid><dc:creator><![CDATA[asadMarmash]]></dc:creator><pubDate>Fri, 02 Jun 2023 16:29:19 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically? on Fri, 02 Jun 2023 14:02:05 GMT]]></title><description><![CDATA[<p dir="auto">Perhaps something could be “scripted” for this desire?</p>
<p dir="auto">I don’t like Notepad++'s auto-completion feature myself, so I don’t use it.  And thus I’m not versed in how it could be scripted, nor would I have interest in writing/using such a script.</p>
<p dir="auto">But it seems like some others have recently produced scripts that manipulate auto-completion, so maybe <em>they</em> would be interested in this opportunity to show off some script-brilliance?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/86744</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86744</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Fri, 02 Jun 2023 14:02:05 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically? on Fri, 02 Jun 2023 13:42:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> The brief list could be a bit more visually appealing, so thanks for the suggestion.<br />
I doubt that the feature would be implemented since Notepad++ is primarily a code editor and not a “text” editor.<br />
Do you know any text editor that has this feature? I though I would experiment with Vim or Emacs, but the learning curve is quite steep.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/86742</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86742</guid><dc:creator><![CDATA[asadMarmash]]></dc:creator><pubDate>Fri, 02 Jun 2023 13:42:43 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically? on Fri, 02 Jun 2023 13:39:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/asadmarmash" aria-label="Profile: asadMarmash">@<bdi>asadMarmash</bdi></a> ,</p>
<p dir="auto">There aren’t any plugins (that I know of) that re-order the auto-completion list based on word frequency, sorry.</p>
<p dir="auto">However, v8.5 (and newer) added <a href="https://npp-user-manual.org/docs/preferences/#auto-completion" rel="nofollow ugc">Settings &gt; Preferences &gt; Auto-Completion</a> <strong>&gt; ☑ Make auto-completion list brief</strong>, which will at least trim down the list based on how many characters you’ve typed.  So just  having typed <code>ab</code> will list all words starting with <code>ab</code>, whereas typing an <code>e</code> after the auto-completion list has popped up will limit the list to words starting with <code>abe</code>.  So it might help, even if it doesn’t add frequency-sorting.</p>
<p dir="auto">If you’d like to request that the developers add an option to sort the word-list by frequency, you could follow the <a href="https://community.notepad-plus-plus.org/topic/15741/faq-desk-feature-request-or-bug-report">FAQ about feature requests</a> to put in the request – though my guess is that the developer won’t be interested in that (though I sometimes guess wrong which features will interest him).</p>
]]></description><link>https://community.notepad-plus-plus.org/post/86741</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86741</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Fri, 02 Jun 2023 13:39:36 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete to be sorted by frequency of repetition instead of alphabetically? on Fri, 02 Jun 2023 13:29:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/asadmarmash" aria-label="Profile: asadMarmash">@<bdi>asadMarmash</bdi></a></p>
<p dir="auto">I don’t know of any, but I’m responding to say I think that’s a pretty good idea.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/86740</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/86740</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Fri, 02 Jun 2023 13:29:49 GMT</pubDate></item></channel></rss>