0

so I can replace "<" -square brackets in VIM using ":s/</</g" and thats great, but It does not replace the ending bracket, thats problem number one. But the main issue is:

How do I replace all square brackets marked in VISUAL MODE? Say I want to replace all marked brackets "

just as on the screenshot with "&lt", so It will be displayed in HTML as codeenter image description here. I want to replace only them, not the others, do you know what is the pattern?

Sorry for beginners question, but I would like to know.

Thank you so much

2
  • It works in VISUAL MODE, but the escaping character exits the VISUALLY SELECTED LINES I think... Commented Mar 29, 2022 at 6:29
  • vi.stackexchange.com Commented Mar 29, 2022 at 10:09

3 Answers 3

1
  1. Those are angle brackets, not "square brackets".
  2. :s/</</g does nothing useful. Did you mean :s/</\&lt;/g?
  3. You already know how to change the opening bracket so you only need to do the same thing for the closing bracket but with the appropriate pattern and replacement.
Sign up to request clarification or add additional context in comments.

Comments

0

If I correctly interpret your question and screenshot, you want the > marked in red to be replaced with &gt; -- yes? If so, then I think @romainl suggested a good answer:

:s/>/&gt;/g

Comments

0

:s/>/>/g is working fine, thank you.

Basically, I also wanted to know if I can do this for multiple lines. Bat all you need to do is to select or mark specific "angle brackets", so again, thanks to romainnl and m_mlvx.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.