VimTip: Search and f(replace)

Post by Nico Brailovsky @ 2019-02-26 | Permalink | Leave a comment

Pre-tip: When using search and replace in Vim, you don't need to use slashes This works just fine:

%s#search#replace

Did you know $replace doesn't have to be a literal expression? You can also use Vim functions! For example:

%s#bar#\=line('.')

will replace every occurrence of 'bar' for its line number. You can get creative and use any other Vimscript function.