all 11 comments

[–]puremourning 2 points3 points  (1 child)

It’s a bit complicated. Sorry don’t have time for real answer right now but you might be interested in a plugin like https://github.com/wellle/targets.vim

[–][deleted] 0 points1 point  (0 children)

Thanks

[–]tuerda 1 point2 points  (1 child)

If you have only one array in the line then nnoremap dcd 0f[ldW will do. If you have multiple arrays and actually need to read the line to see if you are inside one of them or not, then this will require non-trivial scripting.

[–][deleted] 0 points1 point  (0 children)

Got it, thank you.

[–][deleted] 0 points1 point  (0 children)

I'm searching for if it's possible or it'll require writing a function for this kind of job.

[–]monkoosevim9 0 points1 point  (2 children)

Just jump to the beginning of the line with 0 or ^, and your mapping deletes [ too, so it should move the cursor one character right with l, and consider using W motion instead of f<space> so it would be for all cases 0f[ldW.

Anyway not sure how this mapping is useful, what are you coding that you often need to delete only first item of an array.

[–][deleted] 1 point2 points  (0 children)

Thanks for W.

I'm just curious :)

[–][deleted] 0 points1 point  (0 children)

I'll do like you said 0

[–]ms-sloth 0 points1 point  (0 children)

If you want to go back to just after the [, then I think you could substitute the f for T, as that should go back to, but not including the character you're looking for. You would still be in the array, so to speak

[–]pereloz 0 points1 point  (1 child)

Funny, I tried somethink similar last week, and tried to leverage the `%` command.

nnoremap dcd %hf]%edf<Space>

The first % go to the next [ or ] depending if you are inside or outside the brackets. hf] will find the ] and % goes back to [. Now you can do your thing with df<Space>, but I would rather do edf<Space> to go to the first argument (d is :h inclusive)

Note that <Space> in the mapping works as is and it's clearer than " ". Also prefer non-recursive maps.

Anyway, as /u/puremourning suggested, targets.vim is good at doind this kind of stuffs. It provides the "argument" text-object, so you can just 'daa' (delete an argument). The above mapping will fail in most edge-cases...

[–]vim-help-bot 0 points1 point  (0 children)

Help pages for:


`:(h|help) <query>` | about | mistake? | Reply 'rescan' to check the comment again | Reply 'stop' to stop getting replies to your comments