How to open the default GUI text editor in Ubuntu or Lubuntu via a script?
Emily Wong
I have a script that uses gedit to open text file in Ubuntu. That script does not work under Lubuntu. What command is required to execute the default text editor?
I want to make the script usable under Ubuntu and Lubuntu.
36 Answers
Use xdg-open it works in most linux distros.
example:
xdg-open /filepath/file.txt 1 You might get somewhere with /usr/bin/gnome-text-editor, as that's set using the alternatives system and points to the default editor under a gnome-ish environment. Not quite sure whether it is actually useful under lubuntu/kubuntu, but you could try.
Just to supplement Dennis' answer, with respect to Lubuntu 12.10, if one runs sudo update-alternatives --display gnome-text-editor, the output is:
gnome-text-editor - auto mode link currently points to /usr/bin/leafpad
/usr/bin/leafpad - priority 40 slave gnome-text-editor.1.gz: /usr/share/man/man1/leafpad.1.gz
Current 'best' version is '/usr/bin/leafpad'.And, as Dennis suggested, /usr/bin/gnome-text-editor does open Leafpad in Lubuntu.
Or you can install gedit
sudo apt-get install geditThen:
- Right-click a text or php file
- Select "Properties"
- Select "Open with" tab
- Choose among the listed/installed text editors
- Click "Set as default"
- Click "Close"
In addition to Dennis Kaarsemaker's answer, you could try using /usr/bin/editor for something even more generic. This will likely lead to a terminal-based editor be launched, though.
Cf. the update-alternatives manpage.
2Here is a list of Lubuntu Apps. However, in 18.10 the editor has changed from Leafpad to Featherpad.
In Lubuntu 20.04 the default terminal text editor is vi: Here is a guide on how to use vi. How to use vi text editor on Lubuntu
Here is an example of using vi in a terminal (or script):
vi /etc/rc.local