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

selecting a URL

Expand Messages
  • Paul
    How would I go about making it easy for myself to select a string matching a complex regex, such as a URL? Ideally I d like to be able to put my cursor into
    Message 1 of 11 , Mar 31, 2009
      How would I go about making it easy for myself to select a string
      matching a complex regex, such as a URL? Ideally I'd like to be able
      to put my cursor into the middle of a line like

      <a href=http://vim.wikia.com/wiki/Special:Search?
      search=comments&go=1>search</a>

      and type "diu" and have Vim delete just the URL. And I'd like that to
      work regardless of the context where the URL is found.

      But a less perfectly streamlined solution would be fine too.

      Any suggestions?
      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Luc Hermitte
      Hello, ... I have an old command that I use to select URL and other path-like strings. http://code.google.com/p/lh-vim/source/browse/misc/trunk/_vimrc_win
      Message 2 of 11 , Mar 31, 2009
        Hello,

        "Paul" <sciadams@...> wrote:

        > How would I go about making it easy for myself to select a string
        > matching a complex regex, such as a URL? Ideally I'd like to be able
        > to put my cursor into the middle of a line like
        >
        > <a href=http://vim.wikia.com/wiki/Special:Search?
        > search=comments&go=1>search</a>
        >
        > and type "diu" and have Vim delete just the URL. And I'd like that to
        > work regardless of the context where the URL is found.
        >
        > But a less perfectly streamlined solution would be fine too.
        >
        > Any suggestions?

        I have an "old" command that I use to select URL and other path-like strings.
        http://code.google.com/p/lh-vim/source/browse/misc/trunk/_vimrc_win

        From this, you can define an :omap on "iu" that calls a function that is turns:
        1- check the cursor is on a valid path
        2- move the cursor to the beginning of the pattern
        3- go into visual mode
        4- move the cursor to the end of the pattern


        See also http://code.google.com/p/lh-vim/source/browse/cpp/trunk/plugin/omap-param.vim
        for complex omap definitions.

        HTH,

        --
        Luc Hermitte
        http://lh-vim.googlecode.com/
        http://hermitte.free.fr/vim/

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Matt Wozniski
        ... It would be a lot easier here if this was valid XHTML, since then you could just use di ... If you re really determined to do this, you could make your
        Message 3 of 11 , Mar 31, 2009
          On Tue, Mar 31, 2009 at 12:23 PM, Paul wrote:
          >
          > How would I go about making it easy for myself to select a string
          > matching a complex regex, such as a URL? Ideally I'd like to be able
          > to put my cursor into the middle of a line like
          >
          > <a href=http://vim.wikia.com/wiki/Special:Search?
          > search=comments&go=1>search</a>

          It would be a lot easier here if this was valid XHTML, since then you
          could just use di"

          > and type "diu" and have Vim delete just the URL. And I'd like that to
          > work regardless of the context where the URL is found.
          >
          > But a less perfectly streamlined solution would be fine too.
          >
          > Any suggestions?

          If you're really determined to do this, you could make your own text
          object to do it (there are some examples on the wiki), but I doubt it
          would be that useful. In my experience, 99 times out of 100, URLs
          will either stand alone (in which case you could use diW) or be quoted
          (so you could use di"). I rarely something like

          foo=http://google.com

          ~Matt

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Paul
          ... Aha, I ll look into that, probably borrowing your code, Luc. Thanks both! ... Yeah, that would be very nice. I m manually editing plain text into HTML, and
          Message 4 of 11 , Mar 31, 2009
            > If you're really determined to do this, you could make your own text
            > object to do it

            Aha, I'll look into that, probably borrowing your code, Luc. Thanks
            both!

            > In my experience, 99 times out of 100, URLs will either stand alone
            > (in which case you could use diW) or be quoted (so you could use di").

            Yeah, that would be very nice. I'm manually editing plain text into
            HTML, and dealing with hundreds of unquoted URLs set into sentences
            and terminated with periods, commas, dashes, unmatched closing parens,
            and worse.
            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • Dotan Cohen
            ... There was an article on Codding Horror not long ago discussing this. What do you do if a URL ends in an end-parenthesis? It could be part of the url or
            Message 5 of 11 , Mar 31, 2009
              > Yeah, that would be very nice. I'm manually editing plain text into
              > HTML, and dealing with hundreds of unquoted URLs set into sentences
              > and terminated with periods, commas, dashes, unmatched closing parens,
              > and worse.
              >

              There was an article on Codding Horror not long ago discussing this.
              What do you do if a URL ends in an end-parenthesis? It could be part
              of the url or not! Wikipedia is especially bad about this.

              --
              Dotan Cohen

              http://what-is-what.com
              http://gibberish.co.il

              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • Gene Kwiecinski
              ... Not to sound flip about it, but there s only so much you can do to guard against retardery. If someone *insists* on including, bad enough spaces, but
              Message 6 of 11 , Mar 31, 2009
                >>Yeah, that would be very nice. I'm manually editing plain text into
                >>HTML, and dealing with hundreds of unquoted URLs set into sentences
                >>and terminated with periods, commas, dashes, unmatched closing parens,
                >>and worse.

                >There was an article on Codding Horror not long ago discussing this.
                >What do you do if a URL ends in an end-parenthesis? It could be part
                >of the url or not! Wikipedia is especially bad about this.

                Not to sound flip about it, but there's only so much you can do to guard
                against retardery. If someone *insists* on including, bad enough
                spaces, but *punctuation* into filenames and complete urls, then *he's*
                the one with the problem. Garbage in, garbage out. If the link gets
                screwed up so that it's broken (ie, can't click-through it), then too
                bad.

                I always try to separate urls with at least a space, eg, at the end of a
                sentence, so there's no confusion whether/not that trailing dot belongs.

                Me personally, I wouldn't worry about trying to contort a 'vim' script
                to deal with crap like that.

                But *publishers* (like wiki) who merge urls with other surrounding
                text/punctuation? That's unforgiveable. Someone should edit the
                page/entry itself to fix it.

                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • Paul
                ... Thanks, that article s an interesting read (I found it here: http://www.codinghorror.com/blog/archives/001181.html).
                Message 7 of 11 , Mar 31, 2009
                  >There was an article on Codding Horror not long ago discussing this.
                  >What do you do if a URL ends in an end-parenthesis? It could be part
                  >of the url or not! Wikipedia is especially bad about this.

                  Thanks, that article's an interesting read (I found it here:
                  http://www.codinghorror.com/blog/archives/001181.html).
                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_use" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                • Dotan Cohen
                  ... Well, it is standards-compliant. The same was once said about spaces in filenames, but look how common that is today. You and I may hate it, but so long as
                  Message 8 of 11 , Mar 31, 2009
                    > Not to sound flip about it, but there's only so much you can do to guard
                    > against retardery.  If someone *insists* on including, bad enough
                    > spaces, but *punctuation* into filenames and complete urls, then *he's*
                    > the one with the problem.  Garbage in, garbage out.  If the link gets
                    > screwed up so that it's broken (ie, can't click-through it), then too
                    > bad.
                    >

                    Well, it is standards-compliant. The same was once said about spaces
                    in filenames, but look how common that is today. You and I may hate
                    it, but so long as the RFC / filesystem supports punctuation in URLs /
                    filenames then we can't complain when users use that feature.



                    > I always try to separate urls with at least a space, eg, at the end of a
                    > sentence, so there's no confusion whether/not that trailing dot belongs.
                    >

                    Be conservative with what you send, and liberal with waht you receive, no?



                    > Me personally, I wouldn't worry about trying to contort a 'vim' script
                    > to deal with crap like that.
                    >

                    It depends on what the job was, I suppose.


                    > But *publishers* (like wiki) who merge urls with other surrounding
                    > text/punctuation?  That's unforgiveable.  Someone should edit the
                    > page/entry itself to fix it.
                    >

                    It's perfectly legal in the standards. You might want to try to change
                    wikipedia policy, however.


                    --
                    Dotan Cohen

                    http://what-is-what.com
                    http://gibberish.co.il

                    --~--~---------~--~----~------------~-------~--~----~
                    You received this message from the "vim_use" maillist.
                    For more information, visit http://www.vim.org/maillist.php
                    -~----------~----~----~----~------~----~------~--~---
                  • Gene Kwiecinski
                    ... Well, if an url is split across lines because of a space in a directory/filename, again, that s just too bad. Ditto with urls that happen to require 6
                    Message 9 of 11 , Mar 31, 2009
                      >>Not to sound flip about it, but there's only so much you can do to guard
                      >>against retardery.  If someone *insists* on including, bad enough
                      >>spaces, but *punctuation* into filenames and complete urls, then *he's*
                      >>the one with the problem.  Garbage in, garbage out.  If the link gets
                      >>screwed up so that it's broken (ie, can't click-through it), then too
                      >>bad.

                      >Well, it is standards-compliant. The same was once said about spaces
                      >in filenames, but look how common that is today. You and I may hate
                      >it, but so long as the RFC / filesystem supports punctuation in URLs /
                      >filenames then we can't complain when users use that feature.

                      Well, if an url is split across lines because of a space in a directory/filename, again, that's just too bad. Ditto with urls that happen to require 6 video-lines of text to contain. Hitting tinyurl.com to compress it to something manageable *shouldn't* be a requirement.


                      >>I always try to separate urls with at least a space, eg, at the end of a
                      >>sentence, so there's no confusion whether/not that trailing dot belongs.

                      >Be conservative with what you send, and liberal with waht you receive, no?

                      Generally, yeah. The issue is *how* liberal you need to be to receive a valid url.


                      >>Me personally, I wouldn't worry about trying to contort a 'vim' script
                      >>to deal with crap like that.
                      >It depends on what the job was, I suppose.

                      Point being that no program, even a 'vim' script, can be perfect, and adding all sorts of preprocessing, postprocessing, regexp hacks, etc., to *try* to make sense of everything some ninny who things that having an entire article-title with ".htm" appended to it is a Good Idea for a weblink, is just foolhardy. The added complexity can break *other* things if you're not careful, obfuscate the clear intent of the code, even open itself up for attacks.


                      >>But *publishers* (like wiki) who merge urls with other surrounding
                      >>text/punctuation?  That's unforgiveable.  Someone should edit the
                      >>page/entry itself to fix it.

                      >It's perfectly legal in the standards. You might want to try to change
                      >wikipedia policy, however.

                      Then they should be prepared to have things like

                      The page (http://fooey.com/waycoolarticle.htm) is awesome!

                      remain ambiguous, since the opening '(' *might* be spotted and disregarded as not part of the actual url, being before the "http:", but the trailing ')' *can* be considered part of the url or not, since it *would* be a valid part of the title, which is what I thought the OP's issue originally was.

                      At the *very* least, use

                      The page ( http://fooey.com/waycoolarticle.htm ) is awesome!

                      as I got into the habit of doing. Then you can code for parens, squares, quotes, whatever some ninny decides to throw into an url just because it's "legal".

                      Again, ain't meaning to sound flip (or surly), but I've really had quite enough of those ninnies who generate garbage as their input data, then wonder why the program/script/filter/whatever chokes on it. Eg, why is the url

                      http://fooey.com/AweSome Article About Nothing At All.htm

                      put through a filter to convert to a hot-link only makes

                      http://fooey.com/AweSome

                      the link in question.

                      Duh..

                      --~--~---------~--~----~------------~-------~--~----~
                      You received this message from the "vim_use" maillist.
                      For more information, visit http://www.vim.org/maillist.php
                      -~----------~----~----~----~------~----~------~--~---
                    • Ben Fritz
                      ... You ve gotten a couple of specific suggestions (for a URL). In the general case, if you don t want to go through defining your own text object every time,
                      Message 10 of 11 , Apr 1, 2009
                        On Mar 31, 11:23 am, Paul <sciad...@...> wrote:
                        > How would I go about making it easy for myself to select a string
                        > matching a complex regex, such as a URL?

                        You've gotten a couple of specific suggestions (for a URL). In the
                        general case, if you don't want to go through defining your own text
                        object every time, there's this:

                        http://vim.wikia.com/wiki/Copy_or_change_search_hit
                        --~--~---------~--~----~------------~-------~--~----~
                        You received this message from the "vim_use" maillist.
                        For more information, visit http://www.vim.org/maillist.php
                        -~----------~----~----~----~------~----~------~--~---
                      • Tony Mechelynck
                        On 01/04/09 00:07, Dotan Cohen wrote: [Gene Kwiecinski wrote] [...] ... In [http://www.example.net/somewhere/something.html MediaWiki external links],
                        Message 11 of 11 , Apr 1, 2009
                          On 01/04/09 00:07, Dotan Cohen wrote:
                          [Gene Kwiecinski wrote]
                          [...]
                          >> But *publishers* (like wiki) who merge urls with other surrounding
                          >> text/punctuation? That's unforgiveable. Someone should edit the
                          >> page/entry itself to fix it.
                          >>
                          >
                          > It's perfectly legal in the standards. You might want to try to change
                          > wikipedia policy, however.

                          In [http://www.example.net/somewhere/something.html MediaWiki external
                          links], [[Internal links|MediaWiki internal links]], or
                          [url=http://www.example.com/wherever/it/is/tobefound.html%5dBBL and forum
                          text[/url], as well as in <a
                          href="http://www.example.org/whatever.htm">[X]HTML</a>, the underlying
                          markup code makes it perfectly unambiguous where the link points to. No
                          edits or policy changes necessary.


                          Best regards,
                          Tony.
                          --
                          The man who sets out to carry a cat by its tail learns something that
                          will always be useful and which never will grow dim or doubtful.
                          -- Mark Twain.

                          --~--~---------~--~----~------------~-------~--~----~
                          You received this message from the "vim_use" maillist.
                          For more information, visit http://www.vim.org/maillist.php
                          -~----------~----~----~----~------~----~------~--~---
                        Your message has been successfully submitted and would be delivered to recipients shortly.