Is it possible to delete everything except the selected text?

Viewed 191

For example, we have text:

<Text>Test_request</Text>

Command vit will sélect all inside tags, how delete only tags?

2 Answers

The real real world solution would be to use the dst command provided by the ubiquitous surround plugin.

If you want a vanilla solution:

yit"_datP

Breakdown:

  • yit yanks the content of the tag to the default register,
  • "_dat cuts the whole tag to the "black hole" register,
  • P puts the content of the default register before the cursor.

See :help "_, :help P.

Just to complement romainl's answer. There is another plugin called vim-sandwich which works similarly to vim-surround. If you have installed vim-sandwich successfully, you can use sdt to delete the HTML tag surrounding your text. This works flawlessly for me.

Related