更改默认的crontab编辑器

我正在尝试将默认编辑器从nano更改为vim

我运行了以下命令:

sudo update-alternatives --config editor

update-alternatives --config editor

两者现在输出:

  Selection Path Priority Status ------------------------------------------------------------ 0 /bin/nano 40 auto mode 1 /bin/ed -100 manual mode 2 /bin/nano 40 manual mode * 3 /usr/bin/vim.basic 30 manual mode 4 /usr/bin/vim.tiny 10 manual mode 

我重新启动了我的ssh会话并重新启动了sshd但是crontab -e仍然以nano打开

我还需要做什么?

尝试你的ssh会话,然后

 export EDITOR=vim 

或者可能

 export EDITOR=/usr/bin/vim.basic 

EDITOR变量的设置格式取决于您使用的shell。

在Ubuntu中,您可以通过将上面的内容添加到~/.profile来设置登录时的EDITOR环境变量

您的SSH会话将读取名为~/.ssh/environment的远程主机上的类似文件(如果存在)。 这必须由ssh守护程序配置专门定义。 有关更多详细信息,请参阅man sshd_config并查找PermitUserEnvironment

只需运行select-editor ,就可以选择任何你想要的编辑器。

我的个人偏好……

 cd /bin mv nano nano_must_die ln -s /usr/bin/vim nano 

来自“man crontab”:

  The -e option is used to edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables. After you exit from the editor, the modified crontab will be installed automati‐ cally. If neither of the environment variables is defined, then the default editor /usr/bin/editor is used. 

也许您将EDITOR enivronment变量设置为nano?

在我的Ubuntu 12.04计算机上, crontab使用~/.selected_editor文件,该文件包含所选编辑器的路径。 编辑它:

 nano ~/.selected_editor 

我直接编辑它或使用select-editor ,这是一个执行相同操作的脚本。 编辑以下行:

 SELECTED_EDITOR="/usr/bin/vim.basic" 

IHMO人员不应该在/ etc或/ bin中更改任何内容来执行此操作。 这是用户级别的事情,而不是系统范围的任务。

如果您只想暂时选择编辑器,则可以执行以下操作

 EDITOR=nano crontab -e 

这将为命令设置EDITOR环境变量

我在select-editorupdate-alternatives方案时遇到困难,我的解决方案是简单地编辑链接:

  1. sudo rm /etc/alternatives/editor
  2. sudo ln -s /usr/bin/vim /etc/alternatives/editor

editor现在打开Vim

我遇到了同样的问题–crontab -e依赖于select-editor,visudo依赖于“alternative”的配置

我的解决方案

以root身份运行这两个命令

 # update-alternatives --install /usr/bin/editor editor /usr/bin/sensible-editor 50 # select-editor Select an editor. To change later, run 'select-editor'. 1. /bin/nano <---- easiest 2. /usr/bin/sensible-editor 3. /usr/bin/vim.basic 4. /usr/bin/vim.tiny Choose 1-4 [1]: 3