Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.)

share|improve this question
No. Buffer numbers never change. Why don't you simply :b to that hidden buffer? – romainl Feb 6 '13 at 19:34
up vote 2 down vote accepted

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

for line in getbufline(3, 1, '$')
    echo line
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .