targets.vim
targets.vim copied to clipboard
Change numbered targets to a more natural syntax
Given the following text:
f (a, b, c
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?
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?
This used to be a limitation, but might not be anymore. Will check it out when I find the time 👍
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.
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!
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?
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.
How're things going?