0

I want to view the initial copy of the file in a separate window while I make changes to the same file in another window. Is this possible?

2
  • 1
    If you're using git, then you could use vim-fugitive to have latest commit and changes side by side. Otherwise, you'd need to keep the original file as backup and open that backup. Because Vim doesn't have a different view on files, the windows are viewports to the files on disk and nothing more. If you want two windows to have different texts inside them then they must refer to different files.
    – 3N4N
    May 1, 2019 at 12:24
  • @klaus Add this as an answer, I will accept it.
    – In78
    May 5, 2019 at 0:18

1 Answer 1

2

As a workaround what you could do is:

:vnew | execute("0read " . @#)
  • vnew creates a new buffer in a vertical split
  • execute runs a string as an ex command
  • @# contains the file name of the alternate-file
    • read more at :help alternate-file
  • 0read reads from a file into the first line of a file

Edit:

If you're not making a custom command from this you can do

:vnew | 0read <C-r><C-#>

Both of these require the file to be saved

1
  • Note that there has an extra blank line in the end of new buffer.
    – dedowsdi
    May 1, 2019 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.