- Linux edit command
- Description
- Syntax
- Options
- Examples
- Related commands
- Best Text Editors for Linux Command Line
- Classic Command Line Text Editors
- 1. Vim
- How to install it?
- 2. GNU Emacs
- How to install it?
- 3. Nano
- How to install it?
- Modern Text Editors For Command Line
- 4. ne – The Nice Editor
- How to install it?
- 5. Neovim
- How to install it?
- 6. Tilde
- How to install it?
- Wrapping Up
Linux edit command
On Unix-like operating systems, the edit command is a text editor.
Description
edit is a variant of the text editor ex. It’s recommended for new or casual users who want to use a command-oriented editor. It operates precisely as ex with the following options automatically set:
The following brief introduction should help you get started with edit. If you are using a CRT terminal, you might want to learn about the display editor vi. To edit the contents of an existing file you begin with the command:
edit makes a copy of the file FILENAME which you can then edit. It first tells you how many lines and characters are in the file. If the file does not exist, edit tells you it is a [New File].
The edit command prompt is a colon (:), which is shown after starting the editor. If you are editing an existing file, then you have some lines in edit’s buffer (its name for the copy of the file you are editing). When you start editing, edit makes the last line of the file the current line. Most commands to edit use the current line if you do not tell them which line to use. Thus if you say print (which can be abbreviated p) and enter a carriage return (as you should after all edit commands), the current line is printed. If you delete (d) the current line, edit prints the new current line, which is usually the next line in the file. If you delete the last line, then the new last line becomes the current one.
If you start with an empty file or want to add some new lines, then the append (a) command can be used. After you execute this command (typing a carriage return after the word append), edit reads lines from your terminal until you type a line consisting of a dot (.); it places these lines after the current line. The last line you type then becomes the current line. The insert (i) command is like append, but places the lines you type before, rather than after, the current line.
The edit utility numbers the lines in the buffer, with the first line having number 1. If you execute the command 1, then edit types the first line of the buffer. If you then execute the command d, edit deletes the first line, line 2 becomes line 1, and edit prints the current line (the new line 1) so you can see where you are. In general, the current line is always the last line affected by a command.
You can make a change to some text in the current line using the substitute (s) command:
where old is the string of characters you want to replace and new is the string of characters you want to replace old with.
The file name (f) command tells you how many lines there are in the buffer you are editing and says [Modified] if you have changed the buffer. After modifying a file, you can save the contents of the file by executing a write (w) command. You can leave the editor by issuing a quit (q) command. If you run edit on a file, but do not change it, it is not necessary (but does no harm) to write the file back. If you try to quit from edit after modifying the buffer without writing it out, you receive the message «No write since last change (:quit! overrides)«, and edit waits for another command. If you do not want to write the buffer out, issue the quit command followed by an exclamation point (q!). The buffer is then irretrievably discarded and you return to the shell.
Using the d and a commands and giving line numbers to see lines in the file, you can make any changes you want. Learn at least a few more things, however, if you use edit more than a few times.
The change (c) command changes the current line to a sequence of lines you supply (as in append, you type lines up to a line consisting of only a dot (.). You can tell change to change more than one line by giving the line numbers of the lines you want to change, that is, 3,5c. You can print lines this way too: 1,23p prints the first 23 lines of the file.
The undo (u) command reverses the effect of the last command you executed that changed the buffer. So if you execute a substitute command that does not do what you want, type u and the old contents of the line are restored. You can also undo an undo command. edit gives you a warning message when a command affects more than one line of the buffer. Note that commands such as write and quit cannot be undone.
To look at the next line in the buffer, type a carriage return. To look at several lines, type ^D (while holding down Ctrl , press D ) rather than carriage return. This shows you a half-screen of lines on a CRT or 12 lines on a hardcopy terminal. You can look at nearby text by executing the z command. The current line appears in the middle of the text displayed, and the last line displayed becomes the current line; you can get back to the line where you were before you executed the z command by typing ». The z command has other options: z- prints a screen of text (or 24 lines) ending where you are; z+ prints the next screenful. If you want less than a screenful of lines, type z.11 to display five lines before and five lines after the current line. (Typing z.n, when n is an odd number, displays a total of n lines, centered about the current line; when n is an even number, it displays n-1 lines, so that the lines displayed are centered around the current line.) You can give counts after other commands; for example, you can delete 5 lines starting with the current line with the command d5.
To find things in the file, you can use line numbers if you happen to know them; since the line numbers change when you insert and delete lines this is somewhat unreliable. You can search backwards and forwards in the file for strings by giving commands of the form /text/ to search forward for text or ?text? to search backward for text. If a search reaches the end of the file without finding text, it wraps around and continues to search back to the line where you are. A useful feature here is a search of the form /^text/ which searches for text at the beginning of a line. Similarly /text$/ searches for text at the end of a line. You can leave off the trailing / or ? in these commands.
The current line has the symbolic name dot (.); this is most useful in a range of lines as in .,$p which prints the current line plus the rest of the lines in the file. To move to the last line in the file, you can refer to it by its symbolic name $. Thus the command $d deletes the last line in the file, no matter what the current line is. Arithmetic with line references is also possible: the line $-5 is the fifth before the last and .+20 is 20 lines after the current line.
You can find out the current line by typing ‘.=‘. This is useful if you want to move or copy a section of text within a file or between files. Find the first and last line numbers you want to copy or move. To move lines 10 through 20, type 10,20d a to delete these lines from the file and place them in a buffer named a. edit has 26 such buffers named a through z. To put the contents of buffer a after the current line, type put a. If you want to move or copy these lines to another file, execute an edit (e) command after copying the lines; following the e command with the name of the other file you want to edit, that is, edit chapter2. To copy lines without deleting them, use yank (y) in place of d. If the text you want to move or copy is all within one file, it is not necessary to use named buffers. For example, to move lines 10 through 20 to the end of the file, type 10,20m $.
Syntax
Options
—, -s | Suppress all interactive user feedback. This is useful when processing editor scripts. |
-l | Set up for editing LISP programs. |
-L | List the name of all files saved as the result of an editor or system crash. |
-R | Read only mode; the read-only flag is set, preventing accidental overwriting of the file. |
-r filename | Edit file name after an editor or system crash. (Recovers the version of file name that was in the buffer when the crash occurred.) |
-t tag | Edit the file containing the tag tag and position the editor at its definition. |
-v | Start up in display editing state using vi. You can achieve the same effect by typing the vi command itself. |
-V | Verbose mode. When ex commands are read by means of standard input, the input will be echoed to standard error. This may be useful when processing ex commands within shell scripts. |
-x | Encryption option; when used, edit simulates the X command of ex and prompts the user for a key. This key is used to encrypt and decrypt text using the algorithm of the crypt command. The X command makes an educated guess to determine whether text read in is encrypted or not. The temporary buffer file is encrypted also, using a transformed version of the key typed in for the -x option. |
-wn | Set the default window size to n. This is useful when using the editor over a slow speed line. |
-C | Encryption option; same as the -x option, except that vi simulates the C command of ex. The C command is like the X command of ex, except that all text read in is assumed to have been encrypted. |
+command, —command | Begin editing by executing the specified editor command (usually a search or positioning command). |
filename | The name of the file that you want to edit. |
Examples
Loads myfile.txt for editing, and places the user at the editing command prompt.
Related commands
ed — A simple text editor.
ex — Line-editor mode of the vi text editor.
vi — Text editor based on the visual mode of ex.
Источник
Best Text Editors for Linux Command Line
Last updated July 20, 2020 By Munif Tanjim 21 Comments
A text editor is a must-have application for any operating system. We have no dearth of the best modern editors for Linux. But those are GUI based editors.
But, for a lot of good reasons, you still need to utilize the command-line. Not just for System Administrators but for the average user as well. Hence, text editors tailored for the terminal is definitely something important.
Here, I’ll compile a list of the best command line text editors for Linux.
Classic Command Line Text Editors
These are some of the most commonly-used and powerful command-line text editors for Linux.
1. Vim
If you’re on Linux for quite some time, you must have heard about Vim. Vim is an extensively configurable, cross-platform, and a highly efficient text editor.
It may not be suitable for newbies but it’s something every aspiring Linux System administrator should get comfortable with. You will probably find it pre-installed in your Linux distribution. It is extremely popular for its wide range of advanced features.
Vim can be quite agonizing for first-time users. I remember the first time I tried to edit a text file with Vim, I was completely puzzled. I couldn’t type a single letter on it and the funny part is, I couldn’t even figure out how to close this thing. If you are going to use Vim, you have to be determined for climbing up a very steep learning curve.
But after you have gone through all that, combed through its official documentation, and practice the commands/operations, you’ll find it worth all the time spent. Not to forget, you can use it for basic text editing or leverage its support for hundreds of programming languages, extensions and file formats.
How to install it?
If you don’t have it installed already, you can just try typing in the command (on Debian-based systems) to install it:
You can also find it listed in your software center of the Linux distribution you use. In either case, just head on to its official download page to get more details.
2. GNU Emacs
GNU Emacs is undoubtedly one of the oldest and versatile text editor out there. In case you didn’t know, it was created by GNU Project founder Richard Stallman.
Emacs is cross-platform and has both command-line and a graphical user interface. It is also very rich with various features and, most importantly, extensible.
Just as Vim, Emacs too comes with a steep learning curve. But once you master it, you can completely leverage its power. Emacs can handle just about any types of text files. The interface is customizable to suit your workflow. It supports macro recording and shortcuts as well.
The unique power of Emacs is that it can be transformed into something completely different from a text editor. There is a large collection of modules that can transform the application for using in completely different scenarios, like — calendar, news reader, word processor etc. You can even play games in Emacs!
How to install it?
You should find it in your software center or if you prefer using the terminal on Ubuntu-based distros, you can type in:
You can find more information on it in their official download page. Once you’re done installing, you need to type in a specific command to launch emacs in your terminal, which is:
Basically, this command instructs to not include any window to launch the program but the terminal itself.
3. Nano
When it comes to simplicity, Nano is the one. Unlike Vim or Emacs, it is suitable for beginners to get used to quickly.
If you want to simply create & edit a text file, look no further.
The shortcuts available on Nano are displayed at the bottom of the user interface. It is minimal and perfectly suitable for editing system & configuration files. For those who don’t need advanced features from a command-line text editor, Nano is the perfect pick.
If interested, you can learn how to use Nano text editor in our beginner’s guide.
How to install it?
For the most part, Nano editor should come in pre-installed on Ubuntu-based distributions. If it isn’t there, you can simply visit the official download page to get the binaries for the distribution you want.
Modern Text Editors For Command Line
Here, I shall list some terminal-based text editors that bring something new to the table or focus on making things easier.
4. ne – The Nice Editor
When compared to the classic and popular text editors, ne (the nice editor) is a good alternative which tries to offer advanced functionalities and making it easier to use them.
In other words, it’s a simpler alternative to Vim/Emacs offering you powerful features. It is being actively maintained — but not as regular as you’d expect. However, I tried it installing on Pop OS 20.04 and it worked just fine. You can explore more about it in their GitHub page.
Of course, unless you test it extensively, you should take it with a pinch of salt.
How to install it?
You should find it available in the official repositories of your Linux distribution. For Ubuntu-based distros, you can install it using the command:
You can also check out their official download page for more information on other Linux distributions.
5. Neovim
Neovim is a fork of Vim that aims to add more extensibility while simplifying it. If you’re comfortable with Vim, you will be good to go using Neovim.
The project is being actively maintained and the progress is promising so far. Of course, unless you’re acquainted with how Vim works, you may not notice the striking difference between the two.
But, overall, Neovim tries to take Vim up a notch.
How to install it?
For Ubuntu-based distros, you can simply install it by typing:
For other Linux distributions or platforms, you may refer to its official installation instructions to get started.
To give you a head start, I must mention that when using the terminal, you will have to type the following to launch it (instead of neovim):
6. Tilde
Tilde is a terminal-based text editor tailored for users who are normally used to GUI applications.
Unlike other options mentioned in this list — this may not be a power tool. But, for basic text editing operations, this is very easy to use. You do have some advanced functionality – but that’s not something to compare with Vim/Emacs.
If you wanted to try something easy-to-use and different, this is the one I’d recommend you to try.
How to install it?
For Ubuntu-based distros, you can simply type the following command in the terminal:
For information on other Linux distributions, you may refer to their GitHub page or the download page to explore more about it.
Wrapping Up
If you are an experienced Linux user, you must be aware of the popular options mentioned in this list.
Even though there are some good-old options like WordGrinder and JOE — I’m afraid that they are no longer actively maintained.
What do you think of the best command line text editors for Linux listed in this article? Did I miss any of your favorites? Let me know your thoughts in the comments below!
Like what you read? Please share it with others.
Источник