Text editors in terminal linux

Terminal Basics #9: Editing Files in Linux Terminal

Learn about editing text files in the Linux terminal using the beginner friendly Nano editor in the second last chapter of this series.

You have learned a bunch of file operations so far in this Terminal Basics series. You learned to create new files, delete existing ones, and copy and move them. It is time to take it to the next level. Let’s see how to edit files in the Linux terminal. If you are writing bash shell scripts, you can use the GUI text editors like Gedit and run them in the terminal. But at times, you’ll find yourself in a situation where you have to edit existing files in the terminal itself. For example, modifying config files located in the /etc directory. As a desktop Linux user, you could still use GUI editors for editing config files even as root. I’ll show it to you later. However, knowing how to edit files in the command line is better.

Editing files in Linux terminal

You may use the cat command if you just have to add a few lines at the bottom of an existing file. But in order to properly edit a file, you’ll need a proper text editor. There is simply no shortage of terminal-based text editors in Linux. Vi, Vim, Nano, Emacs are just a few of the most popular ones out there. But here is the thing. All of them have a learning curve involved. You don’t have the comfort of the GUI. You don’t have menus to interact with the editor with your mouse. Instead, you have to use (and remember) keyboard shortcuts. I find Nano to be a good starting point for new users. It is the default text editor in Ubuntu and many other Linux distributions. Of course, there is a learning curve, but it is not as steep as that of Vim or Emacs. It keeps on displaying the most relevant keyboard shortcuts at the bottom. This helps you navigate even if you don’t remember the exact shortcut. For this reason, I’ll be covering the absolute basics of the Nano editor here. You’ll learn all the essentials you need to know to start using Nano for editing files in the Linux terminal.

Using Nano editor

Nano can be used to edit text files, script files, program files etc. Please remember that it is not a word processor and cannot be used to edit docs or PDF files. For simple text editing of conf files, scripts, or text files, Nano is a great choice.

I’ll be using a text file named agatha_complete.txt. It consists of the names of all Agatha Christie’s books under her name. You can download it from this link if you plan to follow the steps on your system.

Читайте также:  Ios remote control linux

Источник

9 Best Text Editors for the Linux Command Line

Looking to edit files in the command line? These are the best editors for Linux terminal when you go all command line.

A text editor is a must-have application for any operating system. We have no dearth of good text editors on Linux. There is Gedit for quick text note down, there is VS Code for writing codes and more. But those are all GUI-based editors. What if you need to edit files in the terminal? Linux sysadmins need to do that on a daily basis. The average desktop Linux user may also need to edit files in the command line from time to time. Your distribution has a terminal-based text editor installed by default. But don’t restrict yourself to just that. Here, I have compiled a list of the best command line text editors for Linux. Feel free to experiment. Please note that this is not a ranking list.

1. Neovim

neovim text editor

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 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):

2. ne – The Nice Editor

ne the nice editor

When compared to the classic and popular text editors, ne (the nice editor) is a good alternative that tries to offer advanced functionalities and make 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. I tried it installing on Ubuntu 22.04 and it worked just fine. You can explore more about it on 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.

3. Vim

vim text editor

If you’ve been on Linux for quite some time, you must have heard about Vim. Vim is an extensively configurable, cross-platform, and 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 must be determined to climb 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.

Читайте также:  Deepin linux нет звука

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.

4. GNU Emacs

gnu emacs text editor

GNU Emacs is undoubtedly one of the oldest and versatile text editors 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 type of text file. 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 use 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 on 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 not to include any window to launch the program but the terminal itself.

5. MCEDIT

mcedit text editor

Midnight Commander is a fairly popular command line file manager and mcedit is an internal file editor of GNU Midnight Commander. It’s possible that many of us forget about this text editor, which is embedded inside the midnight commander utility. What this editor does, is open the files specified on the command line. The editor is based on the terminal version of cooledit – a standalone editor for X Window System.

How to install it?

6. Nano

nano text editor

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.

7. Tilde

tilde text editor

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.

Читайте также:  Linux sockets how to

How to install it?

For information on other Linux distributions, you may refer to their GitHub page or the download page to explore more about it.

8. Micro

micro text editor

Micro is an easy-to-use and highly customizable text editor. It also implements the universal copy/paste/save shortcuts (CTRL + C/V/S), which is rare in Linux terminal editors. Another cool offering from this text editor is its plugin system and internal command mode. Though it’s not feature-rich like Vim or other mature text editors, it can easily replace tools like Nano for occasional file editing in the terminal.

How to install it?

Micro is available in the repositories of all major distributions. In Ubuntu, you can install it with:

For other Linux systems, you can check out their GitHub page. We have an article on Micro text editor with a free cheat sheet for beginners if you are interested.

9. Helix

helix editor

Helix editor is a rust-based terminal text editor, which is both fast and efficient in resources. It uses Tree-Sitter for syntax highlighting, which helps boost the speed. The built-in language server support provides context-aware completion, diagnostics, and code actions. Helix editor offers several powerful tools, that can make it work like other editors like Vim and Emacs. On their website, they call themselves, a post-modern text editor, if Neovim is the modern Vim, then Helix is post-modern. For those who are interested, you can check out a dedicated Helix article

How to install it?

For Arch and its derivatives, there is a package available in the Community repository. Also, an AUR package is also available, which builds the master branch. For other Linux distributions, you have to use Cargo, the Rust Package Manager. You should be able to install Cargo using your distribution package manager Also, you need to make sure that Git is installed. On Ubuntu-based distributions, install both like this:

sudo apt install git cargo
git clone https://github.com/helix-editor/helix cd helix cargo install --path helix-term

Helix also needs its runtime files so make sure to copy/symlink the runtime/ directory into the config directory. This location can be overridden via the HELIX_RUNTIME environment variable.

ln -s $PWD/runtime ~/.config/helix/runtime
export PATH=$PATH:/home/team/.cargo/bin

Wrapping Up

If you are an experienced Linux user, you must have heard of most of the options mentioned in this list, if not all. For most users, going with Nano, Vim or Emacs should be good enough. The seasoned terminal dwellers could experiment with the likes of Micro, Helix or some other terminal text editors. That’s just my recommendation. And I would like to know yours. Which text editor do you prefer in the command line? Did you find a new, interesting one on this list? Share it in the comments.

DuckDuckGo hidden features

Hidden Features! 25 Fun Things You Can Do With DuckDuckGo Search Engine

What is TTY in Linux

What is TTY in Linux?

s-tui is used for CPU utilization monitoring

Beautifully Monitor CPU Utilization in Linux Terminal With Stress Terminal UI

Access Grub in VM

How to Access the GRUB Menu in Virtual Machine

FOSS Weekly 23.28

FOSS Weekly #23.28: China’s Linux OS, Linux Exit Codes, Btrfs Origins and More

cp command in Linux

Using cp Command in Linux

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

Источник

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