3

Saying that I have such a file as below:

<random_string>hello<random_string>
random_string<random_string>hello<random_string>

I want to remove the first square bracket and its content so that the file becomes:

hello<random_string>
random_stringhello<random_string>

How could I achieve this?

I've tried to execute :%s/<.*>// but it will remove all things I think it's because it matches the last > for each line.

4

I guess this would be the easiest solution:

%s/<[^>]*>//

It matches:

  • < an opening angle bracket
  • [^>]* anything not being a closing angle bracket
  • > a angle bracket.

Of course the other solution is to use a non greedy operator as in the question linked by @Mass like this:

%s/<.\{-}>//

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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