tags:

views:

55

answers:

1

I have a vim-script which splits output to a new window, using the following command:

below split +view foo

I've been trying to find a way from an arbitrary buffer to scroll to the bottom of foo, or a setting to keep it defaulted to showing the bottom lines of the buffer.

I'm doing most of this inside of a python block of vim script. So I have something like:

python << endpython
import vim
import time
import thread
import sys

def myfunction(string,sleeptime,*args):
    outpWindow = vim.current.window
    while 1:
        outpWindow.buffer.append("BAR")
        #vim.command("SCROLL TO BOTTOM OF foo")
        time.sleep(sleeptime) #sleep for a specified amount of time.

vim.command('below split +view foo')
thread.start_new_thread(myfunction,("Thread No:1",2))
endpython

And need to find something to put in for vim.command("SCROLL TO BOTTOM of foo") line

+3  A: 

I usually record the new buffer number (let b_tgt = bufnr('%')), and more precisely its windows number. Then, in a try-finally block I record the current window number (let w_orig = bufwinnr('%')), jump to the window where I need to do something (:exe w_tgt.' wincmd w'), do the thing (:normal! G in your case), and jump back (in the :finally clause) to the current window (at the beginning of the action -> :exe w_orig.' wincmd w').

Now if other buffers may have been opened, or closed, we need to look for the target window each time as its number may have changed. This is done with bufwinnr(b_tgt).

Luc Hermitte
+1 for a very detailed and well explained answer.
Johnsyweb
Worked great, and I learned some new vim tricks, thanks!
Gavin Black