Vim, changing a tag around a word in HTML mode

In Vim HTML mode if you need to surround a word with a tag you can effectively use vim.surround with the cursor anywhere in the word using the following string: ysiw followed by the specific desired tag.

Alternatively you can use the different string yswt, followed by the specific desired tag, but with the cursor under the first character of the word.

For example, if you have to surround the word test with the tag <h2> you have to type, with the cursor at any point of the word, the following string ysiw or, with the cursor under the first letter, yswt.

In any case you get: test</h2>.

But if you need to change an existing tag you need, in addition to substitute the y command with c, to add another letter to the above string: you need to add another t to complete the operation.

The second string above mentioned must therefore be made up as follows: cstt instead of yswt. You can notice a double t at the end of the string:

  • The first t designates the target to be changed
  • The second t designates the target to replace

You can also notice the letter w is no longer necessary because the delimiter is already marked with the first t.

For example, if you have to change the tag around the word test from <h2> to “ you have to type, with the cursor at any point of the word test, the following string: cstt and you get: test.

Thank You for your attention.

(Originally published in my Tumblr account)

Comments

Popular posts from this blog

Vim: Cut, Copy and Paste to and from the system clipboard

Vim: searching for text containing a slash or a question mark