I'm trying to create a buffer for a specific purpose, and for that, I need to add newlines to it to get it to be the same height as my current window. My first idea, using call append("^", repeat("\r", winheight(win_getid()))) didn't work (all it did was append ^M several times over to a single line), and I can't seem to find a solution anywhere else.


append() (or appendbufline()) do not allow \r or \n to insert new lines. You should use List instead. For instance,

call appendbufline(l:bufnr, '$', repeat([''], winheight(winnr())))

First off, are you sure you need to add actual content to your buffer? If the goal is just to get it the same height as a single, current window, there's a much simpler method in normal mode:


Or in Vimscript:

:wincmd =

The problem with your append command is that you're passing a string, which explicitly tells it add the content to a single line. To add multiple lines, you should instead pass a list:

call append("^", repeat([''], winheight(win_getid())))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.