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

Wishlist item: comma object-selecting motion

Expand Messages
  • Codie Codemonkey
    Object selections have become one of my favorite Vim features. (See :help object-select for some context for this request.) It took me awhile to discover
    Message 1 of 6 , Sep 27, 2013
    • 0 Attachment
      Object selections have become one of my favorite Vim features. (See :help object-select for some context for this request.) It took me awhile to discover them, but now that I have I use them constantly.

      I'd like to see a new one (or actually two considering the a and i forms) to select comma separated items in a list.

      In the simplest use case, comma object selection would include text starting at the previous comma or '(' to the next comma or ')'.

      a, - Select the current parameter in a C-style parameter list. Any previous whitespace will be included, as well as any trailing ','. Whitespace after the trailing ',' will not be included. If the parameter is the last in the parameter list, the ending delimiter will not be selected.

      i, - Same as a, except that leading whitespace and a trailing ',' (if present) will not be part of the selection.

      Other bracketing delimeters should work in addition to '(' and ')', including '[' and ']', '{' and '}' and possibly '<' and '>'.

      Examples:

      Consider this line of programming code:
      func( a, b(c, d[0]), "this, is a test")

      In normal mode with the cursor on the first parameter, "da," would change this to:
      func( b(c, d[0]), "this, is a test")

      Or, if the cursor is on 'b' in the second parameter, "da," would yield:
      func( a, "this, is a test")
      (Note the ignored ')' and ']' characters.)

      Or if the cursor was in the string of the third parameter, "da," would yield:
      func( a, b(c, d[0]), )
      (Note that the ',' in the string was not a delimiter because it was nested between quotes.)

      Some filetypes have other needs. For example in a CDF file, <C-R> is a bracketing character. To accommodate this I suggest some accompanying options:

      listsep - Characters used to separate items in a list. Default: ',;'
      liststart - Characters used to start a list (if not nested in quotes or balanced bracketed strings). Default: '({[<'.
      listend - Characters used to end a list (if not nested in quotes or balanced bracketed strings). Default: ')}]>'.

      -Codie

      --
      --
      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

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • David Fishburn
      On Fri, Sep 27, 2013 at 9:01 AM, Codie Codemonkey
      Message 2 of 6 , Sep 27, 2013
      • 0 Attachment
        On Fri, Sep 27, 2013 at 9:01 AM, Codie Codemonkey <codiecodemonkey@...> wrote:
        ...
         
        I'd like to see a new one (or actually two considering the a and i forms) to select comma separated items in a list.

        In the simplest use case, comma object selection would include text starting at the previous comma or '(' to the next comma or ')'.

        a,  -  Select the current parameter in a C-style parameter list. Any previous whitespace will be included, as well as any trailing ','.  Whitespace after the trailing ',' will not be included.  If the parameter is the last in the parameter list, the ending delimiter will not be selected.

        i,  -  Same as a, except that leading whitespace and a trailing ',' (if present) will not be part of the selection.

        Other bracketing delimeters should work in addition to '(' and ')', including '[' and ']', '{' and '}'  and possibly '<' and '>'.

        Examples:

        Consider this line of programming code:
              func( a, b(c, d[0]), "this, is a test")

        In normal mode with the cursor on the first parameter, "da," would change this to:
              func( b(c, d[0]), "this, is a test")

        Or, if the cursor is on 'b' in the second parameter, "da," would yield:
              func( a, "this, is a test")
        (Note the ignored ')' and ']' characters.)

        Or if the cursor was in the string of the third parameter, "da," would yield:
              func( a, b(c, d[0]), )
        (Note that the ',' in the string was not a delimiter because it was nested between quotes.)


        Since you list of inclusions and exception is fairly involved, I doubt a standard motion object could be created to handle this.

        Though, I believe you can do exactly what you want and even base it on the &filetype of the current buffer by writing your own expression map.

        The YankRing plugin (http://www.vim.org/scripts/script.php?script_id=1234) makes lots of use of the expression maps, which call a function to capture changed text (for later reference).

        These maps (the Vim standard key strokes) end up triggering a YankRing function to do the heavy lifting.

        In this case, the heavy listing is your rules based on &filetype and what the current character is (move to the closing ], skip ','s inside of "" and so on.

        If you are interested, you can look up expression maps.
        :h :omap
        :omap <expr> da, YourFunction(',')

        Or something along those lines.

        HTH,
        David

        --
        --
        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
         
        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • glts
        ... this is a common and very reasonable request. And since it is so common, talented people have already thought of a solution many years ago :) ... The most
        Message 3 of 6 , Sep 27, 2013
        • 0 Attachment
          On Friday, September 27, 2013 3:01:52 PM UTC+2, Codie Codemonkey wrote:
          > Object selections have become one of my favorite Vim features. (See :help object-select for some context for this request.) It took me awhile to discover them, but now that I have I use them constantly.
          >
          > I'd like to see a new one (or actually two considering the a and i forms) to select comma separated items in a list.
          >
          > In the simplest use case, comma object selection would include text starting at the previous comma or '(' to the next comma or ')'.
          >
          > a, - Select the current parameter in a C-style parameter list. Any previous whitespace will be included, as well as any trailing ','. Whitespace after the trailing ',' will not be included. If the parameter is the last in the parameter list, the ending delimiter will not be selected.
          >
          > i, - Same as a, except that leading whitespace and a trailing ',' (if present) will not be part of the selection.
          >
          > Other bracketing delimeters should work in addition to '(' and ')', including '[' and ']', '{' and '}' and possibly '<' and '>'.
          >
          > Examples:
          >
          > Consider this line of programming code:
          > func( a, b(c, d[0]), "this, is a test")
          >
          > In normal mode with the cursor on the first parameter, "da," would change this to:
          > func( b(c, d[0]), "this, is a test")
          >
          > Or, if the cursor is on 'b' in the second parameter, "da," would yield:
          > func( a, "this, is a test")
          > (Note the ignored ')' and ']' characters.)
          >
          > Or if the cursor was in the string of the third parameter, "da," would yield:
          > func( a, b(c, d[0]), )
          > (Note that the ',' in the string was not a delimiter because it was nested between quotes.)
          >
          > Some filetypes have other needs. For example in a CDF file, <C-R> is a bracketing character. To accommodate this I suggest some accompanying options:
          >
          > listsep - Characters used to separate items in a list. Default: ',;'
          > liststart - Characters used to start a list (if not nested in quotes or balanced bracketed strings). Default: '({[<'.
          > listend - Characters used to end a list (if not nested in quotes or balanced bracketed strings). Default: ')}]>'.

          this is a common and very reasonable request.

          And since it is so common, talented people have already thought of a
          solution many years ago :) ... The most popular framework for creating
          custom text objects is

          http://www.vim.org/scripts/script.php?script_id=2100
          https://github.com/kana/vim-textobj-user

          and what's even better, is that there is already a wealth of text
          objects made with that framework. See (especially textobj-parameter!):

          https://github.com/kana/vim-textobj-user/wiki

          Best,

          --
          --
          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

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • glts
          ... Also see http://www.vim.org/scripts/script.php?script_id=2699 http://www.vim.org/scripts/script.php?script_id=4171 https://github.com/b4winckler/vim-angry
          Message 4 of 6 , Sep 27, 2013
          • 0 Attachment
            On Friday, September 27, 2013 7:27:27 PM UTC+2, glts wrote:
            > On Friday, September 27, 2013 3:01:52 PM UTC+2, Codie Codemonkey wrote:
            > > Object selections have become one of my favorite Vim features. (See :help object-select for some context for this request.) It took me awhile to discover them, but now that I have I use them constantly.
            > >
            > > I'd like to see a new one (or actually two considering the a and i forms) to select comma separated items in a list.
            > >
            > > In the simplest use case, comma object selection would include text starting at the previous comma or '(' to the next comma or ')'.
            > >
            > > a, - Select the current parameter in a C-style parameter list. Any previous whitespace will be included, as well as any trailing ','. Whitespace after the trailing ',' will not be included. If the parameter is the last in the parameter list, the ending delimiter will not be selected.
            > >
            > > i, - Same as a, except that leading whitespace and a trailing ',' (if present) will not be part of the selection.
            > >
            > > Other bracketing delimeters should work in addition to '(' and ')', including '[' and ']', '{' and '}' and possibly '<' and '>'.
            > >
            > > Examples:
            > >
            > > Consider this line of programming code:
            > > func( a, b(c, d[0]), "this, is a test")
            > >
            > > In normal mode with the cursor on the first parameter, "da," would change this to:
            > > func( b(c, d[0]), "this, is a test")
            > >
            > > Or, if the cursor is on 'b' in the second parameter, "da," would yield:
            > > func( a, "this, is a test")
            > > (Note the ignored ')' and ']' characters.)
            > >
            > > Or if the cursor was in the string of the third parameter, "da," would yield:
            > > func( a, b(c, d[0]), )
            > > (Note that the ',' in the string was not a delimiter because it was nested between quotes.)
            > >
            > > Some filetypes have other needs. For example in a CDF file, <C-R> is a bracketing character. To accommodate this I suggest some accompanying options:
            > >
            > > listsep - Characters used to separate items in a list. Default: ',;'
            > > liststart - Characters used to start a list (if not nested in quotes or balanced bracketed strings). Default: '({[<'.
            > > listend - Characters used to end a list (if not nested in quotes or balanced bracketed strings). Default: ')}]>'.
            >
            > this is a common and very reasonable request.
            >
            > And since it is so common, talented people have already thought of a
            > solution many years ago :) ... The most popular framework for creating
            > custom text objects is
            >
            > http://www.vim.org/scripts/script.php?script_id=2100
            > https://github.com/kana/vim-textobj-user
            >
            > and what's even better, is that there is already a wealth of text
            > objects made with that framework. See (especially textobj-parameter!):
            >
            > https://github.com/kana/vim-textobj-user/wiki

            Also see

            http://www.vim.org/scripts/script.php?script_id=2699
            http://www.vim.org/scripts/script.php?script_id=4171
            https://github.com/b4winckler/vim-angry

            (And please do search vim.org/scripts, everything's there.)

            --
            --
            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

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • Christian Brabandt
            ... This is probably already implemented using some plugin. I just recently stumbled over this¹, but haven t used it, so this might or might not do what you
            Message 5 of 6 , Sep 27, 2013
            • 0 Attachment
              On Fr, 27 Sep 2013, Codie Codemonkey wrote:

              > Object selections have become one of my favorite Vim features. (See :help object-select for some context for this request.) It took me awhile to discover them, but now that I have I use them constantly.
              >
              > I'd like to see a new one (or actually two considering the a and i forms) to select comma separated items in a list.
              >
              > In the simplest use case, comma object selection would include text starting at the previous comma or '(' to the next comma or ')'.
              >
              > a, - Select the current parameter in a C-style parameter list. Any previous whitespace will be included, as well as any trailing ','. Whitespace after the trailing ',' will not be included. If the parameter is the last in the parameter list, the ending delimiter will not be selected.
              >
              > i, - Same as a, except that leading whitespace and a trailing ',' (if present) will not be part of the selection.
              >
              > Other bracketing delimeters should work in addition to '(' and ')', including '[' and ']', '{' and '}' and possibly '<' and '>'.
              >
              > Examples:
              >
              > Consider this line of programming code:
              > func( a, b(c, d[0]), "this, is a test")
              >
              > In normal mode with the cursor on the first parameter, "da," would change this to:
              > func( b(c, d[0]), "this, is a test")
              >
              > Or, if the cursor is on 'b' in the second parameter, "da," would yield:
              > func( a, "this, is a test")
              > (Note the ignored ')' and ']' characters.)
              >
              > Or if the cursor was in the string of the third parameter, "da," would yield:
              > func( a, b(c, d[0]), )
              > (Note that the ',' in the string was not a delimiter because it was nested between quotes.)
              >
              > Some filetypes have other needs. For example in a CDF file, <C-R> is a bracketing character. To accommodate this I suggest some accompanying options:
              >
              > listsep - Characters used to separate items in a list. Default: ',;'
              > liststart - Characters used to start a list (if not nested in quotes or balanced bracketed strings). Default: '({[<'.
              > listend - Characters used to end a list (if not nested in quotes or balanced bracketed strings). Default: ')}]>'.

              This is probably already implemented using some plugin. I just recently
              stumbled over thisน, but haven't used it, so this might or might not do
              what you want.

              น)https://github.com/kurkale6ka/vim-pairs

              Best,
              Christian
              --
              Marionetten lassen sich sehr leicht in Gehenkte verwandeln. Die
              Stricke sind schon da.
              -- Stanislaw Jerzy Lec (eig. S. J. de Tusch-Letz)

              --
              --
              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

              ---
              You received this message because you are subscribed to the Google Groups "vim_use" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            • Aaron Bohannon
              I ve been meaning to implement that sort of text region on top of textobj-user but haven t found the time. On a related note, it s worth mentioning...you can
              Message 6 of 6 , Sep 28, 2013
              • 0 Attachment
                I've been meaning to implement that sort of text region on top of textobj-user but haven't found the time.

                On a related note, it's worth mentioning...you can probably get more mileage out of the % motion than you realize. I didn't pay attention to this fact until recently, but you do not have to be on a bracket character when you use it. It will advance the cursor forward to the nearest bracket character and then jump to the matching one. For example, if you can yank/delete 'bar(b, baz(c, d))' in the text below by moving your cursor to the 'b' of 'bar' and using y% or d%:

                foo(a, bar(b, baz(c, d)), e, f)

                This fact doesn't get you the region command you're looking for, but it's useful in general and good to remember if you're trying to implement your own text object (obviously, you aren't going to be able to find matching brackets with a regular expression).

                ...Aaron

                On Friday, September 27, 2013 1:52:51 PM UTC-4, Christian Brabandt wrote:
                > On Fr, 27 Sep 2013, Codie Codemonkey wrote:
                >
                >
                >
                > > Object selections have become one of my favorite Vim features. (See :help object-select for some context for this request.) It took me awhile to discover them, but now that I have I use them constantly.
                >
                > >
                >
                > > I'd like to see a new one (or actually two considering the a and i forms) to select comma separated items in a list.
                >
                > >
                >
                > > In the simplest use case, comma object selection would include text starting at the previous comma or '(' to the next comma or ')'.
                >
                > >
                >
                > > a, - Select the current parameter in a C-style parameter list. Any previous whitespace will be included, as well as any trailing ','. Whitespace after the trailing ',' will not be included. If the parameter is the last in the parameter list, the ending delimiter will not be selected.
                >
                > >
                >
                > > i, - Same as a, except that leading whitespace and a trailing ',' (if present) will not be part of the selection.
                >
                > >
                >
                > > Other bracketing delimeters should work in addition to '(' and ')', including '[' and ']', '{' and '}' and possibly '<' and '>'.
                >
                > >
                >
                > > Examples:
                >
                > >
                >
                > > Consider this line of programming code:
                >
                > > func( a, b(c, d[0]), "this, is a test")
                >
                > >
                >
                > > In normal mode with the cursor on the first parameter, "da," would change this to:
                >
                > > func( b(c, d[0]), "this, is a test")
                >
                > >
                >
                > > Or, if the cursor is on 'b' in the second parameter, "da," would yield:
                >
                > > func( a, "this, is a test")
                >
                > > (Note the ignored ')' and ']' characters.)
                >
                > >
                >
                > > Or if the cursor was in the string of the third parameter, "da," would yield:
                >
                > > func( a, b(c, d[0]), )
                >
                > > (Note that the ',' in the string was not a delimiter because it was nested between quotes.)
                >
                > >
                >
                > > Some filetypes have other needs. For example in a CDF file, <C-R> is a bracketing character. To accommodate this I suggest some accompanying options:
                >
                > >
                >
                > > listsep - Characters used to separate items in a list. Default: ',;'
                >
                > > liststart - Characters used to start a list (if not nested in quotes or balanced bracketed strings). Default: '({[<'.
                >
                > > listend - Characters used to end a list (if not nested in quotes or balanced bracketed strings). Default: ')}]>'.
                >
                >
                >
                > This is probably already implemented using some plugin. I just recently
                >
                > stumbled over this�, but haven't used it, so this might or might not do
                >
                > what you want.
                >
                >
                >
                > �)https://github.com/kurkale6ka/vim-pairs
                >
                >
                >
                > Best,
                >
                > Christian
                >
                > --
                >
                > Marionetten lassen sich sehr leicht in Gehenkte verwandeln. Die
                >
                > Stricke sind schon da.
                >
                > -- Stanislaw Jerzy Lec (eig. S. J. de Tusch-Letz)

                --
                --
                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

                ---
                You received this message because you are subscribed to the Google Groups "vim_use" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                For more options, visit https://groups.google.com/groups/opt_out.
              Your message has been successfully submitted and would be delivered to recipients shortly.