[[editors]]
MSc in Computing Science Lab Pages
Show pagesource Old revisions
Recent changes Index Login

# Editors

It's a good idea to spend some time picking a text editor that you like, as being familiar with your tools can save an enormous amount of time and effort. Here are some common Linux editors you might like to try. Don't worry if you're not a Linux command-line guru; you don't have to memorise a million keyboard shortcuts to speed up your work (although learning a few might not hurt).

Broadly speaking, editors come in two types; graphical editors and text-mode ones. The former (unsurprisingly) appear in a graphical window on your desktop, while the latter run directly in your console (i.e. they fill the window your command prompt was showing in). While text-mode may sound a bit primitive, it does have some benefits, particularly when remotely connecting to department machines over the internet. And if you think it still sounds bad, you don't want to know what people used before there was text-mode.

It's a good idea to have a passing familiarity with at least one text-mode editor, because you will almost certainly at some point find yourself needing to edit a text file without full access to a GUI. There are many horrible ways to experience `vi` for the first time (some would say they are all horrible), but without question the very worst is when dialling in to a college computer to try and fix the typo you just noticed in your project, five minutes before the submission deadline expires.

Here are some common editors, all found on the standard department Linux installation. Give them a try, and see which you like best.

## NEdit

NEdit is a relatively simple window-based editor that will be familiar to anyone who's used the more common editors for Windows (the basic keyboard shortcuts are very Windows-y). It has some basic syntax highlighting for things like C and C++, a tabbed user interface for multiple files, and a macro recording and editing facility. It doesn't have Prolog syntax highlighting as standard, though. There's a patch you can download, but it's not particularly sophisticated.

- The NEdit online manual

## Emacs

GNU Emacs is a much more complex graphical editor, but almost infinitely customisable. It has editing modes for every programming language you've ever heard of, plus most of the ones you haven't. These can be very useful, as the better ones are sufficiently intelligent that if you spot them highlighting or indenting something in a way that doesn't seem right, it's often a sign that you've made a mistake (catches a lot of missing semicolons, this).

Its command system is based heavily around “chords”, i.e. combined keypresses like ctrl-C. It takes this to rather more complex levels than you'll have seen before, though. For example, `C-w` means “hold `Ctrl` and press `w`” (so far, so simple). `C-x s` means “hold `Ctrl`, press `x`, then let go of `Ctrl` and press `s`”. `C-x C-c` means “hold `Ctrl`, press `x` then `c` and let go of `Ctrl`”. Here are some common commands to get you started:

`C-x s` | save file
`C-x C-w` | save as… (you will be prompted for a filename)
`C-x C-b` | see a list of currently open files (or “buffers” in emacs-speak)
`C-x C-c` | quit
`C-space` | Sets the “mark”. (see below)
`C-w` | cut, or “wipe”. Deletes highlighted text and keeps it in a temporary buffer.
`C-y` | paste, or “yank” (as in, “yank the text from the temporary buffer and put it here.”)
`C-g` | exit command. Very useful if you've got yourself into a mess with other commands, and want to start again.

The “mark” mentioned above is how you highlight text without using the mouse. Rather than holding shift and using the arrow keys as in many graphical editors, you use `C-space` to set a mark, then move the cursor; text between the cursor and mark will be highlighted, and can then be manipulated with other commands.

Here are some proper references should you decide you like Emacs and want to learn it properly:

- A quick guide to Emacs commands
- Emacs tutorial at linuxhelp
- Emacs FAQ at gnu.org

### Prolog Mode

Emacs can be used as a fairly full-featured IDE for Prolog, by enabling the Prolog mode. To do this you'll need to edit the `.emacs` file in your home directory (create one if it doesn't already exist). Full instructions on how to do this can be found at the Sicstus website. The Prolog mode enables syntax highlighting, hooks to run sicstus within emacs and some basic editing shortcuts. These features will be enabled by default for the Lexis tests.

## vi

`vi` is a text-mode editor, and if you've not come across it before, has a rather steep learning curve. It's referred to as a “modal” editor, because it operates in two modes - “insert” and “command”. In command mode, your keystrokes are interpreted as commands to the editor itself, while in insert mode the text you type becomes part of the document. This is why if you open a file and try to start typing, nothing happens; you're in command mode. The idea of this is to cut down on the chord-style commands found in Emacs and the like, which some people believe can cause RSI.

`vi` is far too powerful to helpfully describe here, so here are just a couple of commands to get you started. Remember you must be in command mode for these to work - press escape a couple of times if you're not sure.

`a` | enter insert mode (inserts after cursor)
`i` | enter insert mode (inserts before cursor)
`esc` | exit insert mode (returns to command mode)
`:w` | write file to disk (the colon is important)
`:q` | quit (will give an error if unsaved changes exist)
`:wq` | save and quit all at once.
`:q!` | quit without saving

That's enough for now; should you want to know more, these links contain much more information (particularly “Learning the vi editor”):

- A vi command summary sheet
- Learning the vi editor
- Why, oh WHY, do those #?@! nutheads use vi? (a bit evangelistic)

## Pico

Pico is a much (much) friendlier text-mode editor, having a list of common commands at the bottom of the screen, and only one mode to remember. However, it doesn't really have any of the features you'll need for heavy programming use, having been initially designed as an editor for writing emails. Handy for some very light editing when you don't have a graphical terminal, though.

- Pico quick reference

— Simon Coffey 2007/09/30 23:20

editors.txt · Last modified: 2007/10/09 16:43 by laborg
Show pagesource Old revisions
Back to top