- Как в Linux изменить текстовый редактор по умолчанию
- Нужна профессиональная удалённая помощь с сервером, сайтом, компьютером или ноутбуком?
- Getting the default text editor used in system
- 3 Answers 3
- How do I change the default text editor in Ubuntu
- 2 Answers 2
- How do I change the default text editor?
- 12 Answers 12
Как в Linux изменить текстовый редактор по умолчанию
В Linux существует несколько текстовых редакторов. Vim, Nano, Mcedit, и другие. У каждого пользователя есть свои предпочтения и привычки, кому-то удобно пользовать одним редактором, кому-то другим.
Я, например, люблю текстовый редактор mcedit, который устанавливается вместе с файловым менеджером Midnight Commander (mc).
Когда работаешь в консоли, легко можно вызвать нужный редактор, просто написав его имя перед файлом, который мы хотим отредактировать. Например, если написать в консоли команду
то откроется редактор mcedit, в котором будет содержимое файла file, доступное для редактирования.
Но существуют некоторые команды, когда нет возможности задать редактор для редактирования. Например, мы хотим изменить список заданий планировщика cron. Для этого вводим команду
Откроется файл, редактирования списка заданий планировщика. Но откроется он в редакторе, установленном в системе по умолчанию. Обычно это vim. А я хочу, чтобы он открывался в mcedit 🙂
Как изменить текстовый редактор по умолчанию в Debian/Ubuntu.
Посмотреть, какой редактор установлен по умолчанию, можно командой:
ls -l /etc/alternatives/editor
А для изменения редактора по умолчанию в Debian/Ubuntu нужно выполнить команду:
sudo update-alternatives --config editor
Появится список всех редакторов, установленных в системе, под определёнными номерами. Для изменения достаточно просто указать цифру нужного редактора. Выглядит это так:
В этом примере по умолчанию был установлен редактор 0, то есть nano.
Отправив цифру 3, я изменил его на mcedit.
Как изменить текстовый редактор по умолчанию в Centos.
Посмотреть редактор, используемый по умолчанию, можно командой:
Вывод этой команды может быть пустой, или она покажет установленный по умолчанию редактор.
Для изменения редактора по умолчанию, достаточно выполнить команду:
Вместо mcedit можно указать любой другой текстовый редактор, который вам по душе. Главное, чтобы он был установлен в системе.
Нужна профессиональная удалённая помощь с сервером, сайтом, компьютером или ноутбуком?
Свяжитесь со мной любым удобным для вас способом, и получите её быстро и не дорого.
Getting the default text editor used in system
I have used select-editor and I note that I am using /usr/bin/nano . Is this the default text editor I am using? When I open text files, It opens with gedit What command in terminal must be specified to get the default text editor that I am using, and have it returned to e in terminal?
3 Answers 3
First of all you should notice that there are two types of text editors..
- The command line editors such as vim, nano, emacs, etc..
- GUI text editors such as gedit, kate, .
The default text editor when using the GUI is not the same as the command line text editors so when you are opening a file using GUI you probably are using the GUI text editors which is gedit by default. While when using the command line so you are using the command line text editors.
To know that is the default command line text editor in your system you can try one of the following methods:
First Method:
sudo update-alternatives --config editor
This command show you the text editors. The one you are using has the * in front
Selection Path Priority Status ------------------------------------------------------------ * 0 /bin/nano 40 auto mode 1 /bin/ed -100 manual mode 2 /bin/nano 40 manual mode 3 /usr/bin/vim.basic 30 manual mode 4 /usr/bin/vim.tiny 10 manual mode
Second Method:
to set the default editor you can add the following to your shell configuration ( ~/.bashrc ):
export VISUAL="/usr/bin/nano" export EDITOR="$VISUAL"
How do I change the default text editor in Ubuntu
How can I change the default text editor for console programs in Ubuntu. When I run mutt and send a message, it currently loads up Joe and I would prefet to load Vim. I know I can change $EDITOR for me only, but would prefe to do it system wide.
This is certainly one of the dumbest things ubuntu has done, setting Emacs (or Joe whatever) as the default editor. And to make matters worse no regular vim, just tiny or basic.
2 Answers 2
You can change $EDITOR systemwide. Just drop a short script into /etc/profile.d/ which does this. The file only needs a single line:
export EDITOR=/usr/bin/myeditor
There are two ways (at least :-/) in which a program can find an editor to launch. The traditional Unix/Linux mechanism is to use $EDITOR. In addition to that, Debian (and therefore Ubuntu) has special aliases for various kinds of programs. These are provided by the «alternatives» system (a system of configurable symlinks). For editors this provides the aliases editor and sensible-editor . These can be updated using update-alternatives:
sudo update-alternatives --config editor
(same for sensible-editor). This will prompt you for the editor to use.
However, in Debian programs are suppposed to read $EDITOR first:
Thus, every program that launches an editor or pager must use the EDITOR or PAGER environment variable to determine the editor or pager the user wishes to use. If these variables are not set, the programs /usr/bin/editor and /usr/bin/pager should be used, respectively.
These two files are managed through the dpkg «alternatives» mechanism.
If it is very hard to adapt a program to make use of the EDITOR or PAGER variables, that program may be configured to use /usr/bin/sensible-editor and /usr/bin/sensible-pager as the editor or pager program respectively.
In one sentence: Setting $EDITOR globally should be enough.
How do I change the default text editor?
It is answered here: askubuntu.com/questions/977538/… — basically you want to export EDITOR=emacs — and perhaps add that to your .bashrc so it becomes your default.
12 Answers 12
Here is what worked in my case:
- Right click on a text file.
- Choose «Properties» (not «Open With. «)
- Click on the «Open With» tab.
- Choose your new text editor.
- Mark chosen text editor using a button «Set as default».
This also works on 12.04 and 13.04.
@ Edit: based on comments it does work on all distros until 20.04
To change default text editor across the file types, try updating gnome-text-editor configuration.
sudo update-alternatives --config gnome-text-editor
sudo update-alternatives --config editor
How can someone add another option? In my case I get the following: There is only one alternative in link group gnome-text-editor (providing /usr/bin/gnome-text-editor): /usr/bin/gedit — EDIT: found how to do it: sudo update-alternatives —install /usr/bin/gnome-text-editor gnome-text-editor /path/to/executablesublime 100 in my case /snap/bin/subl outoutted by which subl .
Thanks for this answer! Same here, I added subl first: sudo update-alternatives —install /usr/bin/gnome-text-editor gnome-text-editor $(which subl) 100 . Then it was already selected as editor, as the above command then confirmed.
This is the one you need to ensure your editor choice persists even when running programs using wsl.exe
A more robust solution would be to replace the bindings in /usr/share/applications/defaults.list .
sed -i 's/gedit/emacs/' /usr/share/applications/defaults.list
I don’t know how, but by copying this command I accidentally cleared the whole file. I would much prefer doing this in a text editor using find-replace (as explained in this answer) for those who are not too familiar with sed.
I did this (in a text editor with find-replace, which should have the same result), then logged out and back in but still C++ header files (*.h) are opened in gedit.
I don’t use a DE, but for my configurations the next command is the best:
- it selects your default sensible-editor from all installed editors
- must run with current user
- you must have more than one editor in your system
After setting EDITOR to vi, VISUAL to vi, linking /etc/alternatives/editor or whatever to vi, I still got the pest named nano as the editor when running commands like virsh edit myvm . Applying a level of self-control I would never have guessed I could reach, I am not venting here. NOT VENTING AT ALL. I renamed nano to nano.deleted, then I got several lines of error messages whenever I edited something. select-editor didn’t change that. What did help was rm /usr/bin/sensible-editor followed by ln -s /usr/bin/vi /usr/bin/sensible-editor . Life is good.
Right click on a text file, point to «Open With» and it’ll show other editors in a sub-menu. Click on «Other Application. «. It’ll show you a dialog with a list of applications, select Emacs and make sure the «Remember this application for «plain text document» file» option is checked. Click «Open».
I did try this, but I’m having a bit of a problem — whenever I double-click on a file in Nautilus, I get a dialog box that says: «Do you want to run «tasks.css», or display its contents? «tasks.css» is an executable text file.» And then there are four options — Run in Terminal, Display, Cancel, Run. (This happens with every file, not just CSS files.)
@begtognen: Sorry for the ultra-late reply. But I’ve been trying to find a solution for this myself. Just found one — go to Nautlius preferences (Edit > Preferences), select the «Behavior» tab and under the «Executable Text Files» section, select the radio button «View executable text files when they are opened». Fixed the issue for me.