Loading ...
Sorry, an error occurred while loading the content.

Re: mass delete words based on spell

Expand Messages
  • Bee
    ... -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit
    Message 1 of 13 , Mar 1, 2010
    • 0 Attachment
      On Mar 1, 11:35 am, Christian Brabandt <cbli...@...> wrote:
      > this should have been
      >
      > :%s/\w\+/\=printf("%s", !empty(spellbadword(submatch(0))[0])?submatch(0):'')/
      >
      > (still one line, though)

      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

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Tim Chase
      ... 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
      Message 2 of 13 , Mar 1, 2010
      • 0 Attachment
        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.

        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







        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • Bee
        ... Yes wonderful introduction to spellbadword() I tried your solution and got errors, counted parens and found one too many closing, and this works. ... -Bill
        Message 3 of 13 , Mar 1, 2010
        • 0 Attachment
          On Mar 1, 12:47 pm, Tim Chase <v...@...> 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.
          >
          > 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.

          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

          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Christian Brabandt
          Hi Tim! ... old habbit (I often tend use use explicitly printf() even when it not required) ... true. Didn t think of that since in Germany we wouldn t
          Message 4 of 13 , Mar 1, 2010
          • 0 Attachment
            Hi Tim!

            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

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • Bee
            ... Thank you Tim and Christian Since I had one word per line, having grabbed the words from a book a ... -Bill -- You received this message from the vim_use
            Message 5 of 13 , Mar 1, 2010
            • 0 Attachment
              On Mar 1, 1:00 pm, Bee <200...@...> wrote:
              > On Mar 1, 12:47 pm, Tim Chase <v...@...> 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.
              >
              > > 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.
              >
              > 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

              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

              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            • corykendall
              I m new here, but I tend to use macro based solutions. Is there a problem with that? For this I would use: qa]sddkq1000@a ... -- You received this message
              Message 6 of 13 , Mar 1, 2010
              • 0 Attachment
                I'm new here, but I tend to use macro based solutions. Is there a
                problem with that?

                For this I would use:
                qa]sddkq1000@a

                On Mar 1, 5:07 pm, Bee <200...@...> wrote:
                > On Mar 1, 1:00 pm, Bee <200...@...> wrote:
                >
                >
                >
                > > On Mar 1, 12:47 pm, Tim Chase <v...@...> 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.
                >
                > > > 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.
                >
                > > 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
                >
                > 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

                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php
              • Tim Chase
                ... [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
                Message 7 of 13 , Mar 2, 2010
                • 0 Attachment
                  corykendall wrote:
                  > I'm new here, but I tend to use macro based solutions. Is there a
                  > problem with that?
                  >
                  > 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



                  --
                  You received this message from the "vim_use" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php
                • Christian Brabandt
                  Hi corykendall! ... Certainly not. Use whatever works best for you. I personally dislike macros, because usually I have problems decrypting them. Therefore I
                  Message 8 of 13 , Mar 2, 2010
                  • 0 Attachment
                    Hi corykendall!

                    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

                    --
                    You received this message from the "vim_use" maillist.
                    Do not top-post! Type your reply below the text you are replying to.
                    For more information, visit http://www.vim.org/maillist.php
                  • corykendall
                    ... 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
                    Message 9 of 13 , Mar 2, 2010
                    • 0 Attachment
                      On Mar 2, 1:49 pm, Christian Brabandt <cbli...@...> wrote:
                      > Hi corykendall!
                      >
                      >
                      > 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...@...> 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 :)

                      --
                      You received this message from the "vim_use" maillist.
                      Do not top-post! Type your reply below the text you are replying to.
                      For more information, visit http://www.vim.org/maillist.php
                    • corykendall
                      ... 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
                      Message 10 of 13 , Mar 2, 2010
                      • 0 Attachment
                        On Mar 2, 1:49 pm, Christian Brabandt <cbli...@...> wrote:
                        > Hi corykendall!
                        >
                        >
                        > 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...@...> 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 :)

                        --
                        You received this message from the "vim_use" maillist.
                        Do not top-post! Type your reply below the text you are replying to.
                        For more information, visit http://www.vim.org/maillist.php
                      Your message has been successfully submitted and would be delivered to recipients shortly.