The most basic task you perform is editing textfiles. In Linux, all configuration can be done using the configurations files that are readable by humans. While distributions may include other tools to configure the system, if you know how to deal with the bare config-files, you will have no problems when switching distros.
Plain text files and their purpose
Probably the most obvious reason to edit plain text files with an “ASCII editor” (this term is inaccurate, since there are many more characters that can be in those files is system configuration. In DOS and Windows, there were INI-files for configuration. Linux uses textfiles stored in /etc for system’s defaults and also checks other locations for user-preferences in the same format.
Another field where plain text files are useful is publishing. Whether it is HTML, XML, LaTeX, DocBook or any other modern markup language, the sourcefiles are all human-readable (well more or less at least and to be edited with regular texteditors.
Also, if you write your own shellscripts or programs, you will need an editor like one of those that are mentioned below.
more or less
Before editing files, we might want to take a look at the contents. The most used programs to view textfiles are
cat is short for “concatenate”. It takes files and, well, concatenates them. The result is printed to the standard output, which is usually the screen. So, if we simply
cat myfile, the command will print the contents of myfile to the screen. This is ok, as long as the file has no more lines than the screen has. If the file is longer, we need a “pager”.
more prints files pagewise to the screen, waiting for keystrokes before proceeding. When more has reached the end of the file, it exits. Thus, you can only move “back up” (using ‘b’) in the file as long as the last line has not been displayed, yet. Use “?” to see the help.
less has more going for it than
more. The up and down arrows work for going back or forward line by line, space and backspace move by page. It does not exit at the end of the file. You need to press
q to quit the program. Help is “h”.
pg is another pager with functionality similar to
less. Help is “h”.
Note that you can look at multiple files with these pagers. Check the help to see how to go to the next file. For example:
Tip for copy and paste in Linux
This tip works in any program, under X11 and console (if you have configured gpm): To copy text, simply highlight it with your mouse. To paste it, just press the middle mouse button. Once you get used to this quick way of copy and paste, you will miss it whenever you need to work on “that other OS”.
This method does not interfere with cut/copy/paste from the applications menu. Just think of it as a second clipboard.
We have compiled many ways to do copy and paste in Linux on our Copy & Paste page.
vi and vim
Being the oldest editor on the block, ‘vi’-basics are a must for anybody using Unix, Linux or the like. There are even some instances, where you are “dropped” into a vi-like environment. The
visudo commands are two examples. So you need at least some basic moves in
Most importantly, pressing <Esc> :q! <Return> will get you out of vi without saving anything (read: Without trashing your system. )
You move the cursor with your right hand, using the keys h, j, k and l. This way the hand can stay in its regular position, using the index-finger for the direction that is used most: Down. (The cursor-keys might also work, but don’t rely on them.)
In order to actually edit the file, press i to get in to insert-mode and type away. <Esc> gets you back into command-mode to move around. To save your changes and exit, press <Esc> :wq <Return>
For help: <Esc> :h Get out of help with :q
If you work in X11, you might take a look at
kvim, the Gnome and KDE versions of vi. With them, you have an editor with menus and everything, but can get used to the keystrokes. If you don’t know how to do something with the keyboard, look in the menus. They have the corresponding keys right next to the options.
For the tutorial on vi simply type
vimtutor from the shell. (Strictly speaking, this is the tutorial for
vim - Vi IMproved, but on most systems vi is a link to vim and the basic functions are the same.)
Another very popular editor with a very high “geek-ranking” is
emacs. You either love it or hate it, so take you pick:
Most importantly, pressing <Ctrl>x followed by <Ctrl>c and n<Return>yes will get you out of emacs without saving anything (read: Without trashing your system ).
You move the cursor by holding down <Ctrl> and pressing n, p, f or b, which is for next, previous, forward and backward. (The cursor-keys might also work, but don’t rely on them.)
In order to edit the file, just type away. To save your changes and exit, press <Ctrl>x<Ctrl>s<Ctrl>x<Ctrl>c If you work in X11,
emacs starts up in a GUI; so you have an editor with menus and everything, but can get used to the keystrokes. If you don’t know how to do something with the keyboard, look in the menus. They have the corresponding keys right next to the options.
emacs-tutorial, start it up and press C-h t (That is <Ctrl> and h simultaneously and after that t).
Wordstar like editors
There are several editors using the commands that come from the Wordstar word-processor many are still used to. If that is a feature for you, then you know them already and do not need a tutorial. So I will skip the quick run-through
The curious find a listing of the Wordstar-Keybindings in
man e3. A popular editor using these keys is joe.
joe are small editors that can disguise itselves as wordstar, emacs, vi or others, depending on how you call it on the command line. See the manpages for details
There are many more editors that follow their own scheme. They might be even more suitable for those new to Linux. With all the learning one has to do in order to master Linux, one might not want to struggle with such basic applications like editors.
So here is a list of some other editors worth checking out; most of them are mouse and/or menu-driven:
- mc: Midnight Commander. A console file browser with intuitive text editor.
- kedit: KDE’s simple editor. (Mouse)
- kwrite: KDE’s word-like editor.(Mouse)
- Kate: KDE’s Advanced Text Editor. (Mouse)
- gedit: Gnome’s editor. (Mouse)
- pico, nano: Resemble some editor I used in DOS (gwbasic?)
- fte: Resembles the TurboPascal editor (Mouse, menus or F1 for keys)
- yudit: For Unicode editing. (Mouse)
- xcoral: X-GUI like they looked before Gnome & KDE (Mouse)