0

If a_session is created via :mksession, when reopening that session via vim -S a_session, Vim doesn't take into account that file permissions of some of the opened files might have changed in the meanwhile.

Here are the repro steps.

  1. Open a_file which is not readonly, and make sure that's the case by verifying :echo &readonly gives 0;
  2. save the session, :mksession;
  3. close Vim, :q;
  4. in the terminal, make the file readonly chmod -w a_file;
  5. reopen Vim via vim -S Session.vim;
  6. verify that :echo &readonly still returns 0, which I find strange
  7. run :e
  8. verify that :echo &readonly returns 1 now.

Is what happens at step 6 by design?

1 Answer 1

3

Session is simply a VimScript file. You can read through it and see what is going on.

What it does, it re-creates buffer(s) and after that it attempts to restore all previously saved options. By doing so it may overwrite any automatic settings such as &readonly that were set while the new buffer was being loaded.

IMO, saving options into session script should be avoided.

Refer to :h 'sessionoptions' to do adjustments.

4

Your Answer

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

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