Vi - The common Unix text editor

mail

How to encrypt text files with Vim ?

Prior to everything, you have to : apt install vim

Create a new encrypted text file / encrypt a clear text file :

  1. vim -x myFile
  2. Enter encryption key: (taptaptap + )
  3. Enter same key again: (taptaptap + again)
  4. Edit the file as you like
  5. Save and exit : :wq
    "myFile" [crypted] 2L, 9C written
    The :x shortcut command for "save and exit" doesn't seem to work very well when transcoding between cleartext / encrypted formats. Mind the confirmation message after saving.
  6. check :
    • cat myFile
      VimCrypt~01!���
    • file myFile
      myFile: Vim encrypted file data
    It's encrypted !

Edit an encrypted text file :

  1. vim myFile
  2. Need encryption key for "myFile"
    Enter encryption key: (taptaptap + )
  3. Edit the file as you like
  4. Save and exit : :wq or :x
    "myFile" [crypted] 3L, 24C written
    :x works fine here ()
  5. check (same commands) : it's still encrypted !

Remove encryption, i.e. turn an encrypted text file into a clear text file :

  1. vim myFile
  2. Need encryption key for "myFile"
    Enter encryption key: (taptaptap + )
  3. :set key=
  4. Save and exit : :wq :
    "myFile" 3L, 24C written		Doesn't mention "crypted" anymore
    :x saves without removing encryption

Change the password of an encrypted file :

  1. open the file : vim myFile
  2. 2 methods :
    • :X
      Enter encryption key: (taptaptap + )
      Enter same key again: (taptaptap +  again)
    • OR : set key=newPassword
  3. Then edit / save / exit as usual

Change the encryption method :

  1. open the file : vim myFile
  2. list available cryptmethods : :help 'cm' (blowfish2 is the recommended method)
  3. leave the help window : :q
  4. set the new encryption method : :setlocal cm=blowfish2
  5. Save and exit : :wq :x doesn't work here.
    "myFile" [blowfish2] 3L, 24C written
mail

vi/vim

Mode Enter by pressing : Leave by pressing :
Command or Normal (at vi startup)
Input [INSERT] or i [ESC] (leave to Command mode)
Replace r [ESC] (leave to Command mode)

Must-know commands :

Edition commands :

Movement commands :

Search commands (similar to less search commands) :

Search + replace old with new (similar to sed commands) :

Miscellaneous commands :