Two things: Vim internally stores null bytes (i.e. CTRL-@
) as <NL>
== CTRL-J
for implementation reasons (the text is stored as C strings, which are null-terminated).
Additionally, the append()
function only inserts multiple lines when passed a List of text lines as its second argument. A single String will be inserted as one line, and (because of the translation), the newlines will appear as CTRL-@
.
Therefore, you need to pass a List, either by building a Python List, or by using the split()
Vim function to turn your single String into a List:
function! Test()
python << EOF
import vim
str = "\n"
vim.command("let rs = append(line('$'), split('%s', '\\n', 1))"%str)
EOF
endfunction