8

I recently installed virt-manager on Arch Linux, and unlike under Ubuntu, I was not prompted to choose a text editor on the first launch of virsh-edit. Instead, the XML file was opened in vi (or vim, not sure).

From this thread in the RedHat archives, I thought that if I just added to ~/.bashrc:

export EDITOR=/usr/bin/nano

that would solve the problem. But setting EDITOR environment variable didn't work.

Also, launching it with EDITOR=geany sudo virsh edit myWINVM gave the same result, as did trying to use a different editor: EDITOR=geany sudo virsh edit myWINVM as described here

and I see that the variable has in fact been set:

[~]$ printenv
SHELL=/bin/bash
SESSION_MANAGER=local/virtland:@/tmp/.ICE-unix/5451,unix/virtland:/tmp/.ICE-unix/5451
WINDOWID=27262979
COLORTERM=truecolor
XDG_CONFIG_DIRS=/etc/xdg
XDG_MENU_PREFIX=xfce-
SSH_AUTH_SOCK=/tmp/ssh-j36TZui4fOt5/agent.5457
DESKTOP_SESSION=Xfce Session
SSH_AGENT_PID=5458
EDITOR=/usr/bin/nano
...

However virsh edit MYVM still opens the XML in vi.

Is there something different I need to do in Arch? Has the method of changing this setting been changed in recent updates of virsh?

3

4 Answers 4

4

I had to add the editor to sudoers by putting Defaults editor=/bin/nano at the end of /etc/sudoers AND THEN I could use sudo EDITOR=nano virsh edit myWINVM.

Update: at a later time, I got it working by adding export EDITOR=nano to /etc/environment.

6
  • 1
    I'm not sure how the sudoers change (of editor) solved your problem, since that's only the editor that visudo will use, and should have no bearing on virsh's EDITOR value.
    – Jeff Schaller
    Feb 24, 2019 at 15:12
  • 1
    You might have better luck with a sudoers change of env_keep += "EDITOR"
    – Jeff Schaller
    Feb 24, 2019 at 15:16
  • Just to add, I encountered this problem again and now changing the visudo editor in /etc/sudoers has no effect. Still looking for a permanent solution.
    – Stonecraft
    Aug 7, 2019 at 23:28
  • OK, I got it working by adding export EDITOR=nano to ` /etc/environment` .
    – Stonecraft
    Aug 7, 2019 at 23:56
  • /etc/environment isn't a shell file, export has no business there.
    – muru
    Aug 8, 2019 at 1:50
2

Remove the file ~/.selected_editor, and virsh will prompt you for the editor to use. Probably, that's the one in /root, since one needs admin privilege to use virsh.

0

If you run virsh with sudo, the /root is the directory the configuration applies to.

Just some remarks: the solution above works fine. And code does not just run out of the box when selected. So this seems to be the works choice for virsh when used together with sudo.

sudo cat .selected_editor 

So the result looks like

# Generated by /usr/bin/select-editor
SELECTED_EDITOR="/usr/bin/code"

Change it and retry, - or as said above.

0

Try

sudo -E virsh edit myWINVM

The -E flag will preserve your current user's environment variables when running as root, so as long as you have EDITOR exported in your user's environment, then it will be picked up.

New contributor
the-magic-code-bus is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.