I have a text file patterned like this :
1 textA == this is textA ==
1.1 textB === this is textB ===
2 textC == this is textC ==
2.1 textD === this is textD ===
2.1.1 textE ==== this is textE ====
Whats the right regex pattern to formatting the text above:
== this is textA ==
=== this is textB ===
== this is textC ==
=== this is textD ===
I already try to perfoming this in vim :
^\w* -> this pattern just changes only textA and textB
I need to detect “.” and any character or words until meet the “=” sign. Any characters behind the “=” sign will be deleted. Thanks in advance for any answers and pointers.
Solution
^.\{-}\ze=
Explanation :
^. -> started with any single character
\{-} -> matches 0 or more of the preceding atom, as few as possible
\ze= -> Matches at any position, and sets the end of the match there: The previous char is the last char of the whole match
In human words :
“Find and replace a text started with any single character followed by anything and ended with “=” sign.
For more details on how to design reg.exps in Vim, see
:help patternwhich is the most useful section help in Vim IMHO.:help :gand:help :vcould also be of interest to you. You could for example do:which will emulate you typing 0dt= on each line containing an = sign.