VI & spell
Mitchell Wyle
wyle at inf.ethz.ch
Mon Nov 13 18:45:12 AEST 1989
In article <740 at uc.msc.umn.edu> glex at uf.UUCP (Jeffrey Gleixner) writes:
>It takes the input from vi (:1,$!sp) and redirects it to a file, I run
>[...]
>There has to be a way to do what I want but I haven't been able to figure
>it out, any ideas???????
>Please reply E-Mail to:
>glex at msc.umn.edu
Well, I hope Jeff reads this group... I think that this "spell check from
within vi" topic should be posted to frequently asked questions and answers.
What do you say, Bill? I also think that Brandon should scan these groups
for clever scripts and post them to comp.sources.misc. What about it,
Brandon?
To answer the question, Among all the schemes that I've seen over the
years, I've settled on this one. It checks the spelling of one paragraph at
a time and highlights the mis-spelled words with ### chars.
1) Put this or a similar macro in your .exrc
map ;sp !}spell_check^V^M
2) Put spell_check in an appropriate place (/usr/local/bin or ~/bin
#!/bin/sh
############################################################################
# A sh script to allow spelling checks either in vi or stand alone #
# Usage: spell_check < file or within vi, #
# !}spell_check or #
# :(addressed lines)!spell_check #
# #
# The wrongly spelled words will be surrounded by ###bad-word### #
# WARNING: Do not try and sell this tiny shell script to some #
# poor sucker! #
# Badri Lokanathan, 30 September 1988 #
# #
# New flags added for tput support. If tput is present, then #
# spell_check -H uses highlight mode for use with more. #
# All other flags are passed to spell. #
# Badri Lokanathan, 6 March 1989 #
############################################################################
PATH=/usr/local/bin:/usr/bin:/bin:/usr/ucb:$HOME/bin
doc=/tmp/splchk.$$
scr=/tmp/sedscr.$$
trap 'rm -f $doc $scr; exit 1' 1 2 15
#
# Modify the following line to your wordlist database
# spellflags="-d $HOME/lib/wlist"
#
T1="###"
T2="###"
for flag in $*
do
case $flag in
-H|-Highlight|-highlight)
T1="`tput bold; tput smso`" # Comment out if tput
T2="`tput sgr0; tput rmso`" # is not available
;;
*) spellflags="$spellflags $flag" ;;
esac
done
cat > $doc
############################################################################
# The following is for macho sed hackers only. #
############################################################################
cat > $scr <<HEAD
s/^/ /
s/\$/ /
HEAD
spell $spellflags < $doc | sed -e "\
s/^/s;\\\\([ ][^a-zA-Z0-9]*\\\\)\\\\(/
s/\$/\\\\)\\\\([^a-zA-Z0-9]*[ ]\\\\);\\\\1${T1}\\\\2${T2}\\\\3;g/
s/ \$//" >> $scr
cat >> $scr <<TAIL
s/^ //
s/ \$//
TAIL
#
# Uncomment the following lines if error count is to be limited
#
#count=`wc -l < $scr`
#if [ $count -gt 50 ]
#then
# echo "Too many mistakes for spell_check. Use spell directly."
#else
sed -f $scr $doc
#fi
rm -f $doc $scr
BTW: If you are running on a Sun, why not just have another window open, :w
the file from vi, and spell it from a different window? I don't get it.
More information about the Comp.unix.questions
mailing list