Let's say I have three files in the same folder,
c.txt, all of them encrypted (with Vim) with the same password ("asdf" for example). Is there a way to open the three of them entering the password only once?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
The encryption password used by Vim for encrypting and decrypting files is stored in the
key variable, see
:help encryption. This variable is normally local to a Vim buffer, so Vim uses a unique password for each encrypted file that is opened or saved. Vim will prompt for a new password when a different encrypted file is opened for the first time.
To make the password global, enter
in Vim, where
asdf is the password. After explicitly giving the
key variable a value like this, Vim will use the same password for subsequent encrypted files that are opened with
:n in the same Vim instance.
key variable can be set on the Vim command line used to open the files with
vim --cmd "set key=asdf" a.txt b.txt c.txt
Beware: this records the password in the clear to your shell history file (for example
~/.bash_history) and to all other users on the system by simply looking at a list of running processes with
Other solutions for encrypting files transparently with Vim are possible, the Vim wiki offers this page of tips on encryption, including executing PGP or GnuPG automatically when opening and saving files based on the file extension.
Type in the key before opening the first file with this cmd:
vim -c ":let &key=inputsecret('key=')|:bdel dummy" dummy a.txt b.txt c.txt
Edit 1. To answer question in the comment below. If you want the files open together in tabs, like vim -p a.txt b.txt c.txt
vim -c ":let &key=inputsecret('key=')|:tab all|:bdel dummy" dummy a.txt b.txt c.txt
set viminfo= noswapfile bin cm=blowfish
Needs a dummy file
dummy, because the input dialog comes up only after the first file is loaded, even with --cmd. In this case, you have to type the key once.
*--cmd="set key=asfd"*; because process args can be seen with the ps command to others users, may get logged in syslog, and also saved in your bash_history.