You are not logged in.
Pages: 1
Topic closed
Vim was not longer being recognized by the command 'vi', so I had to add to my .bashrc (and root's one also) the line
alias vi='vim'
The problem is that I now want to use sudo autentication. I think I did everything right and sudo is working, but I lost my alias. If I use normal user or root, it's there. Let me try to clear it up with examples:
---
as normal user:
vi /etc/rc.conf
Vim opens correctly.
---
as root:
vi /etc/rc.conf
Vim opens correctly.
---
as normal user:
sudo vi /etc/rc.conf
Vi opens instead.
---
An observation: I realized that Vi was opening instead because of the syntax highlighting colors and the lack of bold fonts. That is, when i used the command 'sudo vim /etc/rc.conf' it was displayed correctly.
Any guesses?
Offline
As I understand it sudo runs commands with root privileges but does not actually log in as root so roots .bashrc will not be read when running a command.
---for there is nothing either good or bad, but only thinking makes it so....
Hamlet, W Shakespeare
Offline
As I understand it sudo runs commands with root privileges but does not actually log in as root so roots .bashrc will not be read when running a command.
No, but I thought it used the user settings.
pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))
Offline
If you run sudo -V as root it shows the environment variables. running on my comp it shows bash as one of the environment variables to be removed. I think that these variables can be set in the sudoers file.
---for there is nothing either good or bad, but only thinking makes it so....
Hamlet, W Shakespeare
Offline
I think that these variables can be set in the sudoers file.
Didn't find how to do it in '/etc/sudoers'. I googling to find an answer. If anybody has it, I'd be thankfull.
Offline
With `visudo`, try adding this line:
Defaults !env_reset
Offline
Alias expansion (translating "vi" into "vim", in this case) is done by the shell before the command is executed. Bash only does alias expansion on the first word in a command line, so it doesn't touch "vi", the second word. I suggest either setting "sudoedit" to "vim" in your sudoers file and using "sudo -e", or just getting used to typing "vim".
Offline
Alias expansion (translating "vi" into "vim", in this case) is done by the shell before the command is executed. Bash only does alias expansion on the first word in a command line, so it doesn't touch "vi", the second word. I suggest either setting "sudoedit" to "vim" in your sudoers file and using "sudo -e", or just getting used to typing "vim".
That makes sense. I'm not lazy to type 'vim', it was just a matter of curiosity. Thanks to everyone for the help.
Offline
You could always remove and link it to vim. ... How bad could it be?
Offline
I somehow felt I've read somewhere, at some time that you have to add a alias for sudo as well to use aliases for the second command.
Try adding alias sudo="sudo" as well. I neither have tested this nor put real hope in this to work. But it might be a try.
Last edited by harlekin (2007-08-30 04:57:40)
Hail to the thief!
Offline
I somehow felt I've read somewhere, at some time that you have to add a alias for sudo as well to use aliases for the second command.
Try adding alias sudo="sudo" as well. I neither have tested this nor put real hope in this to work. But it might be a try.
That unfortunately doesn't work:
$ alias a="echo This is the first"; alias b=" and this is the last."
$ a b
This is the first b
$
Offline
I'm not sure if I'm missing something but ... I use vim in both user and root mode.
I have .vimrc in my ~/userid directory and a .vimrc in the /root home directory.
When I do
su -c 'vim /etc/rc.conf'
for example I get vim with root's settings and when I issue vim xyz I get it with my user settings.
Hope this helps.
R
Offline
Hi all, I tried the method mentioned by harlekin and it works. The website that I googled describing this is:
http://www.shellperson.net/using-sudo-with-an-alias/
Just make sure you have the space in "sudo ". The space is very critical.
so put this line in your .bashrc file.
alias sudo="sudo "
This way, if the second argument is an aliases, it will get expanded prior to passing to sudo. Very clever trick I think :0)
Also, there is another way to do the 'sudo vi' command. You can just 'vi filename' as a normal user. Then in the vim editor, do ":w !sudo tee %". This will write the file as root. You can do this if you forgot to 'sudo vi'ed the file and instead just 'vi'ed the file. Vim will prompt you to reload the file as the file is written/changed outside of vim.
Hope this helps. :0)
cheers!
I somehow felt I've read somewhere, at some time that you have to add a alias for sudo as well to use aliases for the second command.
Try adding alias sudo="sudo" as well. I neither have tested this nor put real hope in this to work. But it might be a try.
Last edited by TheFunnyOne (2011-09-12 14:04:10)
Offline
Hello TheFunnyOne, welcome to Arch Linux. Necro bumping is usually not allowed on the forums. Please read and make yourself familiar with the forum rules. Thanks.
Closing.
aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies
Offline
Pages: 1
Topic closed