Wednesday, May 14, 2008

Text Editors

For people coming from Windows a text editor is Notepad. In Linux you have many more choices, the top three I have run into are gedit, nano and vim. They are all three very different.

gedit is pretty close to Notepad in appearance. If you are not very comfortable operating in the terminal screen then this is the editor for you. It runs in a GUI and has menus to do everything you want. To launch it from the command line just type:

$gedit filename

nano does not run in a GUI but it does display your command choices at the bottom of the terminal window. It uses ^ to mean the Ctrl key on the keyboard. For example to save a file you would hit Ctrl+o (o is for "output"). To exit you hit Ctrl+x. To launch nano from the command line just type:

$nano
filename

vim is a favorite of old school Linux users. It is also what is used to edit crontab when you type $crontab -e and is used to display man pages. It does not display any command help so you have to know what you are doing. You can look at the man page for vim to get a lot of information, but to get started you will need to know how to open or create a file, how to edit the text, how to save and how to exit.

To open or create a file just type from the command line:

$vi
filename

If the file exists it will open it. If not it will create it. This actually works for all three editors.

To edit just start typing. In the lower left corner you will notice the word --INSERT-- appear. Hit the Insert key on the keyboard and it will change to --REPLACE--. Hit the Esc key and the corner will go blank. This is important because in order to save and exit that corner needs to be blank.

To save, make sure the corner is blank and type :w and hit enter. If the corner was blank this text will now appear in the corner. If not it will appear in the body of the text.

To exit, do the same as for saving except type :q and hit enter.
To exit without saving type :q! and hit enter.

Crazy. I don't use vim unless I absolutely have to. I typically use nano.

No comments: