Two things: Vim internally stores empty bytes (ie CTRL-@ ) as <NL> == CTRL-J for implementation reasons (the text is saved as C lines that end with zero).
In addition, the append() function only inserts a few lines when a list of text lines is passed as the second argument. One line will be inserted as one line, and (due to translation) newline characters will be displayed as CTRL-@ .
So you need to pass the list by creating a Python list or using the split() Vim function to turn your single line into a list:
function! Test() python << EOF import vim str = "\n" vim.command("let rs = append(line('$'), split('%s', '\\n', 1))"%str) EOF endfunction
source share