如何指定编辑器来打开 crontab 文件?“export EDITOR=vi”不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5952467/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to specify a editor to open crontab file? "export EDITOR=vi" does not work
提问by antonjs
I'm using Red Hat Enterprise Linux 5, and I want to set the vim editor to edit the crontab file.
我使用的是 Red Hat Enterprise Linux 5,我想设置 vim 编辑器来编辑 crontab 文件。
If I run echo $EDITOR
, I get vim. But when I run crontab -e
, I get different editor.
如果我运行echo $EDITOR
,我会得到 vim。但是当我运行时 crontab -e
,我得到了不同的编辑器。
采纳答案by bmk
Very probable that your VISUAL
environment variable is set to something else. Try:
很可能您的VISUAL
环境变量设置为其他内容。尝试:
export VISUAL=vi
回答by Alex Howansky
I think you might need to use the full path:
我认为您可能需要使用完整路径:
export EDITOR=/usr/bin/vim
回答by 9000
To quote the man:
引用这个人的话:
The -e option is used to edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables
-e 选项用于使用 VISUAL 或 EDITOR 环境变量指定的编辑器编辑当前的 crontab
Most often if you run crontab -e
from X, you have VISUAL
set; that's what is used. Try this:
大多数情况下,如果你crontab -e
从 X运行,你已经VISUAL
设置了;这就是使用的。尝试这个:
VISUAL=vi crontab -e
VISUAL=vi crontab -e
It just worked for me :)
它只对我有用:)
回答by L. D. James
If the above methods don't work (as they didn't work on my Ubuntu 13.04 installation) try:
如果上述方法不起作用(因为它们在我的 Ubuntu 13.04 安装中不起作用),请尝试:
There are a number of alternative ways:
有多种替代方法:
1) Run select-editor
1)运行选择编辑器
select-editor
2) Manually edit the file: ~/.selected_editor
specifying your preferred editor. With this option you can specify editor parameters.
2) 手动编辑文件:~/.selected_editor
指定您的首选编辑器。使用此选项,您可以指定编辑器参数。
# Generated by /usr/bin/select-editor
SELECTED_EDITOR="/usr/bin/emacs -nw"
3) You can specify on the fly on the commandline with:
3)您可以在命令行上使用以下命令即时指定:
env VISUAL="emacs -nw" crontab -e
回答by felwithe
It wasn't working for me. I run crontab with sudo, so I switched to root, did the above suggestions, and crontab would open in vim, but it still wouldn't from my user account. Finally I ran sudo select-editor
from the user account and that did the trick.
它对我不起作用。我用 sudo 运行 crontab,所以我切换到 root,做了上面的建议,crontab 会在 vim 中打开,但它仍然不会从我的用户帐户中打开。最后,我sudo select-editor
从用户帐户运行,并且成功了。
回答by Chema
export EDITOR=vim
worked for me
export EDITOR=vim
为我工作
回答by Parveen Shukhala
You can use below command to open it in VIM editor.
您可以使用以下命令在 VIM 编辑器中打开它。
export VISUAL=vim; crontab -e
Note: Please make sure VIM editor is installed on your server.
注意:请确保您的服务器上安装了 VIM 编辑器。
回答by Walk
This worked for me :
这对我有用:
EDITOR="/usr/bin/vim"
export EDITOR
Add this to ~/.bash_profile or ~/.bashrc to enable this for current user.
将此添加到 ~/.bash_profile 或 ~/.bashrc 以为当前用户启用此功能。