博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vim macos_如何在Linux(或macOS)上使用Vim密码保护文本文件
阅读量:2507 次
发布时间:2019-05-11

本文共 8564 字,大约阅读时间需要 28 分钟。

vim macos

vim macos

The vim text editor, a standard tool included on Linux and macOS, can quickly encrypt text files with a password. It’s faster and more convenient than encrypting a text file with a separate utility. Here’s how to set it up.

vim文本编辑器是Linux和macOS附带的标准工具,可以使用密码快速加密文本文件。 与使用单独的实用程序加密文本文件相比,它更快,更方便。 设置方法如下。

确保系统的Vim具有加密支持 (Make Sure Your System’s Vim Has Encryption Support)

Some Linux distributions, including Ubuntu, include a minimal version of vim by default, intended only for basic text editing. For example, Ubuntu calls this package “vim-tiny”. If you try to use encryption in such a minimal version of vim, you’ll see a “Sorry, this command isn’t available in this version” message.

某些Linux发行版(包括Ubuntu)默认包含最低版本的vim,仅用于基本文本编辑。 例如,Ubuntu将此软件包称为“ vim-tiny”。 如果您尝试在vim的最低版本中使用加密,则会看到“抱歉,此命令在此版本中不可用”消息。

You may need to install the full version of vim to get this feature on your Linux distribution. For example, on Ubuntu, you can get the full version of vim that by running the following command:

您可能需要安装完整版的vim才能在Linux发行版上获得此功能。 例如,在Ubuntu上,您可以通过运行以下命令来获取vim的完整版本:

sudo apt install vim

The version of vim included by default with macOS does include encryption support, so you don’t need to install anything else on a Mac. Just launch a terminal window from Finder > Applications > Utilities > Terminal and the commands will work the same on macOS as they do on Linux.

macOS默认包含的vim版本确实包含加密支持,因此您不需要在Mac上安装其他任何东西。 只需从Finder>应用程序>实用程序>终端启动终端窗口,这些命令在macOS上的工作原理与在Linux上相同。

如何使用密码加密文件 (How to Encrypt a File With a Password)

The basic process is relatively simple if you know . If you don’t, you might get hung up on vi’s modal interface. When you open a text file in vim, there are two modes. By default, you’re in a “command mode” where you can use the keys on your keyboard to perform commands. You can also press “i” to enter “Insert mode”, where you can type normally and move the cursor around with the arrow keys, as you would in other text editors. To leave insert mode, press “Esc” and you’ll be back to command mode.

如果您知道则基本过程相对简单。 否则,您可能会挂在vi的模式界面上。 在vim中打开文本文件时,有两种模式。 默认情况下,您处于“命令模式”,可以使用键盘上的键执行命令。 您也可以按“ i”进入“插入模式”,您可以像在其他文本编辑器中一样正常键入并使用箭头键来移动光标。 要退出插入模式,请按“ Esc”,然后返回命令模式。

First, launch vim. For example, the following command will launch vim and point it at a file named “example” in the current directory. If that file doesn’t exist, vim will create a file named “example” in the current directory when you save it:

首先,启动vim。 例如,以下命令将启动vim并将其指向当前目录中名为“ example”的文件。 如果该文件不存在,则在保存时,vim将在当前目录中创建一个名为“ example”的文件:

vi example

You can also point vi at another path with a command like the below one. You don’t have to create a file in the current directory.

您也可以使用以下命令将vi指向另一条路径。 您不必在当前目录中创建文件。

vi /path/to/file

Edit the file normally. For example, you can press “i” to enter insert mode and then type text normally. While editing a file, press Esc to ensure you’re in command mode and not insert mode. Type :X and press Enter.

正常编辑文件。 例如,您可以按“ i”进入插入模式,然后正常键入文本。 编辑文件时,按Esc键以确保您处于命令模式而不是插入模式。 输入:X并按Enter。

You’ll be prompted to enter a password, which the text file will be encrypted with. Type the password you want to use, press Enter, and type it again to confirm. You’ll need to enter this password any time you want to open the file in the future.

系统将提示您输入密码,该密码将用于加密文本文件。 输入您要使用的密码,按Enter,然后再次输入以确认。 您以后想在任何时候打开文件时都需要输入此密码。

Vim will warn that you’re using a weak encryption method by default. We’ll show you how to use a more secure encryption method later.

Vim会警告您默认使用弱加密方法。 稍后,我们将向您展示如何使用更安全的加密方法。

A password will be associated with the current text file in Vim, but you’ll need to save your changes before the password is actually assigned to the file. To do this, press Esc to ensure you’re in command mode, and then type :wq and press Enter to write the file to disk and quit Vim.

密码将与Vim中的当前文本文件相关联,但是您需要先保存更改,然后才能将密码实际分配给该文件。 为此,请按Esc以确保您处于命令模式,然后键入:wq并按Enter将文件写入磁盘并退出Vim。

The next time you attempt to open the file in Vim—for example, by running “vi example“—Vim will ask you for the password associated with the file.

下次尝试在Vim中打开文件时(例如,通过运行“ vi example ”),Vim将询问您与文件关联的密码。

If you enter the wrong password, the contents of the file will be gibberish.

如果输入了错误的密码,文件的内容将是乱码。

Warning: Don’t save the file if you open it and see gibberish. This will save the corrupted data back to the file and overwrite your encrypted data. Just run :q to quit Vim without saving the file to disk.

警告 :如果打开文件并看到乱码,请不要保存。 这会将损坏的数据保存回文件,并覆盖加密的数据。 只需运行:q即可退出Vim而不将文件保存到磁盘。

There’s one other shortcut you can use here. Rather than creating or opening a file with “vim /path/to/file“, you can run the following command to have vim create or open a file and make it immediately prompt you to encrypt the file with a password:

您还可以在这里使用另一个快捷方式。 您可以运行以下命令来使vim创建或打开文件,并使其立即提示您使用密码加密文件,而不是使用“ vim /path/to/file ”创建或打开文件:

vi -x /path/to/file

Note that you need to use a lower-case x here, while you need to use an upper-case X when running the associated encryption command from inside Vim.

请注意,从Vim内部运行关联的加密命令时,需要在此处使用小写的x,而在使用X时需要使用大写的X。

如何在Vim中启用更强的加密 (How to Enable Stronger Encryption in Vim)

By default, Vim uses very bad encryption for these files. The default “zip” or “pkzip’ encryption method is backwards compatible with versions 7.2 and below of vim. Unfortunately, it can be cracked very, very easily—even on hardware from the 90’s. As the puts it: “The algorithm used for ‘cryptmethod’ “zip” is breakable. A 4 character key in about one hour, a 6 character key in one day (on a Pentium 133 PC).”

默认情况下,Vim对这些文件使用非常差的加密。 默认的“ zip”或“ pkzip”加密方法向后兼容vim的7.2及更低版本。 不幸的是,它甚至可以在90年代的硬件上非常非常容易地破解。 正如所说:“用于'cryptmethod''zip'的算法是易破解的。 在一个小时内用一个4个字符的密钥,一天(在Pentium 133 PC上)用一个6个字符的密钥。”

You should not use pkzip encryption for your text documents if you want any security at all. However, Vim provides better encryption methods. Version 7.3 of Vim released in  added a “blowfish” encryption method, which is better. Version 7.4.399 released in included a new Blowfish encryption method that fixes security problems in the original “blowfish” encryption method, and dubs it “blowfish2”.

如果您完全想要任何安全性,则不应对文本文档使用pkzip加密。 但是,Vim提供了更好的加密方法。 发布的7.3版Vim添加了一种“河豚”加密方法,效果更好。 发布的7.4.399版包含一种新的Blowfish加密方法,该方法解决了原始“ blowfish”加密方法中的安全问题,并将其称为“ blowfish2”。

The only problem is that files you create with stronger encryption methods require these newer versions of Vim. So, if you want to use “blowfish2” encryption, you’ll only be able to open that file with Vim versions 7.4.399 and above. As long as you’re fine with that, you should use the strongest encryption method possible.

唯一的问题是,使用更强的加密方法创建的文件需要这些新版本的Vim。 因此,如果要使用“ blowfish2”加密,则只能使用Vim 7.4.399及更高版本打开该文件。 只要您满意,就应该使用最强的加密方法。

To check which encryption method a file is using, open the file in vim, press the Esc key to ensure you’re in command mode, type the following command, and press Enter.

要检查文件正在使用哪种加密方法,请在vim中打开文件,按Esc键以确保您处于命令模式,键入以下命令,然后按Enter。

:setlocal cm?

The “cm” here stands for “cryptmethod”.

此处的“ cm”代表“加密方法”。

You’ll see the encryption method used for the current file displayed at the bottom of the vim screen.

您会在vim屏幕的底部看到用于当前文件的加密方法。

To choose an encryption method, run one of the following commands. The “blowfish2” encryption is best for security.

要选择一种加密方法,请运行以下命令之一。 “ blowfish2”加密最适合安全。

:setlocal cm=blowfish2:setlocal cm=blowfish:setlocal cm=zip

Once you’ve selected your encryption algorithm, use the :w command to write the file to disk or the :wq command to write the file to disk and quit.

选择了加密算法后,请使用:w命令将文件写入磁盘或:wq命令将文件写入磁盘并退出。

The next time you re-open the file in Vim, it won’t complain about a weak encryption algorithm. You’ll also see the encryption algorithm you selected at the bottom of the vim screen when you open the file.

下次在Vim中重新打开该文件时,它不会抱怨加密算法较弱。 打开文件时,您还会在vim屏幕的底部看到选择的加密算法。

如何更改或删除密码 (How to Change or Remove a Password)

To remove a password from a file, open that file in Vim and run the :X command. You’ll be prompted to provide a new encryption key. Enter the new password you want to use here. To remove the password completely, leave the password field blank and just press Enter twice.

要从文件中删除密码,请在Vim中打开该文件并运行:X命令。 系统将提示您提供一个新的加密密钥。 在此处输入您要使用的新密码。 要完全删除密码,请将密码字段留空,然后按两次Enter键。

Save the file and quit afterwards with :wq . The file will be decrypted, so you won’t be prompted to enter a password when you open the file in the future.

保存文件,然后使用:wq退出。 该文件将被解密,因此以后打开该文件时不会提示您输入密码。

Be sure to remember whatever password you set or you won’t be able to access the contents of the file in the future.

请务必记住您设置的任何密码,否则以后将无法访问该文件的内容。

翻译自:

vim macos

转载地址:http://xwuwd.baihongyu.com/

你可能感兴趣的文章
mysql数据库存放路径
查看>>
TestNG(五)常用元素的操作
查看>>
解决 Visual Studio 点击添加引用无反应的问题
查看>>
通过镜像下载Android系统源码
查看>>
python字符串格式化 %操作符 {}操作符---总结
查看>>
windows 不能在 本地计算机 启动 Apache
查看>>
iOS开发报duplicate symbols for architecture x86_64错误的问题
查看>>
Chap-6 6.4.2 堆和栈
查看>>
【Java学习笔记之九】java二维数组及其多维数组的内存应用拓展延伸
查看>>
C# MySql 连接
查看>>
网络抓包分析方法大全
查看>>
sql 数据类型
查看>>
android 截图
查看>>
WebServicer接口类生成方法。
查看>>
POJ 1740
查看>>
【翻译】火影忍者鸣人 疾风传 终级风暴2 制作介绍
查看>>
http和webservice
查看>>
hdu1879------------prim算法模板
查看>>
jdbc之二:DAO模式
查看>>
MySQL性能优化方法一:缓存参数优化
查看>>