0

I have a common task which is refactoring typescript import statements. However sometimes the quotes used for the dependency path are single quotes and sometimes double quotes. this means when i go through my list and want to use . repeat to repeat the ci" action, if the next item is single quoted I am screwed and it will not repeat, because it is looking for double quotes.

So I hope there is something out there that works with repeat (or will it require tpope/vim-repeat? I don't know) that can match both single and double quotes? I would use q for quote for it. And I would love if it could work on even more char classes too like javascript template string backtick quotes.

0

1 Answer 1

1

You could define you own iq text object with the following commands:

vnoremap iq ?['"]^Mlo/['"]^Mh
omap iq :normal viq<CR>

Where ^M is obtained by hitting Ctrl vEnter

Or simply:

vnoremap iq ?['"]<CR>lo/['"]<CR>h
omap iq :normal viq<CR>

I don't know any Vim plugin that define such Text Object but if you are using Neovim you could use the iq Text Object provided by nvim-various-textobjs.

3
  • very interesting, thank you, if this works as expected this looks like a powerful way to define anything a regex could match!
    – Steven Lu
    Feb 28 at 10:59
  • Thanks for your feedback. If it solves you problem I'll be glad if you could accept the solution. It allow the question to rest (but take your time to verify that it works for you ;-) ) :-) Feb 28 at 11:11
  • 1
    Not had time to test it yet and it is an admittedly rare use case. But I'll accept and come back to revoke it and comment if I encounter issues.
    – Steven Lu
    Mar 3 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.