Tuesday, February 26, 2013

Re: How to refresh (reload) an opened file?

On 2013-02-26 10:53, Andy Richer wrote:
> I opened a report file that is changed once I correct some code and
> re-generate report.
> Is there a way that I can do "refresh" or "reload" without quit the
> re-open the file to see updated contents?

Depends on what behavior you want, and whether you want to preserve
any changes you made in the first version of the output. To re-read
the file from disk, you can use

:e

(note: no filename) If you've made changes in the current buffer,
you can abandon those with

:e!

If you want to keep the current version in Vim and read the existing
file into another buffer, you can do that either by preserving what
you have into another scratch buffer and re-reading as above:

:%y " yank the old contents
:new " create a new buffer
:put " dump the old contents into this buffer
:1d " delete the initial blank line
:e! " reread the updated file

Or, you can leave the current buffer pointed at the file and read the
new file into a new buffer:

:new " create a new empty buffer
:r filename.txt " read in the contents from disk
:1d " delete the initial blank line

If you want to compare the old-version with the new version, I
recommend the "yank, new, put, e!" version, possibly followed by a
":diffthis" in each buffer.

-tim



--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment