vim replacing text code example Example 1: search and replace vim :%s/foo/bar/g Example 2: vim replace command :%s/foo/bar/g