Loading ...
Sorry, an error occurred while loading the content.

Display File Contents Realtime

Expand Messages
  • jason heddings
    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
    Message 1 of 4 , Sep 30, 2005
    View Source
    • 0 Attachment
      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
    • David Fishburn
      ... 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
      Message 2 of 4 , Sep 30, 2005
      View Source
      • 0 Attachment
        > -----Original Message-----
        > From: jason heddings [mailto:vim@...]
        > Sent: Friday, September 30, 2005 4:38 PM
        > To: vim@...
        > 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
      • jason heddings
        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
        Message 3 of 4 , Oct 1, 2005
        View Source
        • 0 Attachment
          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:fishburn@...]
          Sent: Friday, 30 September, 2005 15:10
          To: 'jason heddings'; vim@...
          Subject: RE: Display File Contents Realtime



          > -----Original Message-----
          > From: jason heddings [mailto:vim@...]
          > Sent: Friday, September 30, 2005 4:38 PM
          > To: vim@...
          > 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
        • A. J. Mechelynck
          ... 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
          Message 4 of 4 , Oct 2, 2005
          View Source
          • 0 Attachment
            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.
          Your message has been successfully submitted and would be delivered to recipients shortly.