Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appending a message to a buffer from a Vim script

Tags:

vim

scripting

What's the best way to append the content of a string variable from a Vim script?

like image 838
Ricardo Avatar asked Aug 05 '10 15:08

Ricardo


2 Answers

If variable contains no newlines, then use

call append(line('$'), [variable])

, you can also do

call append(line('$'), split(variable, "\n"))

,

execute "normal! Go".variable

, or

execute "normal! Go\<C-r>\<C-r>=variable\<CR>"
like image 154
ZyX Avatar answered Nov 15 '22 18:11

ZyX


You could also put the variable into a register like this:

let @a = variable

normal! G

execute "put a"

This works with or without carriage returns.

like image 37
Joel Avatar answered Nov 15 '22 20:11

Joel