Friday, September 27, 2013

Re: Wishlist item: comma object-selecting motion

On Fri, Sep 27, 2013 at 9:01 AM, Codie Codemonkey <codiecodemonkey@gmail.com> 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@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: