I would like to turn on vim's spell check and delete only the words
vim knows. Then I will go thru the remaining words and add them, or
not, to my vim word list.
Is that possible?
-Bill
How about that:
:%s/\w\+/\=printf("%s",
empty(spellbadword(submatch(0))[0])?submatch(0):'')/
(one line)
regards,
Christian
On Mo, 01 M�r 2010, Christian Brabandt wrote:
> :%s/\w\+/\=printf("%s",
> empty(spellbadword(submatch(0))[0])?submatch(0):'')/
> (one line)
this should have been
:%s/\w\+/\=printf("%s", !empty(spellbadword(submatch(0))[0])?submatch(0):'')/
(still one line, though)
regards,
Christian
That does work, but leaves empty lines, which are easy to remove with:
:sort iu
Is it possible to use spellbadword() in:
:g/{pattern}/d
Lovely solution and introduction to spellbadword() (which I've
not seen/used before). However, I'm curious why you chose to use
printf("%s", ...) instead of just using the contents.
So my reworking of Christian's idea:
:%s/\w\+/\=empty(spellbadword(submatch(0))[0]))?'':submatch(0)/g
The other catch (at least in English) is that words like "can't"
aren't found whole by "\w\+", so you might have to tweak the
regexp or 'iskeyword' to include apostrophes.
-tim
Yes wonderful introduction to spellbadword()
I tried your solution and got errors, counted parens and found one too
many closing, and this works.
:%s/\w\+/\=empty(spellbadword(submatch(0))[0])?'':submatch(0)/g
-Bill
On Mo, 01 M�r 2010, Tim Chase wrote:
> Christian Brabandt wrote:
>> this should have been
>>
>> :%s/\w\+/\=printf("%s", !empty(spellbadword(submatch(0))[0])?submatch(0):'')/
>
> Lovely solution and introduction to spellbadword() (which I've not
> seen/used before). However, I'm curious why you chose to use
> printf("%s", ...) instead of just using the contents.
old habbit (I often tend use use explicitly printf() even when it not
required)
>
> So my reworking of Christian's idea:
>
> :%s/\w\+/\=empty(spellbadword(submatch(0))[0]))?'':submatch(0)/g
>
> The other catch (at least in English) is that words like "can't" aren't
> found whole by "\w\+", so you might have to tweak the regexp or
> 'iskeyword' to include apostrophes.
true. Didn't think of that since in Germany we wouldn't consider that as
words.
regards,
Christian
Thank you Tim and Christian
Since I had one word per line, having grabbed the words from a book a
friend is writing, sorted to keep only unique, this works great:
:%s/\w\+\n/\=empty(spellbadword(submatch(0))[0])?submatch(0):''/g
-Bill
For this I would use:
qa]sddkq1000@a
[please don't top-post]
The problems I'd have with doing that are mostly "I have to think
about things" issues:
- do I have more than 1000 items and may need to re-execute the
macro? (having 'ruler' showing the number of lines in the file
might help)
- does "]s" break the repeated macro execution if there isn't a
bad-spell match, or does it continue to delete the remainder of
the 1000 things after the last bad-spelling is found?
- do I have something valuable in register "a" that I don't want
to tromp with my macro; or the flip side of "what register do I
have that's available"?
- if there's a bad-spell word as the first line, does issuing "k"
("go up from line #1", possibly an error-ish condition) after
deleting it trigger the macro-recording to stop?
- can I issue this from anywhere in the file or do I have to do
it from the top (and does my 'wrapscan' setting change its behavior)?
That's a lot more thinking than I like to do ;-)
The :g or :s versions can be used in a mapping and trusted to do
what they should without any of the above issues (except perhaps
tromping the search register).
-tim
On Mo, 01 M�r 2010, corykendall wrote:
> I'm new here, but I tend to use macro based solutions. Is there a
> problem with that?
Certainly not. Use whatever works best for you. I personally dislike
macros, because usually I have problems decrypting them. Therefore I
prefer ex commands and functions which I find more readable.
regards,
Christian
On Mar 2, 9:49 am, Tim Chase <v...@tim.thechases.com> wrote:
>
> The problems I'd have with doing that are mostly "I have to think
> about things" issues:
>
> - do I have more than 1000 items and may need to re-execute the
> macro? (having 'ruler' showing the number of lines in the file
> might help)
>
> - does "]s" break the repeated macro execution if there isn't a
> bad-spell match, or does it continue to delete the remainder of
> the 1000 things after the last bad-spelling is found?
>
> - do I have something valuable in register "a" that I don't want
> to tromp with my macro; or the flip side of "what register do I
> have that's available"?
>
> - if there's a bad-spell word as the first line, does issuing "k"
> ("go up from line #1", possibly an error-ish condition) after
> deleting it trigger the macro-recording to stop?
>
> - can I issue this from anywhere in the file or do I have to do
> it from the top (and does my 'wrapscan' setting change its behavior)?
>
> That's a lot more thinking than I like to do ;-)
>
> The :g or :s versions can be used in a mapping and trusted to do
> what they should without any of the above issues (except perhaps
> tromping the search register).
>
> -tim
Good responses both, thanks guys.
I think I agree that if you want as repeatable solution, an ex
expression is better because it's more readable, and rememberable.
But if I need a one-off solution, I find it easier to record a
macro... Fix the first occurance, navigate to the next occurance in a
repeatable way, and then execute as many times as necessary. I also
like that I can run a macro once... twice... three times... each time
making sure it worked correctly, and then launch it on the whole file.
Perhaps once I get more comfortable with regular expressions I'll
change my tune :)
On Mar 2, 9:49 am, Tim Chase <v...@tim.thechases.com> wrote: