This article assumes…
you know the basics of Vim, including how to switch between command mode and insert mode,
you know how to create and edit a vimrc file,
and you are using Vim v7.4.399 or newer.
In this article, Vim
Note that the commands described in this section are run from within Vim.
If Vim is built with the
cryptv feature, you can
use it to create, view, and edit an encrypted file.
To see if your version of Vim supports this, run:
If your version of Vim supports encryption, the following will be displayed in the list of features.
To learn what types of encryption are supported by your version of Vim, run:
This will list some or all of the following encryption methods.
zip blowfish blowfish2 xchacha20
In 2021-October, blowfish2 is recommended and is the default. To display your Vim’s current default cryptmethod, run either of the following equivalent commands.
:set cryptmethod? :set cm? ^ Note the question mark
If you are using Vim v8.1.0606 or newer, this should display:
If it does not display this, do one of the following.
is needed to use
To encrypt a file with Vim:
Open the file in Vim.
In command mode, run
:X (note that
X must be upper case).
Enter encryption key: prompt, type a password.
Enter same key again: prompt, retype the password.
Save the file.
To decrypt, edit, and re-encrypt a file with Vim:
Attempt to open the file in Vim.
Enter encryption key: prompt, type the file’s password.
If you mistyped the file’s password…
Close the file without saving it. For example by using Esc:q
If you correctly typed the file’s password…
Edit the file.
Save the file.
If a Vim-encrypted file has been renamed and/or is on another device, it can be decrypted by any version of Vim that supports the used encryption method (e.g. blowfish2). This means that you can, for example, keep a copy of your encrypted-secrets file on a USB drive and open the file on any device with any Vim (v7.4.399+).
For more about Vim, see Infinite Ink’s…
blowfish2is available as a
cryptmethod. Vim v7.4.399 was released 2014-August-10 (more than 6 years ago).
blowfish2. Vim v8.1.0606 was released 2018-December-16 (more than 2 years ago).
:terminalcommand, which launches an integrated terminal emulator. The
:terminalcommand, which is equivalent to
:term, was introduced in Vim v8.1.
Your public comment or question might immediately improve this page or help me to (eventually) improve this page.