Why doesn’t vim ask for password when reopenning an encrypted file

vim

If I run Vim and then open an encrypted file it asks for the encryption password. If I close the window where the file was opened (without closing vim) and then reopen the file, the password prompt is not shown anymore. Is there any setting to modify this behavior? I'd like vim to ask the password every time the file is opened regardless if it's the same Vim "session".

Best Answer

According to the vim documentation, :q closes the current window and only quits if there are no windows left. In vim, windows are merely "viewports" where buffers can be displayed. The vim documentation itself sums this up quite nicely. From :help window:

A buffer is the in-memory text of a file.
A window is a viewport on a buffer.
A tab page is a collection of windows.

If you have the hidden option set, closing a window hides the buffer but does not "abandon" it, so vim is still keeping track of the contents. With 'hidden' set, when you "reopen" the file, you are simply re-showing/un-hiding the buffer, not actually re-opening the file on disk.

For more information take a look at

:help hidden
:help abandon
Related Question