Default file editor linux

Command for the default in-terminal text editor

I often see instructions that include vim or nano , meaning to open the file in that step in your text editor of choice. Is there an agnostic command I can use in place of the specific program that would open the input in the user’s default in-terminal text editor, whether it’s vim , nano , or something else? I see editor mentioned in the Similar Questions sidebar—is that still limited to Debian-based distros? And is there any alternative?

in Debian you can also configure the program executed when you call «editor» by executing once: «update-alternatives —config editor». There you can select the one you prefer (default is nano). This will e.g. make so that when you press «v» in less you get the editor you want, so you can switch from nano to vi.

4 Answers 4

You can use $EDITOR , provided that it’s been defined:

But I think most docs use nano because if someone’s blindly following along, it’s a safe bet to use. If the user has decided they actually prefer one editor over another, they’ll know enough to replace it with vim , emacs , etc themselves.

edit may work well on Debian-based systems, but on others it invokes ex , which isn’t recommended.

$EDITOR only makes sense if it’s defined. Invoking ed hardly counts as standard and is abysmal in terms of user-friendliness. edit is perfectly fine on Debian, but may invoke vi on other systems (where does it invoke ex?).

Gilles: You’re right, it only makes sense if it’s been defined. It was the closest thing to a «universal» command per the OP’s question. «Ed is the standard» is an old joke, since it’s the one defined in the POSIX standard (see «man ed» or Google «Ed is the standard» for more info). I don’t know about «edit» on other systems, but mine invokes ex (Arch Linux), so it can’t be considered universal.

POSIX also defines vi. Jokes are fine, but don’t present them as something serious — I‘ve heard that one before but your target audience hasn’t.

If the environment variable VISUAL is set, use that.

Otherwise, if the environment variable EDITOR is set, use that.

Otherwise, Unix tradition defaults to vi . This is not at all user-friendly — people who use vi know how to set up their system to invoke it, your application should be friendly to those users who don’t. Unfortunately there’s no good, portable way to find a decent editor. You can try xdg-mime query default , but even where the utility is available, it doesn’t always work. On Debian and Debian-like systems, invoke sensible-editor , which does all that stuff for you — but I don’t know of anything like it on other Unix variants.

#!/bin/sh if [ -n "$VISUAL" ]; then exec $VISUAL "$@" elif [ -n "$EDITOR" ]; then exec $EDITOR "$@" elif type sensible-editor >/dev/null 2>/dev/null; then exec sensible-editor "$@" elif cmd=$(xdg-mime query default ) 2>/dev/null; [ -n "$cmd" ]; then exec "$cmd" "$@" else editors='nano joe vi' if [ -n "$DISPLAY" ]; then editors="gedit kate $editors" fi for x in $editors; do if type "$x" >/dev/null 2>/dev/null; then exec "$x" "$@" fi done fi 

Most programs do whitespace splitting on $VISUAL and $EDITOR , but not all.

Читайте также:  Capacity of battery in linux

Источник

ubuntu default editor

It opens the Nano editor on my system as it is the default text editor for Ubuntu 18.04 (Bionic Beaver). If you want to change the default editor or any other program for that matter, you can use the update-alternatives utility for this purpose.

  1. How do I find the default editor in Linux?
  2. What is default editor in Linux?
  3. What is default editor?
  4. How do I change the default editor in Vim Ubuntu?
  5. How do I find my default editor?
  6. How do I change the default text editor in Terminal?
  7. How do I open a text editor in Linux?
  8. Does Linux have a text editor?
  9. How do I edit a .bashrc file?
  10. How do I make Gedit my default text editor?
  11. Which is not a text editor?
  12. Which is the most common text editor in Unix?

How do I find the default editor in Linux?

  1. Log in to your account using SSH.
  2. Open the . bashrc file in your preferred text editor.
  3. Add the following lines to the .bashrc file. .
  4. Save the changes to the . .
  5. To make the new default text editor settings take effect, log out of your account and then log back in.

What is default editor in Linux?

Set Nano as the Default Text Editor

By default on most Linux systems, the default text editor for commands such as visudo and crontab is set to vi. To use nano as the default text editor, you need to change the VISUAL and EDITOR environment variables .

What is default editor?

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.

How do I change the default editor in Vim Ubuntu?

On Ubuntu (or other Debian-based systems), update-alternatives can be used to change the default editor: sudo update-alternatives —config editor # Type the number which corresponds to Vim here (after installing it) then press Enter.

How do I find my default editor?

You can test this out by typing in crontab -e to edit your cron file. You should see the editor that you chose, instead of the default.

How do I change the default text editor in Terminal?

2 Answers. Simply set the EDITOR variable to vim in your bash startup file. edit-and-execute-command (C-xC-e) Invoke an editor on the current command line, and execute the result as shell commands. Bash attempts to invoke $FCEDIT, $EDITOR, and emacs as the editor, in that order.

Читайте также:  Linux время последней загрузки

How do I open a text editor in Linux?

The easiest way to open a text file is to navigate to the directory it lives in using the “cd” command, and then type the name of the editor (in lowercase) followed by the name of the file.

Does Linux have a text editor?

There are two command-line text editors in Linux®: vim and nano. You can use one of these two available options should you ever need to write a script, edit a configuration file, create a virtual host, or jot down a quick note for yourself.

How do I edit a .bashrc file?

  1. Open the BASH configuration file for editing: sudo nano ~/.bashrc. .
  2. You can change the BASH prompt temporarily by using the export command. .
  3. Use the –H option to display a a full hostname: export PS1=»uH » .
  4. Enter the following to show username, shell name, and version: export PS1=»u >sv «

How do I make Gedit my default text editor?

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

Which is not a text editor?

A text editor is a type of computer program that edits plain text. Such programs are sometimes known as «notepad» software. Word pad and note Pad for windows and simple text and text edit for the mac are common text editors.

Which is the most common text editor in Unix?

1. Vi/Vim Editor. Vim is a powerful command-line based text editor that has enhanced the functionalities of the old Unix Vi text editor. It is one the most popular and widely used text editors among System Administrators and programmers that is why many users often refer to it as a programmer’s editor.

How to kill a process on Linux

Process

How do you kill a process in Linux?How do you kill a process in Unix?How do you kill a process?How do I start a process in Linux?How do I list all pro.

How to Use Regex with the 'awk' Command

Patterns

Can you use regex in awk?What is awk regex?What is expression in awk?How do you match patterns with awk?How do you escape quotes in awk?How do you use.

Mycroft Mark II The Open Source Answer to Amazon Echo and Google Home That Doesn't Spy on You

Google

What is the difference between Alexa and Echo and Google home?Can Google home and Amazon Alexa work together?What is Google’s answer to Amazon’s Echo.

Latest news, practical advice, detailed reviews and guides. We have everything about the Linux operating system

Источник

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:

Читайте также:  Мультизагрузочная флешка linux windows iso

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 to open the default text editor in Linux?

I need to open the default text editor in Linux without having a file. I know that I could use the command xdg-open to open a file in the default editor, but I need to open the editor without having a file and let the user create the file. I solved it with this script:

#!/bin/sh cd /usr/share/applications/ atalho=`grep $1 defaults.list | tail -1 | sed "s:^$1=::" ` `grep '^Exec' $atalho | tail -1 | sed 's/^Exec=//' | sed 's/%.//'` & 

2 Answers 2

There is no completely reliable concept of «default editor» on Linux, let alone more broadly Unix-like systems.

Traditionally, users would set the environment variable EDITOR to the path of their editor of choice. If this variable is set, I’m thinking you can be reasonably confident that they will know how to use it, even if they end up in something horrible like nano .

A slightly newer convention is to set VISUAL to the preferred «visual editor» — I guess the terminology comes from vi to contrast against line editors like ed .

On Debianish systems, the system default editor is configurable via alternatives and available simply with the command editor .

On XDG systems, of course, you could simply

touch path/to/new/file.txt xdg-open path/to/new/file.txt 

Needless to say, this only works if you have XDG, i.e. In practice a Linux (or maybe modern *BSD) platform with an active graphical session (excludes Mac and pre-XDG graphical systems as well as of course any server environment where there is no GUI).

As an aside, if I can guess even roughly what your script does, it could probably be pared down to a fairly simple sed script. Remember, sed can do (almost) everything grep and tail can. Maybe see also Combining two sed commands — here is a quick and dirty refactoring.

cd /usr/share/applications $(sed -n "s:^Exec=\([^%]*\)\(%.\(.*\)\)*:\1\3:p" "$(sed -n "s:^$1=::p" defaults.list | tail -1)" | tail -1) & 

However, from quick googling, it looks like /usr/share/applications/defaults.list is specific to OpenDesktop environments; but it’s the system-wide default default — the admin could have installed an override in a different location, and individual users probably have individual preferences on top of that. Finding and traversing this hierarchy is precisely what xdg-open does, so I’m not going to try to reimplement it in an ad-hoc script of my own, and suggest you shouldn’t, either.

There is nothing about graphical environments in your question, so it’s unclear whether you are actually looking for a simple editor for beginners who barely know how to click and drool in a graphical environment (in which case I’d say go with touch followed by xdg-open ) or a competent programmers’ editor which way or may not run in a window (maybe try VISUAL with fallback to EDITOR , and document that you use this mechanism).

Источник

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