vim -x filename
And vim will automatically encrypt your file upon saving it. I’m still not sure how it treats the .swp file it creates upon editing a file.
If you forgot the -x switch, you can still encrypt your file by typing
:X (colon and capital x)