Originally Posted by ufmale
how to replace every space with newline?
For example, if I have "i want to go to school", i want to convert it to
I try :%s/ /\n/g , but it does not seem to work
Also is there a way to count the number of space or number of word within vi?
I know you kind of got an answer already, but I wanted to shed some more light on the issue.
The reason it doesn't work is that \n has a different meaning in the replacement part of :substitue. See :help sub-replace-special for more information. Instead, you'll want to use the command :%s/ /\r/g. Use \s instead of a space if you want to include tabs, too. And \s\+ if you want it to replace consecutive spaces and/or tabs with one newline.