[英]how do I change default editor for sudo vipw from "vi" to "vim" by tcsh in FreeBSD
When I use command sudo vipw
to edit my password file, It's always use vi as editor.当我使用命令
sudo vipw
编辑我的密码文件时,它总是使用 vi 作为编辑器。 I don't like this very much and want to change it to vim.我不太喜欢这个,想把它改成vim。
I already tried: Add export EDITOR=/usr/local/bin/vim
in /etc/profile
.我已经尝试过:在
/etc/profile
添加export EDITOR=/usr/local/bin/vim
。
But shell told me "export: Command not found".但是外壳告诉我“导出:找不到命令”。 I thought the reason is export is built-in function only in
bash
.我认为原因是 export 是仅在
bash
中的内置功能。 And I don't want to change my shell.而且我不想改变我的外壳。
Add EDITOR=/usr/lcoal/bin/vim
in default block of /etc/login.conf
在
/etc/login.conf
的默认块中添加EDITOR=/usr/lcoal/bin/vim
Add setenv EDITOR vim
in /root/.cshrc
, /.cshrc
, ~/.cshrc
在
/root/.cshrc
, /.cshrc
, ~/.cshrc
添加setenv EDITOR vim
All above didn't work at all.以上所有都不起作用。 I have google for hours but could not find anything help.
我有几个小时谷歌,但找不到任何帮助。
Your /etc/sudoers file doesn't keep your EDITOR environment variable. 您的/ etc / sudoers文件没有保留EDITOR环境变量。
I personally have an /etc/sudoers.d/local file, something like 我个人有一个/etc/sudoers.d/local文件,类似
# We don't need to worry about wheel users breaking in to get root access because they already have it.
Defaults:%wheel env_keep+="HOME EDITOR",!set_home,shell_noargs
I'm not sure why this isn't the default, since wheel users have already been given full access. 我不确定为什么这不是默认设置,因为轮盘用户已经获得了完全访问权限。 But it's apparently prevailing wisdom to continue hassling them.
但是,继续困扰他们显然是普遍的智慧。
Note: If you're using an older /etc/sudoers file that doesn't support an /etc/sudoers.d directory, these lines can be dropped in there... or you could add #includedir /etc/sudoers.d
as the last line of your /etc/sudoers file to enable an /etc/sudoers.d directory. 注意:如果您使用的旧的/ etc / sudoers文件不支持/etc/sudoers.d目录,则可以将这些行放在其中...或者您可以添加
#includedir /etc/sudoers.d
作为/ etc / sudoers文件的最后一行,以启用/etc/sudoers.d目录。 Um, yes, the #
is a required part of that line, because someone thought it was important for that directive to look like a comment. 嗯,是的,
#
是该行的必需部分,因为有人认为该指令看起来像注释很重要。
Try adding this to the root
user /root/.chsrc
: 尝试将其添加到
root
用户/root/.chsrc
:
setenv EDITOR vim
or to set it globally to all users using shell tcsh/csh
add it in /etc/csh.cshrc
或使用shell
tcsh/csh
将其全局设置为所有用户使用,请将其添加到/etc/csh.cshrc
A login shell begins by executing commands from the system files /etc/csh.cshrc
and /etc/csh.login. It then executes commands from files in the user's home directory:
first ~/.tcshrc or, if ~/.tcshrc is not found, ~/.cshrc ...
Non-login shells read only /etc/csh.cshrc and ~/.tcshrc or ~/.cshrc on startup.
Also verify vim is installed since is not by default, you could try: 还要验证vim是否已安装,因为默认情况下未安装,您可以尝试:
pkg install vim-console
setting the EDITOR or VISUAL environment variable is the key.设置 EDITOR 或 VISUAL 环境变量是关键。 if you don't want to go to the trouble of modifying config files (which is indeed the long term solution) then you could
sudo su -
to get to the root prompt and then you could export EDITOR=/usr/bin/vim
before running vipw
如果您不想麻烦修改配置文件(这确实是长期解决方案),那么您可以
sudo su -
进入根提示符,然后您可以在之前export EDITOR=/usr/bin/vim
运行vipw
There is an empty file called .selected_editor
in $HOME (/root). $HOME (/root) 中有一个名为
.selected_editor
的空文件。 Remove it and the next call to vipw will ask you to select the editor.删除它,下次调用 vipw 将要求您选择编辑器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.