To specify ex (or ed ) commands in vi , you precede the ex command with a : ; not with a % . The ex substitute command s/[ ]*^//g is a request to replace string of 0 or more <space> characters that are followed by the start of a line with nothing and to repeat that operation for every portion of each input line that matches that pattern. (Since there can never be anything on a line before the start of that line, there will never be any matches.)
To remove leading spaces from every line in a file you are editing in vi , try the command: