Setting default editor linux

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 .

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.

Читайте также:  Linux here is document

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.

Источник

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..

  1. The command line editors such as vim, nano, emacs, etc..
  2. 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.

Читайте также:  Команда установки linux mint

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.

Источник

Introduction

This short tutorial will demonstrate how to change default command line (bash) editor in Linux and Unix type operating system. Most of the Linux distribution comes with vim or vi as default bash editor. Both are powerful editor, but I don’t like their interface. Here I’m going to demonstrate changing bash editor from vim to nano in CentOS 7.3 environment. Nano (developer’s link) is an advance command line editor with better interface. Same method is applicable for any other Linux or Unix distribution with bash as default command line.

Disclaimer: I’m running all installation commands as root user. So, I’m not using sudo. If you’re running a non root user with super user privilege append all installation and other necessary commands with sudo.

Difficulty: Easy Time Require: Less than 5 minutes.

Installing nano

In RHEL and CentOS nano is present in base repository and can be installed with yum as follows

Same way, you can install nano in Debian and Ubuntu using apt-get

Finding the binary location

You can find executable binary of any installed package using which as follows.

This will give the location of executable binary location, here “/usr/bin/nano”

If which which is not installed install it as follows

Changing bash editor from vim or vi to nano

For Individual User:

Edit or create “.bash_profile” or “.bashrc” in user’s home directory with your favorite editor

Append the file with following

A sample configuration file is as follows

.bash_profile sample picture

From next time when you log into the system you’ll find nano as your default editor.

Читайте также:  Newer command in linux

Changing system wide configuration

To change system wise default bash editor edit “/etc/bashrc” file and append it as follows

Note: For specific user, system wise bash configuration is overridden with individual user’s configuration.

Checking the configuration

You may want to let sure that it’s changed. To check the new default editor first logout from the existing bash session.

Then start a new session and try to edit crontab with the following command.

If everything goes right you’ll find the nano interface as crontab editor instead vim or vi. If this is not in your case please follow the above steps once again

Serverlog thanks you for reading. For any difficulty please don’t forget to leave your comments bellow.

Источник

Как сменить редактор по умолчанию

Когда поставил себе цель уметь пользоваться чем-либо то нужно сразу же переключиться на задуманное, а не время от времени. Вот так и я. Я решил, хочу более сносно ориентироваться при использовании редактора именуемого vim, а раз так то ниже пошаговые шаги по воплощении задуманного. Все дальнейшие действия происходят на рабочей/тестовой системе Ubuntu Trusty Desktop/Server.

Ранее я постоянно использовал редактор nano, а теперь хочу VIM.

ekzorchik@system:~$ sudo apt-get install vim -y

ekzorchik@system:~$ sudo update-alternatives —config editor

Есть 5 вариантов для альтернативы editor (предоставляет /usr/bin/editor).

Выбор Путь Приор Состояние

* 0 /bin/nano 40 автоматический режим

  • 1 /bin/ed -100 ручной режим
  • 2 /bin/nano 40 ручной режим
  • 3 /usr/bin/mcedit 25 ручной режим
  • 4 /usr/bin/vim.basic 30 ручной режим
  • 5 /usr/bin/vim.tiny 10 ручной режим

Нажмите enter, чтобы сохранить текущий выбор[*], или введите выбранное число: 5

update-alternatives: используется /usr/bin/vim.tiny для предоставления /usr/bin/editor (editor) в ручной режим

Но и после этого при вызове sudo crontab -e все равно открывает редактирование через редактор nano, а я хочу через vim, как тогда сделать это?

ekzorchik@system:~$ select-editor

touch: невозможно выполнить touch для «/home/ekzorchik/.selected_editor»: Отказано в доступе

ekzorchik@system:~$ ls -l /home/ekzorchik/.selected_editor

-rw-r—r— 1 root root 66 Jul 18 15:26 /home/ekzorchik/.selected_editor

ekzorchik@system:~$ sudo chown ekzorchik:ekzorchik ~/.selected_editor

ekzorchik@system:~$ select-editor

Select an editor. To change later, run ‘select-editor’.

Choose 1-6 [2]: 4

ekzorchik@system:~$ cat ~/.selected_editor

# Generated by /usr/bin/select-editor

ekzorchik@system:~$ sudo crontab -e

При редактировании crontab файл VIM теперь дефолтный редактор

Отлично, сработало, теперь редактор по умолчанию vim. На этой ноте, я завершаю свое повествование. Т.к. заметка писалась под конкретную задачу лично для себя и что интересовало меня в данный момент. На этом у меня всё, с уважением автор блога Олло Александр aka ekzorchik.

От ekzorchik

Всем хорошего дня, меня зовут Александр. Я под ником — ekzorchik, являюсь автором всех написанных, разобранных заметок. Большинство вещей с которыми мне приходиться разбираться, как на работе, так и дома выложены на моем блоге в виде пошаговых инструкции. По сути блог — это шпаргалка онлайн. Каждая новая работа где мне случалось работать вносила новые знания и нюансы работы и соответственно я расписываю как сделать/решить ту или иную задачу. Это очень помогает. Когда сам разбираешь задачу, стараешься ее приподнести в виде структурированной заметки чтобы было все наглядно и просто, то процесс усвоения идет в гору.

Источник

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