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

Change numbered targets to a more natural syntax

Open blasco opened this issue 4 years ago • 7 comments

Given the following text: f (a, b, c , d)

if I want to change the 2nd previous argument I need to type " c2ila ", but isn't it more natural to think:

c(hange) [operator] in / around 1,2,3,4... nth last / next argument [text object]

so, ci2la instead of c2ila. Is it possible to achieve this behavior? Or am I thinking about it in the wrong way?

blasco avatar Sep 21 '19 22:09 blasco

I've found a tutorial referring this plugin, and they also thought it in the way I wrote it: https://www.barbarianmeetscoding.com/blog/2019/08/11/exploring-vim-plugins-improve-and-extend-your-text-objects-with-targets-vim

c2ina to change inside the second next argument (notice the explanation doesn't match the position of the 2)

Is this a limitation? or could it be achieved?

blasco avatar Sep 21 '19 22:09 blasco

This used to be a limitation, but might not be anymore. Will check it out when I find the time 👍

wellle avatar Sep 23 '19 08:09 wellle

Great news. Is there anyway that I could help? Could you give me some hints on where to start? I would really love this feature.

blasco avatar Sep 25 '19 12:09 blasco

The parsing is happening in this function: https://github.com/wellle/targets.vim/blob/a79447f261e4b8b4327557aa03726f3849334b84/autoload/targets.vim#L36

I'm thinking that in some cases where getchar() returns digits those digits should be parsed as count instead. And then in s:call use that instead of v:count1. Or actually it should probably be parsedCount * v:count1 to still support c2ina next to ci2na (and possibly cin2a too?). Thanks!

wellle avatar Sep 25 '19 12:09 wellle

Great, I got it working. Thank you for the guidance, I'll open a Pull Request.

'cin2a' should be possible too, but with the current approach it would be quite dirty I think. We would need to check if check if a digit is pass after 'cin' just like now we check after 'ci'. A lot of sequential parsing, but maybe its the only approach. Any ideas? It would also be cool to have an absolute reference, without the 'n' or 'l', just 'c2a' = change 2nd argument. I have clear how to do the parsing, but any guidance on how to achieve this absolute positioning?

blasco avatar Sep 29 '19 20:09 blasco

Hey, thanks for the PR, I'll have a look at it soon 👍

I think we can ignore the cin2a thing for now. Let's keep the discussion about absolute positioning in #239.

wellle avatar Sep 29 '19 21:09 wellle

How're things going?

winkee01 avatar May 03 '20 06:05 winkee01