I've the following example line:aa ... abc abc abc ... zzI'm aware that :s/abc/ok/ will change the first occurrence of abc in the current line and adding g flag will change all of them.How do I change last occurrence of the string (without knowing how many there are and what's after the last)?
How to change last occurrence of the string in the line?
substitute
Greedy matching::s/.*\zsabc//The .* will consume as many characters as possible (therefore leaving you at the last occurrence), and the \zs sets the start of the actual match (\zs and \ze are useful substitutes for positive lookaheads/lookbehinds in Vim) so that the text before isn't removed as well.