Skip to main content
1 of 5
林果皞
  • 5.6k
  • 4
  • 35
  • 46

You can add this line to ~/.bashrc (gedit as example, since my default is already vim.gtk3):

export SYSTEMD_EDITOR=gedit

And then sudo visudo and add this line:

Defaults  env_keep += "SYSTEMD_EDITOR"

Start new bash session to take effect, then run sudo systemctl edit <foo> as usual.

Second way is use update-alternatives:

$ sudo update-alternatives --config editor
There are 6 choices for the alternative editor (providing /usr/bin/editor).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/vim.gtk3    50        auto mode
  1            /bin/ed             -100       manual mode
  2            /bin/nano            40        manual mode
  3            /usr/bin/code        0         manual mode
  4            /usr/bin/vim.basic   30        manual mode
  5            /usr/bin/vim.gtk3    50        manual mode
  6            /usr/bin/vim.tiny    15        manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /bin/nano to provide /usr/bin/editor (editor) in manual mode

Third way is direct set the EDITOR on runtime:

sudo EDITOR=gedit systemctl edit <foo>
林果皞
  • 5.6k
  • 4
  • 35
  • 46