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.
    – klaus
    May 1 '19 at 12:24
  • @klaus Add this as an answer, I will accept it.
    – In78
    May 5 '19 at 0:18
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 '19 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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