You are not logged in.

#1 2015-04-02 06:33:31

natepad
Member
Registered: 2014-09-25
Posts: 14

[SOLVED] Sudo Ranger does not open files with VIM

I am using ranger as my file manager. And sometimes I run it with sudo. But then it want's to open all with nano. Even tough the environment variables (EDITOR & VISUAL) are set to vim.

Maybe it hast something to do with /bin/sh - but when that is the case, how do I change the default behaviour of /bin/sh?

Last edited by natepad (2015-04-02 16:07:36)

Offline

#2 2015-04-02 07:12:05

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] Sudo Ranger does not open files with VIM

Add a line to sudoers:

Defaults editor=/usr/bin/vim

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2015-04-02 07:25:16

natepad
Member
Registered: 2014-09-25
Posts: 14

Re: [SOLVED] Sudo Ranger does not open files with VIM

jasonwryan wrote:

Add a line to sudoers:

Defaults editor=/usr/bin/vim

Did that. Changed nothing.

Maybe this helps. When I open a file inside ranger on the background the output is:

/bin/sh: nano: command not found

Offline

#4 2015-04-02 08:53:19

mychris
Member
From: Munich
Registered: 2012-09-15
Posts: 68

Re: [SOLVED] Sudo Ranger does not open files with VIM

When sudo executes a command, this command will not inherit all the environment variables of the shell. See the man page for sudo.

Offline

#5 2015-04-02 09:03:43

natepad
Member
Registered: 2014-09-25
Posts: 14

Re: [SOLVED] Sudo Ranger does not open files with VIM

Ok. So I can't use vim to open files inside ranger when I opened ranger with sudo?

Offline

#6 2015-04-02 09:25:48

mychris
Member
From: Munich
Registered: 2012-09-15
Posts: 68

Re: [SOLVED] Sudo Ranger does not open files with VIM

Sure you can. As the sudoers man page describes, the env_reset option is on by default. You could use the env_keep options. Or use the -E flag for sudo. Or....

http://www.sudo.ws/sudo/man/1.8.13/sudo.man.html
http://www.sudo.ws/sudo/man/1.8.13/sudoers.man.html

Offline

#7 2015-04-02 14:30:23

natepad
Member
Registered: 2014-09-25
Posts: 14

Re: [SOLVED] Sudo Ranger does not open files with VIM

Thanks a lot for your patience. Will have a look and when all works I will mark the thread as resolved.

Edit: I will use -E flag - but I am not sure if there is a security risk involved to do so. Thanks. Resolved!

Last edited by natepad (2015-04-02 16:07:11)

Offline

#8 2015-04-04 08:29:45

mychris
Member
From: Munich
Registered: 2012-09-15
Posts: 68

Re: [SOLVED] Sudo Ranger does not open files with VIM

It is not only a security problem. You may also end up with files which are owned by root and not changeable by your user in the home directory of your user (depending on your vim configuration, vim may created backup files, just one example).

https://wiki.archlinux.org/index.php/Su … _variables

Offline

#9 2015-04-04 09:14:04

natepad
Member
Registered: 2014-09-25
Posts: 14

Re: [SOLVED] Sudo Ranger does not open files with VIM

Ah, thanks a lot chris. Good point!

Offline

Board footer

Powered by FluxBB