Text Editors

If you don't know how to use a text editor in Linux then you can't really get too far. Reading 'README' files and 'INSTALL' files will be a necessity quite early on when learning Linux on the command line.

Text editors is a topic that many books have been written about. So, how do we cover it here and do it justice... well its tricky. We can at best get a superficial glimpse. We will arbitrarily choose a couple: nano and vim. We will also look at less which is not an editor but is a command that allows you to read files on your system.

less

Lets start with 'less'. This is a command that opens text files for reading only. If, for example, the directory you are currently working in has a file called 'README', then try this command:

[d:b] ~ # less README [Enter]
and you should see something like this in the terminal: less.jpg

To scroll use the up and down arrows, and to quit just type q

Remember that less will only allow you to read files. To edit files you will need a text editor or word processor (Sometimes there isn't much difference between the two).

vim

Vim is a text editor commonly used by programmers for working on code. When you type *vim* in the terminal you will see something like this: vim.jpg If you have *vi* installed you will see pretty much the same thing.

To open a file with *vim* it is best if you type the name of the file you wish to open after the vim command, so that vim opens with the file already loaded. For example if we wanted to read a "README" file in the same directory we are currently working in then just type:

[d:b] ~ # vim README [Enter]
This will open vim with the README file loaded as so: vim_muse.jpg

Now to scroll up and down the file use the up and down arrows on your keyboard. To quit vim press : then q then enter.

There is really a lot to 'vi' or 'vim', and I don't want to get into it here, but you should really know how to open a file (as above) and then edit a file. To edit a file in vim you need to first open the file, and then press i.

Now, I am imagining vim is quite a bit different to any text editor you have used before, so perhaps some explanation is needed. Vim opens a file initially as a read only file. This means that when you first open the file with vim you are not allowed to change the file. Vim has then a whole world of commands you can use to work on the file and most of the commands are executed by just typing a single letter, or they are in the format:

: command
Where 'command' is the name of the command you wish to use. The commands are all designated by shortcuts. An 'i' , for example, is short for 'insert'. The following is a table of vim commands you should know:
command                                 action
i  (only used in read-only mode)        insert text
:w (only used in read-only mode)        write changes to file
u  (only used in read-only mode)        undo changes
:q (only used in read-only mode)        quit vim

In addition, by pressing the esc (escape) key, you will tell vim to return to the original mode (read only). You must actually press escape before you execute any of the commands in vim. For example if I wanted to open the file "README" and then alter some text, I would do the following, starting with typing vim README in the terminal. This will open the "README" file as explained above. Then if I wish to edit the file, I use my arrow keys to navigate to where I want to insert or delete some text. I then press i, this will put me in the insertion mode and now anything I type will appear in the document itself. When I have finished making the changes I will then press the esc key, and finally to save the changes I press :w. This will write the file with the new changes. I then need to quit from vim so I press the escape key followed by :q.

Now find a file and experiment. If you haven't used something like vim before then it might take some getting used to, so spend some time working out for yourself how vim works before you really need to use it.