I have the following in my vimrc:
func! AddSpaceBeforeEqual()
s/\([a-z)_0-9"'\[\]]\)=/\1 =/ge
endfunc
I'm using vint to lint my vimrc, and got the following warning :
ProhibitCommandWithUnintendedSideEffect Avoid commands with unintended side effects. Avoid using :s[ubstitute] as it moves the cursor and prints error messages. Prefer functions (such as search()) better suited to scripts. For many vim commands, functions exist that do the same thing with fewer side effects. See :help functions() for a list of built-in functions. Google Vimscript Style Guide
However, I do not think that they is a way to do the substitution without using the :s
command.
For example, the search()
function gives the lines matching a pattern, but there is no way to do substitution.
The substitute()
function operates on a string, and doesn't substitute on a whole file.
Should I implement a substitute method myself, or is they a smarter way to rewrite my function ?