Change default text editor linux

Как в 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

Появится список всех редакторов, установленных в системе, под определёнными номерами. Для изменения достаточно просто указать цифру нужного редактора. Выглядит это так:

Linux изменить текстовый редактор по умолчанию

В этом примере по умолчанию был установлен редактор 0, то есть nano.

Отправив цифру 3, я изменил его на mcedit.

Как изменить текстовый редактор по умолчанию в Centos.

Посмотреть редактор, используемый по умолчанию, можно командой:

Вывод этой команды может быть пустой, или она покажет установленный по умолчанию редактор.

Для изменения редактора по умолчанию, достаточно выполнить команду:

Вместо mcedit можно указать любой другой текстовый редактор, который вам по душе. Главное, чтобы он был установлен в системе.

Нужна профессиональная удалённая помощь с сервером, сайтом, компьютером или ноутбуком?

Свяжитесь со мной любым удобным для вас способом, и получите её быстро и не дорого.

Источник

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.

Читайте также:  Postgresql install linux yum

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.

Источник

Change your default text editor in Linux

Nowadays Linux uses nano for most distributions as the default text editor. In some cases people prefer that, but others may not. It’s possible to change the default text editor in Linux with only a single command. Here’s how.

default text editor

For those who prefer something like vim, you can apply changes through the whole system to use it as a default text editor. In order to do that, simply run the following command:

sudo export EDITOR=/usr/bin/vim

This changes the default editor to vim. What if I want to go back to nano? You can do just that by simply running the command once more like we did earlier:

sudo export EDITOR=/bin/nano

Linux distributions such as CentOS use vi by default, which is why users may have a preference for something else.

Change your default text editor with .bashrc

Let’s say Jim wants to use vim and Amy nano. You can do that simply by configuring the file .bashrc for each user:

sudo echo "export EDITOR=/usr/bin/vim" >> /home/Jim/.bashrc && sudo echo "export EDITOR=/bin/nano" >> /home/Amy/.bashrc

.bashrc contains commands to run for when the user logs on. It’s crucial that this particular file may not be tampered in any other way unless you know what you’re doing. Make sure not to use > instead of >>, otherwise you’ll overwrite the entire .bashrc file.

You now know how to change the text editor in Linux at will!

3 thoughts on “Change your default text editor in Linux”

Источник

How To Set Default Text Editor in Ubuntu

change default text editor in ubuntu

By default, nano is the text editor in Ubuntu. Sometimes you may need to change the default text editor for applications like crontab, that require a text editor. For example, if you are comfortable with vi then you may want to set the default text editor to vi. There are two ways to do this. In this article, we will look at both these methods. Here are the steps to set default text editor in Ubuntu. You can also use them to change text editor in other Linux distributions like CentOS, Redhat, Debian, and other systems.

Читайте также:  Switch to tty linux

How To Set Default Text Editor in Ubuntu

You can change default text editor in Ubuntu by editing .bashrc file, or using update-alternatives command.

Using .bashrc

Open terminal and run the following command to open .bashrc file. Please use the dot(.) before its filename since it is a hidden file.

Add the following lines to .bashrc file to set default editor to vi in Ubuntu. Replace vi with the text editor of your choice.

export EDITOR='vi' export VISUAL='vi'

Now log out of your account and log in again, to apply changes. Alternatively, you can also run the following command.

That’s it. The default text editor in Ubuntu will be changed to vi.

Using update-alternatives

Open terminal and run the following command. It will list all the editors available in your system, with a * displayed before the present default text editor.

$ sudo update-alternatives --config editor

When you enter the above command, you will see a prompt as shown below.

There are 5 alternatives which provide `editor’. Selection Alternative ———————————————– 1 /usr/bin/vim 2 /bin/ed *+ 3 /bin/nano 4 /usr/bin/vim.basic 5 /usr/bin/vim.tiny Press enter to keep the default[*], or type selection number:

In the above output, * is displayed before option 3 since it is our default editor. If you want to change the default text editor to vim, enter 1. If you want to continue with your existing default text editor, then enter 3.

That’s it. Your default text editor will be changed.

You can easily test the change by entering crontab -e command, which will open the default text editor.

Источник

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:

  1. Right click on a text file.
  2. Choose «Properties» (not «Open With. «)
  3. Click on the «Open With» tab.
  4. Choose your new text editor.
  5. 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 .

Читайте также:  Astra linux debian ubuntu

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 in WSL. (Specifically sudo update-alternatives —config editor )

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.

Источник

Оцените статью
Adblock
detector