Select all mispelled words in Sublime Text at once

Solution 1:

You can easily create a custom plugin to do this:

  1. From the Tools menu -> Developer -> New Plugin... (instructions based on Dev Build 3111. For Stable channel 3103, it is just Tools -> New Plugin... )
  2. Replace the contents of the file with the following:
import sublime, sublime_plugin

class SelectAllSpellingErrorsCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        regions = []
        while True:
            self.view.run_command('next_misspelling')
            if self.view.sel()[0] not in regions:
                regions.append(self.view.sel()[0])
            else:
                break
        self.view.sel().clear()
        self.view.sel().add_all(regions)
  1. Save it in the default directory (which will be your Packages/User folder) as something like spelling.py
  2. Create a custom keybinding to run command select_all_spelling_errors

Solution 2:

I used the algorithm to perform it on a file within 1.500.000 lines/words within 81.000 misspelled words. This was the profile result:

         1.555.756 function calls in 9.196,582 seconds ~2,5 hours

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.077    0.077 9196.582 9196.582 <string>:1(<module>)
        1    6.087    6.087 9196.505 9196.505 select_all_spelling_errors.py:23(findRegions)
   245644    1.042    0.000    1.042    0.000 sublime.py:550(__init__)
   163763    2.559    0.000    2.559    0.000 sublime.py:557(__str__)
   245644    1.357    0.000   15.908    0.000 sublime.py:638(__getitem__)
        1    0.000    0.000    0.000    0.000 sublime.py:659(clear)
    81881    0.611    0.000   56.255    0.001 sublime.py:662(add)
        1    0.385    0.385   56.640   56.640 sublime.py:668(add_all)
    81882    0.884    0.000 9114.968    0.111 sublime.py:829(run_command)
   245646    0.344    0.000    0.344    0.000 sublime.py:832(sel)
        1    0.001    0.001 9196.582 9196.582 {built-in method exec}
    81881    0.071    0.000    0.071    0.000 {built-in method isinstance}
    81882 9114.084    0.111 9114.084    0.111 {built-in method view_run_command}
    81881   55.573    0.001   55.573    0.001 {built-in method view_selection_add_region}
        1    0.000    0.000    0.000    0.000 {built-in method view_selection_clear}
   245644   13.509    0.000   14.551    0.000 {built-in method view_selection_get}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
        1    0.000    0.000    0.000    0.000 {method 'values' of 'dict' objects}

There we may see the culprit which eat almost all the time:

81882 9114.084    0.111 9114.084    0.111 {built-in method view_run_command}

This was the source code used:

import sublime
import sublime_plugin

import cProfile


class SelectAllSpellingErrorsCommand(sublime_plugin.TextCommand):

    def run(self, edit):

        cProfile.runctx( 'findRegions(self, edit)', globals(), locals() )

def findRegions(self, edit):

    regionsList = []

    while True:

        self.view.run_command('next_misspelling')

        if self.view.sel()[0] not in regionsList:

            regionsList.append( self.view.sel()[0] )

        else:

            break

    self.view.sel().clear()
    self.view.sel().add_all( regionsList )