A vimscript variable longstring
(for instance obtained by let longstring = getline('.')
) contains a long sequence of characters (numbers, letters, commas, spaces, ...).
I want to replace a specific character, let it be A
, with a carriage return, so that when I use call writefile(longstring, 'this.file', '')
I obtain a file with several lines, each containing what was found between two consecutive A
s.
I tried with let longstring = substitute(longstring,'A','\r','g')
, which only results (after writefile
) in a single long line file with ^M
in place of A
. I guess I'm using the wrong replace string, but \n
doesn't work either.