In normal usage :%s/A/B/g
is a simple way to substitute a pattern across the entire buffer. However the command mode implementation of :substitute
is subject to many user configurable variables and as such linters rightfully complain about it's usage in scripts.
I'm trying to use call substitute()
instead since this is a documented best practice in scripts. Using it against a string is easy, but I can't figure out how to make it operate on a buffer. I seem to be able to to call setline('1', substitute(getline('1'), 'A', 'B', ''))
to change one line at a time, but it doesn't work across a whole buffer.
What is the correct robust way to run a substitution across a whole buffer from a script or plugin?