Saturday, September 28, 2013

Re: Wishlist item: comma object-selecting motion

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@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment