Password protect a VIM file

You can password protect a file using VIM – it’s built right in. To do this either edit a current file or create a new file e.g. testdata.txt and press :X

Enter a password and confirm it, now save the file with a :w and finally quit the file. When you reopen the file you will need to enter the password in order to view the contents.

 

 

If the password is entered incorrectly, you can’t read the contents:

 

 

You can also create a file with encryption turned on by including the -x switch e.g.

 vim -x test2.txt 

man vim for more details.

 

Bookmark the permalink.