Do not just like the default textual content editor in your Linux distro and need to change it to one thing else? It is fairly easy to do with just a few quick instructions. I am going to stroll you thru a number of methods you are able to do it, irrespective of which Linux model you are utilizing.


For this information, I am utilizing Ubuntu 24.04 LTS. Should you’re utilizing a distinct distro, you’ll be able to nonetheless observe alongside as most if not all of the instructions are the identical.



Checking Present Default Textual content Editor

Earlier than altering the default textual content editor, it is good to know the present default one set in your Linux distro. To try this, you’ll be able to examine the $EDITOR variable by operating this command:

echo $EDITOR

Nonetheless, in case your $EDITOR variable will not be set, you won’t get any output in return. If that is the case, you may also examine the default editor utilizing this command:

sudo visudo

Running the visudo command to check the default text editor on Linux.

The file was opened in the nano editor. So, that is my default editor.

Altering the Default Textual content Editor

Now that you recognize your present default editor, let’s discover how one can change it.

Utilizing select-editor

The select-editor command lets you choose a per-user editor. It selects your most popular sensible-editor. Run the command:

select-editor

You may see a number of editors listed subsequent to a quantity. Kind within the quantity for the default editor you need and hit Enter.


Changing the default editor on Linux using the select-editor command.

For demonstration, I am coming into 2 to vary the default editor to Vim. To examine if it was profitable, run:

cat ~/.selected_editor

Checking the selected_editor file to find the current default editor.

It ought to present you the editor you simply chosen.

Utilizing the update-alternatives Command

The update-alternatives command helps you to keep symbolic hyperlinks that decide default instructions. You should use this to vary default behaviors reminiscent of which editor to open for a system name. In contrast to the select-editor instrument, this can be a system-wide selector. To make use of this command for altering the editor, run:

sudo update-alternatives --config editor


Then choose the quantity on your most popular editor and press Enter.

Changing the default editor on Linux using the update-alternatives command.

Now, to examine if you happen to modified it efficiently, run the under command:

ls -l /usr/bin/editor /and many others/options/editor

Checking if update-alternatives could change the default editor.

In my case, the editor was modified from nano to Vim efficiently.

Enhancing the EDITOR Surroundings Variable

If the above strategies did not be just right for you, or your distro would not help them, then contemplate configuring the necessary environment variables, which I am going to cowl on this and the following technique.


First, open your shell configuration file in a textual content editor. Since I am utilizing Bash on Ubuntu, I will be working with the .bashrc file. In different circumstances, this could possibly be the bash_profile file or one other file relying in your shell. To open the file in nano, run:

nano ~/.bashrc

Then add this line to the tip of the file:

export EDITOR=/path/to/your/most popular/editor

For instance, for Vim, the road could be as follows:

export EDITOR=/usr/bin/vim

Setting the EDITOR environment variable in the bashrc file.

Should you’re unsure the place your editor is positioned, you’ll be able to write the road like this:

export EDITOR=$(which vim)

This technique makes use of the which command on Linux to find Vim. As soon as you have written the road, save the file with Ctrl+O after which exit nano utilizing the Ctrl+X buttons.

This is a one-liner you’ll be able to run in your terminal to do the entire thing:

echo "export EDITOR='/usr/bin/vim'" >> ~/.bashrc


After doing this, you must make the adjustments take impact by sourcing the file. To try this, run:

supply ~/.bashrc

Now check if the variable was set correctly by operating:

echo $EDITOR

It ought to present the textual content editor you had simply set and use it as default.

Enhancing the VISUAL Surroundings Variable

The VISUAL variable’s editor is able to superior terminal functionalities and helps full-screen editors reminiscent of nano, emacs, vim, and many others. The EDITOR variable’s editor would not have such privileges, which makes them a bit completely different. You may set the VISUAL variable in your shell configuration file the identical manner you set the EDITOR variable.

echo "export VISUAL='/path/to/your/most popular/editor'" >> ~/.bashrc

Then run:

supply ~/.bashrc

See if you happen to’ve efficiently set the VISUAL variable.

echo $VISUAL

Setting the VISUAL environment variable in the bashrc file.

As anticipated, that labored efficiently.


Testing the Modifications

The very last thing to do is see if you happen to may efficiently change your default textual content editor to your most popular one. You may examine this in just a few alternative ways. For instance, you’ll be able to examine crontab’s editor. To take action, run:

crontab -e

Running the crontab -e command to check the default editor.

As you’ll be able to see, my default textual content editor is now Vim versus nano.

One necessary factor to know is that there is an order of priority amongst these configurations. So, suppose that you simply used completely different strategies to outline completely different default editors. Which would be the default editor? To find out that, here is the order:

  1. Configuring the atmosphere variables will take the best priority and override all different settings for the present consumer.
  2. Software program that makes use of the select-editor command to know the default editor will use the ~/.selected_editor file’s selection as a priority, once more for the present consumer.
  3. The system-wide configuration utilizing update-alternatives command takes the least priority and is overridden by the user-specific settings listed above.



Text editing on Linux is without doubt one of the most typical issues to do and doing it in your favourite editor is a bonus. Should you do not just like the textual content editors you will have in your working system, you also needs to consider trying alternative ones.


Source link