Display File Contents Realtime

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Display File Contents Realtime

jason heddings-2
Hello-

Is it possible to display a file contents in real time?  I have been trying
to get the contents of a file to be displayed in the preview window.  I can
manually re-edit this file, but I would like for it to automatically load
the file when it changes.  I have tried autoread, but that does not seem to
be working.

Thanks,
--jah

Reply | Threaded
Open this post in threaded view
|

RE: Display File Contents Realtime

David Fishburn
 

> -----Original Message-----
> From: jason heddings [mailto:[hidden email]]
> Sent: Friday, September 30, 2005 4:38 PM
> To: [hidden email]
> Subject: Display File Contents Realtime
>
> Hello-
>
> Is it possible to display a file contents in real time?  I
> have been trying to get the contents of a file to be
> displayed in the preview window.  I can manually re-edit this
> file, but I would like for it to automatically load the file
> when it changes.  I have tried autoread, but that does not
> seem to be working.

Have a look at my Tip:

" Tip #616: Have Vim check automatically if the file has changed externally
" http://www.vim.org/tips/tip.php?tip_id=616
" If you are using a console version of Vim, or dealing
" with a file that changes externally (ie a web server log)
" then Vim does not always check to see if the file has been changed.
" The GUI version of Vim will check more often (for example on Focus
change),
" and prompt you if you want to reload the file.

HTH,
Dave

Reply | Threaded
Open this post in threaded view
|

RE: Display File Contents Realtime

jason heddings-2
Thanks Dave-

It doesn't seem to be catching updates unless I remove then restore focus
from Vim.

I've got a build going in the background, and I'm trying to watch the
results as they are being captured to a file.  So, I don't think that the
timestamp is updated on each write to the file.

To simulate this, I've created a shell script:
#!/bin/sh
VAL=1
while [ "1" -eq "1" ] ; do
  echo $VAL >> watchme
  VAL=`expr $VAL + 1`
  sleep 1
done

And I'm trying to see Vim update 'watchme' about once a second.  My
'updatetime' is set to 500ms for CursorHold.

Here is the function that I've created to watch it, and incorporated your
'checktime' tip:

function PreviewFile(file)
  let l:file = expand(a:file)

  if !filereadable(l:file)
    echohl ErrorMsg | echo "Cannot open file for preview: " . l:file |
echohl None
    return
  endif

  " if the buffer is already open, kill it
  if bufexists(bufnr(l:file))
    execute ':' . bufnr(l:file) . 'bwipeout'
  endif

  " set up the new window with minimal functionality
  silent execute "10new " . l:file
  let g:preview_win = bufnr(l:file)
  setlocal noswapfile
  setlocal noshowcmd
  setlocal bufhidden=delete
  setlocal nobuflisted
  setlocal nomodifiable
  setlocal nowrap
  setlocal nonumber
  setlocal autoread

  " set it up to be watched closely
  execute "autocmd CursorHold " . l:file . " :checktime"
  execute "autocmd FileChangedShell " . l:file . " :echo \"changed\""
endfunction





-----Original Message-----
From: David Fishburn [mailto:[hidden email]]
Sent: Friday, 30 September, 2005 15:10
To: 'jason heddings'; [hidden email]
Subject: RE: Display File Contents Realtime

 

> -----Original Message-----
> From: jason heddings [mailto:[hidden email]]
> Sent: Friday, September 30, 2005 4:38 PM
> To: [hidden email]
> Subject: Display File Contents Realtime
>
> Hello-
>
> Is it possible to display a file contents in real time?  I
> have been trying to get the contents of a file to be
> displayed in the preview window.  I can manually re-edit this
> file, but I would like for it to automatically load the file
> when it changes.  I have tried autoread, but that does not
> seem to be working.

Have a look at my Tip:

" Tip #616: Have Vim check automatically if the file has changed externally
" http://www.vim.org/tips/tip.php?tip_id=616
" If you are using a console version of Vim, or dealing
" with a file that changes externally (ie a web server log)
" then Vim does not always check to see if the file has been changed.
" The GUI version of Vim will check more often (for example on Focus
change),
" and prompt you if you want to reload the file.

HTH,
Dave



Reply | Threaded
Open this post in threaded view
|

Re: Display File Contents Realtime

A.J.Mechelynck
jason heddings wrote:
> Thanks Dave-
>
> It doesn't seem to be catching updates unless I remove then restore focus
> from Vim.
>
> I've got a build going in the background, and I'm trying to watch the
> results as they are being captured to a file.  So, I don't think that the
> timestamp is updated on each write to the file.
> [...]

If I were you, I wouldn't use Vim to do that. On Unix (or cygwin) the
"tail" program with the --follow (or -f) option will do exactly what you
want. So while your build is running, or shortly before, start "tail
--follow=name --retry make.log" (or similar), if necessary in another
xterm, and it will display the log as it is being written.

Best regards,
Tony.