[comp.editors] spelling from within vi

abed@saturn.wustl.edu (Abed Hammoud) (10/31/90)

	Hello,

	I am sure this is a very frequent question,....sorry.
	Is there a way I can use the unix spelling program ispell
	or spell from within vi. if yes and some body have done it
	please let me know how...

	thanks
	--------------------------------------------------------------
	| Abed  M. Hammoud			abed@saturn.wustl.edu|
	| Washington University.	        office:(314)726-7547 |
	| Electronic Systems & Signals Research Laboratory.          |
	| Dept. of Electrical/Biomedical Engineering.		     |
	| St.Louis Mo U.S.A                                          |
	-------------------------------------------------------------- 

mayoff@cs.utexas.edu (Robert Mayoff) (11/01/90)

In article <1990Oct31.153710.7865@cec1.wustl.edu> abed@saturn.wustl.edu (Abed Hammoud) writes:
>	Is there a way I can use the unix spelling program ispell
>	or spell from within vi. if yes and some body have done it
>	please let me know how...

I use ispell.  Here's the macro I use (straight from my .exrc):

" *c to check the spelling with ispell.
map *c :w^V^M:!ispell %^V^M:e!^V^M^V^M

Note that if you want to type this in to vi, just type it as shown (with a
colon before the "map" command, of course).  If you want it in your .exrc, you
must type control-V before each of the control characters, to actually get the
control-V's in your .exrc file.

This will save the file, run ispell on it (vi expands the % to the current
filename), and then re-edit the file when ispell exits (in case ispell changed
the file because there were errors).

If you want to use the standard spell, you'll have to do more work - spell only
lists words it doesn't know, and doesn't give you the opportunity to change
them.  Here's what you can use:

map *c :w^V^M1GO---End of Spelling List---^V^[:0r !spell %^V^M^V^M

This will save your file, then run spell on it and put the output of spell at
the beginning of your file.  The end of spell's output will be marked by the
line "---End of Spelling List---".

Hope this helps.
-- 
/_  rob		<mayoff@cs.utexas.edu>
 /_ Fun things to do with UNIX (#12 in a series):
  / cd /dev; cat mouse			# Try this on a Sun.  Really!

rouben@math9.math.umbc.edu (Rouben Rostamian) (11/01/90)

In article <1990Oct31.153710.7865@cec1.wustl.edu> abed@saturn.wustl.edu (Abed Hammoud) writes:
>	Is there a way I can use the unix spelling program ispell
>	or spell from within vi.

Here are a couple of lines from my .exrc:

map #S :w^M:$r!spell +${HOME}/lib/word.list % ^M:"... spell ckecking complete^M
map #s :1,$w !spell +${HOME}/lib/word.list ^V| fmt ^M

Both #s and #S commands check the current buffer for spelling mistakes
via unix's spell(1) utility.  The part "+${HOME}/lib/word.list" refers to
the a file containing a private word list which will be consulted in 
addition to the standard dictionary.  Omit that part if you do not have a
personal words file.

The command #s is suitable for spell-checking short files or files which
you know will not have too many spelling mistakes.  The misspelled words
appear at the bottom of the screen and will go away when you hit the 
Return key.

The command #S is suitable for spell-checking longer files or files which
are likely to contain a large number of typos.  It appends a list of 
misspelled words to the end of the current buffer.

Note:  You must enter the ^M and ^V characters in your .exrc file by typing
       CtrlVCtrlM and CtrlVCtrlV, respectively.

--
Rouben Rostamian                            Telephone: (301) 455-2458
Department of Mathematics and Statistics    e-mail:
University of Maryland Baltimore County     bitnet: rostamian@umbc
Baltimore, MD 21228,  U.S.A.                internet: rostamian@umbc3.umbc.edu

rbp@investor.pgh.pa.us (Bob Peirce #305) (11/07/90)

In article <1990Oct31.153710.7865@cec1.wustl.edu> abed@saturn.wustl.edu (Abed Hammoud) writes:
>
>	Is there a way I can use the unix spelling program ispell
>	or spell from within vi. if yes and some body have done it
>	please let me know how...

I usually use :1,.$!spell.  This replaces the buffer with your spelling
errors, but u[ndo] restores the buffer.  You can also say !}spell to do
a paragraph.  I suppose you could get real fancy with macros, but this
is simple and does the job for most of the cases I run into.
-- 
Bob Peirce, Pittsburgh, PA				  412-471-5320
...!uunet!pitt!investor!rbp			rbp@investor.pgh.pa.us

Dan_Jacobson@ATT.COM (11/08/90)

>	Is there a way I can use the unix spelling program ispell
>	or spell from within vi. if yes and some body have done it
>	please let me know how...

Why don't you just "go with the flow", "get with the program", "get
up, get into it, get involved" (--James Brown) and use GNU Emacs' vi
(or vip) mode, and its ispell interface.

"some restrictions apply, offer good after 11/8/1990"
-- 
Dan_Jacobson@ATT.COM  Naperville IL USA  +1 708-979-6364

joseph@hpuplca.HP.COM ( Joseph Hohl ) (11/08/90)

> In article <1990Oct31.153710.7865@cec1.wustl.edu> abed@saturn.wustl.edu (Abed Hammoud) writes:
> >
> >	Is there a way I can use the unix spelling program ispell
> >	or spell from within vi. if yes and some body have done it
> >	please let me know how...
> 
> I usually use :1,.$!spell.  This replaces the buffer with your spelling
> errors, but u[ndo] restores the buffer.  You can also say !}spell to do
> a paragraph.  I suppose you could get real fancy with macros, but this
> is simple and does the job for most of the cases I run into.
> -- 
> Bob Peirce, Pittsburgh, PA				  412-471-5320
> ...!uunet!pitt!investor!rbp			rbp@investor.pgh.pa.us
> ----------

I use the following entry in my .exrc to use ispell:

	map S :w!^M:!ispell %^M:e!^^M^M           ! The ^Ms are Cntl-Ms

This will save your file, run ispell on it and read the corrected file
back into your buffer with a S from command mode in vi.

Joseph

mayoff@cs.utexas.edu (Robert Mayoff) (11/09/90)

>Why don't you just "go with the flow", "get with the program", "get
>up, get into it, get involved" (--James Brown) and use GNU Emacs' vi
>(or vip) mode, and its ispell interface.

Argh.  I've been reading this newsgroup for quite a while now, and have
been pleasantly surprised that no one has made a comment like this -
until now.

It really, *really* offends me when people say stuff like this.  I get
loads of this stuff around here: people nag me about how vi is
inferior, why don't I use emacs, etc.

Well, I *know* vi is "inferior" in many ways - it's not programmable,
it doesn't have online help, and it doesn't support lines of greater
than 1024 characters, to name three ways.  Does any of that bother me?
Well, I'd like to use a more programmable editor, but I hate lisp, so
emacs is out on that count.  I don't usually need online help myself,
but others do, so yes, emacs wins there.  Lines greater than 1024
characters?  Files like that are usually binary in nature, in which
case I use od, edit the dump, and use a little utility I wrote to turn
the dump back into a file; emacs is out there.

Anyway, I've used vi-mode and vip-mode in emacs.  Forget vi-mode;
hitting escapes puts you back into pure emacs.  vip-mode is only
slightly better.  The problem is that vi isn't just an editor, it's an
editing philosophy.  emacs is not just an editor, either; in fact, it's
not just an editing philosophy; it's a kitchen sink.  If I want to run
towers of hanoi, I'll write it (I did, once, in BASIC, no less, with
animation).  However, I don't often want to run towers.  If I want to
use eliza, I'll type it in from More Basic Games (or whatever the title
is, that one from Creative Computing, ya know?).  I never really want
to use eliza, either, though.  As for the ispell interface, doesn't
ispell already have an interface?  (Yes.)  Why not use it?  Same with
mail, mh, news, etc.  Sure, emacs has interfaces for all those, but I'd
rather type "mail" than escape-meta-alt-ctrl-shift-m (or whatever, you
get the idea) if I want to read mail.  I don't feel a need for any of
that stuff in my text editor.  What I want in my text editor is a
command set that's fast to type, and editor functions that execute
quickly.  vi wins big in both of these - having to use control keys
simply to move around on the screen (possibly the most common operation
in a text editor, aside from entering text) is a loss in my book.  And
since vi was original written for use on 300 baud terminals (or was it
110?), you can be pretty sure that the output functions are darn near
optimal.  I know I'm going to get bitten with a comment about how old
vi is because of this, though.

Anyway, emacs isn't a religion (I hope).  Neither is vi.  Please,
*please*, don't try to win "converts" on this newsgroup.  People who
read this are either hoping to get an answer to a (usually) simple
question, or are discussing various features of editors; neither group,
I think, wants to be "preached" to (I know I don't) about which is the
better editor.  Rational arguments should be the rule.  People who become
dissatisfied with vi will switch to emacs when they wish to, and not because
someone said they aren't "with it"; the rest of us don't want to hear it.

Flame-retardation suit donned.

BTW, here's my macro for using ispell from within vi:

" *c to check the spelling with ispell.
map *c :w^V^M:!ispell %^V^M:e!^V^M^V^M
-- 
/_  rob		<mayoff@cs.utexas.edu>
 /_ Fun things to do with UNIX (#12 in a series):
  / cd /dev; cat mouse			# Try this on a Sun.  Really!

rock@warp.Eng.Sun.COM (Bill Petro) (11/09/90)

Dan_Jacobson@ATT.COM writes:

>>	Is there a way I can use the unix spelling program ispell
>>	or spell from within vi. if yes and some body have done it
>>	please let me know how...

>Why don't you just "go with the flow", "get with the program", "get
>up, get into it, get involved" (--James Brown) and use GNU Emacs' vi
>(or vip) mode, and its ispell interface.

I have just started playing with the vip-mode in emacs and  would be interested
in any suggestions on how to use the ispell interface.

In the meantime, here is what I so in vi.  It is a little faster than
the other suggestions:

map @x :!ispell -x %^M^M:e!^M	

Here are other macro mappings that will allow you to spell smaller parts
of your buffer:

"	ISPELL MACROS
"	CURRENT WORD
map x lbi
"       FROM DOT TO END OF FILE
map @X :.,$w!/tmp/ispell.buf|t.|.,$d|!ispell -x #
:r#
"       FROM MARK (M) TO DOT
map  :'m,.w!/tmp/ispell.buf|t.|'m,-d|!ispell -x #
:r#
"       CURRENT PARAGRAPH
map  {ma}mb:'a,'bw!/tmp/ispell.buf|t.|'a,'bd|!ispell -x #
:r#
--
     Bill Petro  {decwrl,hplabs,ucbvax}!sun!Eng!rock
"UNIX for the sake of the kingdom of heaven"  Matthew 19:12

rob@b15.INGR.COM (Rob Lemley) (11/11/90)

>> In article <1990Oct31.153710.7865@cec1.wustl.edu> abed@saturn.wustl.edu (Abed Hammoud) writes:
>> >
>> >	Is there a way I can use the unix spelling program ispell
>> >	or spell from within vi. if yes and some body have done it
>> >	please let me know how...
>> 
>> I usually use :1,.$!spell.  This replaces the buffer with your spelling
>> errors, but u[ndo] restores the buffer.  You can also say !}spell to do
>> a paragraph.  I suppose you could get real fancy with macros, but this
>> is simple and does the job for most of the cases I run into.
>> -- 
>> Bob Peirce, Pittsburgh, PA				  412-471-5320
>> ...!uunet!pitt!investor!rbp			rbp@investor.pgh.pa.us
>> ----------

I like the following macros because they don't do any writing out of the 
file you are currently editing.

A very simple macro to do this is (where ^M is entered in vi as
control-V followed by control-M, this enters a literal carriage-return
in the macro):

	map K :%w !spell^M

To add your own list of spelling words to this (System V, R3):

	map K :%w !spell +$HOME/.spell^M

To save the spell output at your current postion in the buffer:

	map K :%w !spell>/usr/tmp/$LOGNAME.spell

You can put these macros in your .exrc file.

Rob
--
Rob Lemley
System Consultant, Scanning Software, Intergraph, Huntsville, AL
rcl@b15.ingr.com		OR		...!uunet!ingr!b15!rob
205-730-1546

steveha@microsoft.UUCP (Steve Hastings) (11/13/90)

In article <1990Nov7.005405.461@investor.pgh.pa.us> rbp@investor.pgh.pa.us (Bob Peirce #305) writes:
>I usually use :1,.$!spell.  This replaces the buffer with your spelling
>errors, but u[ndo] restores the buffer.

Simpler still:

:w !spell

This pipes the whole file through spell, then waits for you to hit a key
before showing you the file again.  No danger of losing your data, and less
to type.

I have the following lines in my .exrc file:

map - :w !spell^M
map = :w !diction^M


So when I hit the - key I get a spell check, and when I hit the = key I get
a grammar check (very rudimentary).  Sometimes I have thought about
modifying these to pipe through more, but usually I get less than a
screenful of complaints and the speed overhead isn't worth it.
-- 
Steve "I don't speak for Microsoft" Hastings    ===^=== :::::
uunet!microsoft!steveha  steveha@microsoft.uucp    ` \\==|

rob@b15.INGR.COM (Rob Lemley) (11/13/90)

In <1780@b15.INGR.COM> I wrote:

>To save the spell output at your current postion in the buffer:

>	map K :%w !spell>/usr/tmp/$LOGNAME.spell
:r /usr/tmp/$LOGNAME.spell



Sorry, I forgot to remove the literal <control-M>s (carriage-returns).
It should have read (where ^M is a literal carriage-return, entered as
<control-V><control-M>):

     map K :%w !spell>/usr/tmp/$LOGNAME.spell^M:r /usr/tmp/$LOGNAME.spell^M

Rob
--
Rob Lemley
System Consultant, Scanning Software, Intergraph, Huntsville, AL
rcl@b15.ingr.com		OR		...!uunet!ingr!b15!rob
205-730-1546

kal@cs.brown.edu (Keith Lewis (x1136)) (11/14/90)

This is what I use for spell checking in vi:

map \sp :!/u/kal/bin/texsp % > %.sp^V^M:e %.sp^V^M^V^M
map \/ 0i/^V^[$a/^V^["wdd:w^V^M:e#^V^M@w
map \\ :w^V^M:e#^V^M

You should replace /u/kal/bin/texsp by whatever spell program you use.
From command mode in vi, `\sp' will create a file containing the output
of the spell program with the same name as the original extended by .sp
and switch you over to it. Put your cursor on the line containing a
word you wish to correct and type `\/' from command mode. This will
swap you back into the original file with the cursor underneath the
first letter of the misspelled word. Type `\\' to switch back to the
.sp file. Don't forget to remove the .sp file when you are done.
(`map \$ :!rm -f %.sp^V^M' maybe?)

                                The ASCII Kid

richard@mqcomp.mqcc.mq.OZ (Richard Miller) (11/14/90)

In article <2230002@hpuplca.HP.COM> joseph@hpuplca.HP.COM (	Joseph Hohl ) writes:
>> In article <1990Oct31.153710.7865@cec1.wustl.edu> abed@saturn.wustl.edu (Abed Hammoud) writes:
>> >
>> >	Is there a way I can use the unix spelling program ispell
>> >	or spell from within vi. if yes and some body have done it
>> >	please let me know how...
>> 
>> I usually use :1,.$!spell.  This replaces the buffer with your spelling
>> errors, but u[ndo] restores the buffer.  You can also say !}spell to do
>> -- 
>> Bob Peirce, Pittsburgh, PA				  412-471-5320
>> ...!uunet!pitt!investor!rbp			rbp@investor.pgh.pa.us
>> ----------
>
>I use the following entry in my .exrc to use ispell:
>
>	map S :w!^M:!ispell %^M:e!^^M^M           ! The ^Ms are Cntl-Ms

So what is this ispell thing ?

I have a little shell script which I invoke from something like this
!}spck or !!spck or what ever you like, and it will flag all the
misspelt words with SPCK>.  Once you have corrected the words you
can run spck over it again and the SPCK> that are now correct disappear.
I also have an uspck script which simply removes all the remaining SPCK>s
since there are always so words that are not in the dictionary.

Richard.

PS.  I also have some vi macros cut the word under cursor and add them
     to a list which can be appended the list spell(1) uses, I can
     dig them up an post 'em if anyone is interested.

------- SNIP --------------------------------------------------
#!/bin/sh
#
# spck
#   marks mis-spelt words in the input stream SPCK\>word
#
# Richard Miller 
# Sat Apr 25 02:20:43 EST 1987
SOURCE=/tmp/source$$
SEDFILE=/tmp/sedfile$$

if test $# = 0
then
    cat > $SOURCE
else
    cat $* > $SOURCE
fi

echo s/SPCK\>//g  > $SEDFILE
sed 's/SPCK>//g' $SOURCE |
spell  |
sed '
    /^$/d
    s|^.*$|s/\\\<&\\\>/SPCK>&/g|
    ' >> $SEDFILE
sed -f $SEDFILE $SOURCE
rm -f $SEDFILE $SOURCE
------- SNIP --------------------------------------------------
#!/bin/sh
# uspck
#     un-marks mis-spelt words which were marked SPCK\>word
#
# Richard Miller 
# Mon Jun 22 00:57:16 EST 1987

if test $# = 0
then
    sed 's/SPCK>//g' 
else
    sed 's/SPCK>//g' $*
fi
 ____________________________________________________________________________
|   __                                                                       |
|  /_/ -__ /_ _ _ _ __/  /\/\ -//  _                                         |
| / \ /(_ / /(_/ / (_/  /   ////(~/                                          |
|                                                                            |
| School Math, Physics, Elec and Computing, Macquarie University SYDNEY AUST.|
|  Email: richard@mqcomp.mqcs.mq.oz.au ,Ph:+61 2 8058374, Fax:+61 2 8058983  |
|____________________________________________________________________________|

mayoff@cs.utexas.edu (Robert Mayoff) (11/14/90)

ispell is a program that does interactive spell-checking; when it finds a word
not in its dictionary, it puts it on the screen, with some context, and gives a
list of possible replacement words.  It lets you take several actions, such as
replacing the word with a suggested word, or adding the word to a private
dictionary.  It has a better dictionary than the standard spell, because its
dictionary have conjugation information.  Hence, while standard spell accepts
'verbing' as a word (I just checked), ispell won't, because it knows that that
is not a valid conjugation.
-- 
/_  rob		<mayoff@cs.utexas.edu>
 /_ Fun things to do with UNIX (#12 in a series):
  / cd /dev; cat mouse			# Try this on a Sun.  Really!

kevin@ttidca.TTI.COM (Kevin Carothers) (11/15/90)

In article <1990Nov7.005405.461@investor.pgh.pa.us> rbp@investor.pgh.pa.us (Bob Peirce #305) writes:
>I usually use :1,.$!spell.  This replaces the buffer with your spelling
>errors, but u[ndo] restores the buffer.

 A VERY dangerous proposition indeed.

And in article <59025@microsoft.UUCP> steveha@microsoft.UUCP (Steve Hastings) writes:
>Simpler still:
>
>:w !spell
>
>This pipes the whole file through spell, then waits for you to hit a key
>before showing you the file again.  No danger of losing your data, and less
>to type.
>
 [---]


 Which is sound advice.
 However, if People are more "comfortable" with Mr. Pierce's more 
 orthogonal approach, the buffer "replace" behavior may be obviated
 by the following syntax;

 :1,.$w !spell


 This command may also be entered with buffer marks;

 :'a,'bw !spell


--
Kevin Carothers   {csun,psivax,philabs,retix}!ttidca!kevin

dhesi%cirrusl@oliveb.ATC.olivetti.com (Rahul Dhesi) (11/21/90)

Here's my spell filter for vi.  It's useful for LaTeX files, but works
for everything.  The stop list contains words one per line, enclosed in
backets.  E.g.:

[Emacs]
[Email]
[Feb]
[Fri]

#! /bin/csh -f
# filter text through this to see spelling errors summarized in
# a compact format;  make changes to avoid misinterpretation of
# Latex features; and use a stop list for final filtering.
# The stop list must be sorted in alphabetic order and is
# case-sensitive.   R.D. Wed Apr 18 21:17:43 PDT 1990

cat $* | 		# use stdin or list of files		\
 sed -e 's/\\/ /g' 	# replace backslash by blank		\
 	-e 's/^%//' 	# delete % at beginning of line		\
	-e 's/\$/ /g' 	# replace $ by blank			\
	-e 's/{/ /g' 	# replace { by blank			\
	-e 's/}/ /g' 	# replace } by blank			\
	| \
 spell | \
 sed -e 's/^/[/' -e 's/$/]/' |  # bracket so complete lines match \
 fgrep -v -f ~dhesi/.stoplist | # print only words not in stoplist \
 sed -e 's/^\[//' -e 's/\]$//'  |  # remove brackets		   \
 fmt				# ... and display in compact format
--
Rahul Dhesi <dhesi%cirrusl@oliveb.ATC.olivetti.com>
UUCP:  oliveb!cirrusl!dhesi