0

I got two files named as vim1 and vim2. vim1 files has some text in it, but vim2 is totaly empty. I used vim vim1 command to open that file. Later on i write :vsplit vim2 to open vim2 file on splited side. I changed my beam to vim2 screen with Ctrl+w command. Later i write this :e vim1 at vim2's split. And i write :wq at this split. After i close the both splits, i checked vim2 file and it was totaly empty. How did this happen?

  • Hard to follow. Why would it not be empty? Do you write anything to it? – pfnuesel Mar 6 '18 at 17:40
  • :e vim1 does not write while on vim2's split? – Alp Mar 6 '18 at 17:43
1

Let us look through your sequence of events, with slightly more clear filenames:

  • Open file1 with vim.
  • (presumably, make edits to file1)
  • Open file2 as a vertical split with :vsp file2 This puts the cursor into file2's new split.
  • Move cursor with Ctrl-W to file1's split.
  • Move the cursor with unspecified means back to file2's split.
  • Execute the command :e file1, which changes the active buffer in what was file2's split to also be used to display and edit file1
  • Execute :wq to save and quit file1, in the split which had originally been used for file2.

At no time was file2 written to in this chain of events, which is why the file is empty (if it even exists).

Note that at the end of this chain of events, the state of vim will be file2, as the only remaining open buffer (in what had been the split which was used for file1, which was just closed), open in an unsplit interface, as yet unsaved.

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.