2

I'd like echo line from a hidden buffer without moving my cursor. Something like this:

:redir! > /tmp/myfile
:1,$print 3
:redir end

(I want to inspect hidden buffers without changing the window layout or the cursor position.)

The above works great for the current buffer, but :print doesn't take a buffer as an argument.

Is there some vim command that prints the lines in a buffer?

(And FWIW, I can't use :w because that also changes the names and numbers of the open buffers.)

So8res
  • 1,521
  • 1
  • 18
  • 30

1 Answers1

2

You can access lines from any buffer via the getbufline() function. Example:

for line in getbufline(3, 1, '$')
    echo line
endfor
Ingo Karkat
  • 22,638
  • 2
  • 45
  • 58