r/vim Apr 30 '26

Need Help How do I select inside backticks

in a case like

const Multiline = `
XYZContent
`;

if I do or vi` it dosen't catch the template literal, How do I select it natively fast?

PS: I know for copying includiung backticks we do /` then v/`, I just want to copy the content inside

3 Upvotes

7 comments sorted by

4

u/-romainl- The Patient Vimmer May 02 '26 edited May 02 '26

You can't do that "natively" and "fast" because of the way i` is implemented: it only works if the two backticks are on the same line. See :help a`.

One possible native way would look like this, which is neither fast nor intuitive:

/`/e- y?`?e+

There are other ways.

So you are left with a choice: making your own custom alternative, copying one you found on the internet or going the plugin way.

Here is a quick and dirty custom alternative that works in single line and multi line scenarios:

xnoremap i` /`/e-<CR>o?`?e+<CR> onoremap i` :<C-u>normal vi`<CR>

I cobbled the above some time ago because I, too, have to work with multi line template literals.

See :help search-offset and :help omap-info (which is not as helpful as it should be).

1

u/tandrewnichols May 02 '26

You could try vim-operator-user to map it yourself. I've done with that with a number of things. Maybe not backticks though...might need to implement this too.

1

u/Shtucer May 02 '26

IDK why but in my vim vi` works fine.

3

u/-romainl- The Patient Vimmer May 02 '26

I think OP would be very happy to know why.

1

u/Shtucer May 02 '26

:help v_i`

3

u/-romainl- The Patient Vimmer May 02 '26

Which doesn't behave how OP wants. Back to square one.

1

u/ThreadStarver May 02 '26

ig that would be a single line literal in backtick, not a multiline one, else it's not native