Editors in Linux
A text editor is like a word processor but without a lot of the features. All operating systems come with a text editor and linux is no exception. In fact linux comes with several text editors. The primary purpose of text editors is for writing a file in plain text with little or no formatting so that various other programs can read it. As students of computer systems you will use various text editors to generate code. Your choice of text editor will no doubt depend on such things as syntax highlighting, size of editor, debugging tools and various other features.
The standard text editor for Linux is called 'vi'. This is a program that comes from UNIX. There is a more recent version called 'vim' which means 'vi improved'. The problem with 'vi' or 'vim' is that a lot of people don't like it. You have to remember a lot of key combinations to do stuff that other text editors will do for you more easily. An alternative to 'vi' is 'Emacs'. Emacs is easier for first time users to become familar with and remembering key combinations is not required. Some of the popular editors are introduced below. Visit their homepages for additional information.
Emacs text editor
Emacs is one of the most popular and powerful text editors used on Linux (and Unix). You will use it to create, edit and save files. It comes with syntax highlighting for most main stream programming languages including c/C++. When Emacs works on a file, it doesn't actually work on the file itself. Instead it copies the contents of the file into a special Emacs work area called a buffer, where you can modify it. When you have finished working, you tell Emacs to save the buffer (i.e. to write the buffer's contents into the corresponding file). Until you do this, the file remains unchanged. There're a number of ways of opening emacs. Probably the simplest it to type emacs at the prompt in the terminal window. Remember to insert an ampersand "&" after the call to emacs so that the terminal can be used for other purposes following the call to emacs. Alternatively emacs can be opened by clicking start -> Applications -> emacs. This may of course vary depending on the version of linux that you are using and whether or not you are using a "GNOME" or "KDE" session. In order to become familiar with emacs it is recommended that you complete the tutorial on emacs. To view the tutorial simply launch emacs and the select help->emacs tutorial or alternatively use Ctrl-h t
Emacs is also very easy to customize. This involves changing the .emacs file.
Some Useful Emacs Commands
The most important commands listed below are in bold.
99% of your emacs experience will deal with these commands and therefore we have
made a quick reference guide which you may find handy to print out and keep on hand.
Cutting and Pasting:
Search and Replace:
Most Emacs commands are linked to keystrokes.
Using ^x ^c, you invoke save-buffers-kill-emacs, which saves your file
and quits Emacs. You can invoke any Emacs command using ESC x and
entering a command. ESC x lets you enter the window (it looks like a
blank line) at the bottom of the screen where you can enter commands. To
save a file and quit Emacs, you can use ^x ^c or use ESC x
save-buffers-kill-emacs. Emacs puts the hyphens in for you.
Emacs has command completion. If you want to save your file, but have forgotten the key sequence and the command, don't panic! Press ESC x, enter save,and press return. Emacs will list commands that start with save, and you can pick the one you want.
In is worth noting that emacs has a menu system like microsoft word. Therefore you are not required to learn all of the above comands.Customizing Emacs:
To customize Emacs, you need to write some Lisp code. It's not really that
difficult. The code should be put in a file named '.emacs' in your
home directory. Every time Emacs starts up, it automatically reads any Lisp code
you have put into your '.emacs' file unless you tell it not to
by specifying `-q' on the command line. (The emacs -q command gives you a plain, out-of-the-box Emacs.) .
To define a key binding, use an expression
of this form:
VI Text Editor
VI is a Visual Editor, hence the name. Visual editors are ones that let you see multiple lines of the document that you are editing as you edit it. This seems pretty common in most editors today, so the idea of a non-visual editor is a little strange. Examples of non-visual editors are sed, ex, ed, and edlin (the last one being the editor shipped with DOS.) VI was written by William Joy as part of the bsd distribution of Unix. It was later used by AT&T, and has been standard Unix since.
Why should I use VI
vi is default visual editor under Unix, and is therefore shipped with all versions of Unix following the mid 80's. This means that whenever you run across a machine that is running a Unix of some sort, you will know that you have a powerful editor at your fingertips. VI is a powerful editor. Also, once you know vi, you can edit files really quickly, as it is extremely economical with the keystrokes. Due to its different modes for inserting and issuing commands, it is much faster than most non-mode based editors. It is also a very small editor been only a few hundred k big. Furthermore, as an editor it allows a lot of interaction with the Unix operating system. It allows you to use many of the powerful Unix utilities from within vi. It's possible to, from within vi, kill off a list of specific processes that you want to kill. If you haven't given yourself permission to write to the file you're editing by accident, you can change the permission without leaving vi. vi works by having commands that work on objects. By learning only a few commands and a few objects you can learn how to do a lot of things, simply by combining the commands and the objects. Even the commands are separated into subcategories. For example, the movement commands and the modification commands are different. If you know that d is the command to delete, and j is the command to go down a line, and you know how to combine them (dj), you can delete down one line. When you use numbers it gets even more powerful. d5j will delete 5 lines below you. Then, once you learn the character for "paragraph" (}), you already know how to delete 5 paragraphs.
Problems with VI
VI can be somewhat hard to learn, and until you do so, it will be slow and painful. Once you learn it, it will be faster, but the process of learning it is slow. In fact for those people new to linux I would suggest that you use emacs for the time being at least. It's easier to learn.
To use VI type vi at the command prompt and your console should look like the image below.
Basic VI commands
The following list of commands will only suffice to get you started. For a more detailed explaination View the numerous tutorials and FAQs on the web the links for which are given below. If this is not to your satisfaction then consult any Unix book that will typically have an introductory chapter on the VI editor. Good luck!
Many of the vi commands take prefixes. For example 5h moves the cursor 5 places to the left.
Department of computer science and information systems
University of limerick, limerick, Eire
Department of Computer Science and Information Systems, University of Limerick, Limerick, Eire