targets.vim icon indicating copy to clipboard operation
targets.vim copied to clipboard

Absolut position of text objects

Open blasco opened this issue 4 years ago • 3 comments

Right now we can do "change 1,2,3 previous/next text object". Would it be possible to achieve an absolute reference instead of a relative one, so : "change 1st, 2nd, 3rd, .. text object".

So we could do something like:

function ( first argument, second argument, third argument) function ( first argument, second argument, third argument )

c2a: "change 2nd argument" Achieving the same result in both cases.

blasco avatar Sep 21 '19 22:09 blasco

This is currently not supported, but an interesting idea. Thanks for bringing it up 👍

wellle avatar Sep 23 '19 08:09 wellle

Some quick comments on the suggestion:

  1. c2a conflicts with word objects c2aw, c2aa, c2ab etc. as it's a prefix.
  2. It's not clear if c2a would mean to change inner argument etc.
  3. Even the longer form c2aa is already used, for nested arguments, see https://github.com/wellle/targets.vim/blob/master/cheatsheet.md#argument-mappings.

So in order to add absolute positioning we'd need a different syntax, something like ci2fa (change in second "first" argument for example). But even then it's not clear how you could use this in nested args.

wellle avatar Sep 29 '19 21:09 wellle

You are right, I like your proposal ci2fa would also allow ci2la (change in second last argument). Not sure how to solve the nesting problem, I would propose that it works within the outer level if you are outside, and within the current level if you are inside:

In the following example:

<cursor> fun (arg1, arg2, arg3(subarg_1, subarg_2))

doing cila would change the last argument of fun. iIaA are still available to control the finer behavior.

fun (arg1, arg2, <insert cursor>)

If we would be inside fun, it would have the same effect:

 fun (<cursor>arg1, arg2, arg3(subarg_1, subarg_2))

But if we would be inside arg3:

fun (arg1, arg2, arg3(<cursor>subarg_1, subarg_2))

Then it would affect the last argument of arg3:

fun (arg1, arg2, arg3(subarg_1, <insert cursor>))

I think the "change in first" and "change in last" syntax makes sense. It unfortunately clashes with my cil (change in line), but I prioritize ease of mind rather than number of strokes, so I would consider fine to change that to cicl (change in current line) for example.

Oh, I've just noticed that cil also doesn't work with your default for previous. I personally don't like l for previous and I use nN (I think is consistent with vim's search behavior), but that would be a big philosophy change I guess.

blasco avatar Oct 20 '19 06:10 blasco