Skip to content
David-Apps edited this page May 8, 2024 · 11 revisions

This function lists all the words in the current buffer that do not appear in an external word list. The function puts the list of unknown words in a new buffer in the current session. If there are no such words, the function returns to the original buffer. From the list of unknown words:

  • Use the ^ or up commands to return to the buffer.
  • Use the M command to return to the buffer and move the list of unknown words to another session.

The function uses the external word list /usr/share/dict/words by default. You can use multiple word lists. You can create your own word lists.

Suppose that the buffer includes the words "linux", "Linux", "LINUX", "word", "Word", and "WORD". Suppose that the external word list contains "Linux" and "word" but not "linux", "LINUX", "Word", or "WORD". If you do not pass the function an option argument, the function lists "linux", "LINUX", "Word", and "WORD" but not "Linux" or "word". If you pass the function the -i option argument, the function lists "linux", "LINUX", and "WORD" but not "Linux", "word", or "Word". If you pass the function the -l option argument, the function lists "LINUX", "Word", and "WORD" but not "linux", "Linux", or "word". If you pass the function the -u option argument, the function lists "linux" and "Word" but not "Linux", "LINUX", "word", or "WORD". You can pass the function more than one option argument. If you pass the function the -i, -l, and -u option arguments, the function does not list "linux", "Linux", "LINUX", "word", "Word", or "WORD".

# List the words that are not in a word list.
# usage: <sp [options] [<extra word lists>]
# With option -i, if "word" is in the external list, do not list "Word".
# With option -l, if "Intel" and "AMD" are in the external list, do not list "intel" or "amd".
# With option -u, if "word" and "Intel" are in the external list, do not list "WORD" or "INTEL".
function:sp {
db0
H-
ebvar-
# List the words in the buffer.
etmp
r+1
,s/\s+/\n/gf
,s/^[^[:alnum:]]+//gf
v/^https?:\/\//fs/[^[:alnum:]]+$//gf
g/^$/fd
v/[[:alpha:]]/fd
# Check the external word list for each word.
# To use a different external word list, edit the next line.
W !awk 'BEGIN { for (i = 1; (i < ARGC) && (no_more_options == 0); i++) { if (ARGV[i] ~ /^-[ilu]+$/) { if (ARGV[i] ~ /i/) { initial_capital = 1 } if (ARGV[i] ~ /l/) { lower_case = 1 } if (ARGV[i] ~ /u/) { upper_case = 1 } ARGV[i] = "" } else if (ARGV[i] ~ /^--$/) { no_more_options = 1; ARGV[i] = "" } else { no_more_options = 1 } } } { word_list[$0]++ } END { while ((getline line < "/dev/stdin") > 0) { if (0 == word_list[line]++) { if ((initial_capital != 0) && (line ~ /^[[:upper:]][[:digit:][:punct:][:lower:]]*$/)) { if (0 == (tolower(line) in word_list)) { print line } } else if ((lower_case != 0) && (line ~ /^[[:digit:][:punct:][:lower:]]*$/)) { if ((0 == ((toupper(substr(line, 1, 1)) substr(line, 2)) in word_list)) && (0 == (toupper(line) in word_list))) { print line } } else if ((upper_case != 0) && (line ~ /^[[:digit:][:punct:][:upper:]]*$/)) { if ((0 == (tolower(line) in word_list)) && (0 == ((substr(line, 1, 1) tolower(substr(line, 2))) in word_list))) { print line } } else { print line } } } }' ~0 /usr/share/dict/words
# Delete the next line if you do not want this feedback.
=
1
if(?) {
^
}
}