简体   繁体   中英

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. I don't like this very much and want to change it to vim.

I already tried: Add export EDITOR=/usr/local/bin/vim in /etc/profile .
But shell told me "export: Command not found". I thought the reason is export is built-in function only in bash . And I don't want to change my shell.

Add EDITOR=/usr/lcoal/bin/vim in default block of /etc/login.conf
Add setenv EDITOR vim in /root/.cshrc , /.cshrc , ~/.cshrc

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.

I personally have an /etc/sudoers.d/local file, something like

# 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. 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 :

setenv EDITOR  vim

or to set it globally to all users using shell tcsh/csh add it in /etc/csh.cshrc

From the man :

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:

pkg install vim-console 

setting the EDITOR or VISUAL environment variable is the key. 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

There is an empty file called .selected_editor in $HOME (/root). Remove it and the next call to vipw will ask you to select the editor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM