The Linux operating system - editing text files

0 34
Avatar for valo
Written by
3 years ago
Topics: Linux, Technology, Text, Editor, Vim, ...

Several days ago I wrote about copying and moving files, as well as navigating through directories from the command line. Now I would like to proceed with actually creating new ones and editing them.

It's a heated topic among Linux users what is the best text editor. There are three popular options and the user of each is 100% certain that his preference is the correct one. This hints clearly that in the end, it doesn't matter which one you take, as long as you learn its tricks and let it make your life easier. Indeed, I'm not an exception. I also have a favourite.

The three most commonly used command-line editors for Linux: vim, nano and emacs. (screenshots of my terminal)

Command-line editors

The most important feature of a command-line editor is apparently to let you open, modify and save text files. They are not MS Word where you type and click buttons with your mouse. You need to navigate using your keyboard. Cutting, copying and pasting is, of course, possible. So are undo and redo. You can search and replace text.

The three beasts

I will start with my favourite - vim. It's the first screenshot on the left above. Click on the picture to see it in full view. I like the variety of keyboard shortcuts that one can define as well as the wide variety of features that are built into it. However, be prepared that it takes a bit of time to learn how to use it. One can write a whole article just to give a basic introduction to vim, and a series of articles on various tips and tricks. I won't go into such detail unless someone requests it. Many beginners are intimidated by vim. They try typing something but the text doesn't appear. Some mysterious events happen. And how on Earth to exit? Vim is based on several modes. It starts in what is called normal mode. One can navigate through the file, replace and delete characters and words, for example. But in order to add text, one needs to go into insert mode by pressing the letter i or o, or pressing the Insert button from the keyboard. When ready with typing, you probably want to save your work. This doesn't work in insert mode. You need to press the Escape button from the keyboard to go back to normal mode. Commands can be given to vim in normal mode. Saving the file requires typing :w and pressing Enter. Alright, we're done, now how to get back? This requires typing :q. There is also visual mode where it's possible to select multiple lines of text, move them around, delete them, align them, or whatever.

The home screen of vim that appears if you just call it from command line (screenshot).

The next editor is nano. It appears more simplistic and unlike vim, there are no separate modes. When you open a file, you can directly start typing into it. It also kindly gives instructions on the bottom of the terminal how to use it. The keyboard shortcuts are given as, e.g., ^O. The caret symbol stands for the Control key from the keyboard. Control and O makes nano write the file. To me personally, it's a bit too simplified. Yes, it does the job in a simple manner but I can't configure complicated sets of commands to be done by the press of a single button.

The home screen of nano (screenshot of my terminal).

Emacs is the third very popular editor. Note that by third I don't imply the third most popular. It's just a random order in my article. Emacs is an editor rich in functionality. I admit that I should have familiarised myself better with it. Similarly to vim, starting it doesn't allow you to start typing right away. It even has a menu bar. Some call emacs a mini operating system. It has a file manager - so you can browse your files without exiting, you can read RSS feeds and there is even tetris! I had a quick look around some tutorials and I must say that I'm myself impressed with it. Emacs is customisable to ones wishes and like vim, there are so many features that it takes year to master them all if ever. If that's not enough, there are extensions available for download to pamper yourself. Emacs kindly provides a tutorial to help you get started. I had fun going through it. And I enjoyed the tetris! Go ahead and test it out yourself. Oh, and when you're eventually done and want to quit, press Control, X and C from your keyboard and you are out.

The home screen of emacs (screenshot of my terminal).

All three text editors have their benefits. I clearly expressed my preference, though, I must admit that I'd like to test emacs more. I don't think it will replace vim for me after so many years, yet it's a pleasure to see something so refined and full of features. Oh, and after spending enough years on the command line, you will end up open files with your editor of choice rather than some program with a graphical interface. Speaking of which, there is a graphical interface for both vim and emacs but... I don't like them. I want to just exist in the text-only world.

5
$ 4.21
$ 4.03 from @TheRandomRewarder
$ 0.05 from @Jnavedan
$ 0.05 from @nomadghada
+ 3
Sponsors of valo
empty
empty
empty
Avatar for valo
Written by
3 years ago
Topics: Linux, Technology, Text, Editor, Vim, ...

Comments