Caution: This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.

Using Editors

This chapter includes:

Choosing an editor

An editor is a utility designed to view and modify files. Editors don't apply any persistent formatting to viewed text, although many use colors or styles to provide additional contextual information, such as type information in source code files. For example, if you're editing C code, some editors use different colors to indicate keywords, strings, numbers, and so on.

Which editor you use is largely a question of personal taste:

One important distinction between the editors is whether they're text-based or graphical. Text-based editors are more flexible because you can use them in text mode, in a console window in Photon, remotely via telnet or qtalk, and so on; graphical editors tend to be friendlier and easier to use, but can run only in a graphical window.


Note: If you start a graphical editor from the command line, you'll probably want to start it as a background process -- by adding an ampersand (&) to the command line -- so that you can continue to use the current window while the editor is still open. If you're using a text-based editor, start it as a foreground process by omitting the ampersand.

Neutrino includes these editors:

vi
A powerful, but somewhat cryptic text-based editor that you'll find in most -- if not all -- UNIX-style operating systems.
ped
The Photon editor, an easy-to-use graphical editor.
qed
The QNX editor, a fullscreen, text-based editor that has been around since the time of QNX 2, and still has many devotees. We don't recommend that you use it, but you can find out more about it in the QED -- Fullscreen Editor guide in your online documentation.

Note: The QNX Momentics development suite features an Integrated Development Environment (IDE) that incorporates various specialized editors for creating C and C++ programs, buildfiles, and so on. For more information, see the IDE User's Guide.

You'll find other editors in the third-party repository, including AbiWord, Emacs, JED, Vim, and Workspace.

Supported editors

Neutrino includes and supports these editors:

vi

You'll find a version of vi on every UNIX-style operating system. It's actually the Visual Interface to an editor called ex. To start vi, type:

vi filename

The vi editor has two modes:

Command mode
The keyboard is mapped to a set of command shortcuts used to navigate and edit text; vi commands consist of one or more letters, but ex commands start with a colon (:).
Insert mode
Lets you type normally.

To switch to command mode, press Esc; to switch to input mode, press one of:

The two modes can make vi very confusing for a new user; by default, vi doesn't tell you which mode you're in. If you type this when you're in command mode:

:set showmode

the editor indicates the current mode, in the lower right corner of the display. If you always want this option set, you can add this command -- without the colon -- to the profile for vi, $HOME/.exrc.

Here are some of the vi commands that you'll use a lot:

To: Press:
Leave vi without saving any changes :q!
Save the current file :w
Save the current file and exit :wq, :x, or ZZ
Move the cursor to the left h (see below)
Move the cursor to the right l (see below)
Move the cursor up one line k (see below)
Move the cursor down one line j (see below)
Move to the beginning of the next word w
Move to the end of the current or next word (depending on the cursor position) e
Move to the beginning of the current or previous word (depending on the cursor position) b
Page back Ctrl-B
Page forward Ctrl-F
Yank (copy) the current line yy
Yank from the cursor to the end of the current word yw
Delete from the cursor to the end of the current word dw
Delete the current line dd
Paste text before the cursor P
Paste text after the cursor p

Note: In some implementations of vi -- including Neutrino's -- you can also use the arrow keys to move the cursor, whether you're in command or input mode.

You can combine the commands to make them even more useful; for example, type a number before dd to delete several lines at once. In addition, vi has 26 named buffers that let you easily cut or copy and paste different blocks of text.

You can find numerous resources, tutorials, and command summaries online. In Neutrino, vi is actually a link to elvis; see the Utilities Reference.

ped

The Photon editor, ped, is a simple graphical editor that's similar to editors that you'll find on other windowing systems. It runs in a Photon window, so you can't access ped through text consoles or console-only systems.


Editors; ped


The Photon editor, ped.

If you need to type international characters, accents, and diacritical marks, you'll find ped useful, because it supports UTF-8. To type international characters in ped, use the compose sequences described in "Photon compose sequences" in the Unicode Multilingual Support appendix of the Photon Programmer's Guide.

To start ped, choose Editors-->Ped from the desktop's Launch menu, or type:

ped [filename] &

in a pterm terminal window. For more information about using ped, see the Utilities Reference.

Third-party editors

The third-party repository includes at least these editors:

Note that we don't support these editors (or anything else in the third-party repository).

AbiWord

AbiWord is a free word-processing editor that you can use to edit Microsoft Word documents. It's supported on a variety of operating systems, including Neutrino.

To start this editor, choose Editors-->AbiWord from the desktop's Launch menu. The interface looks like this:

AbiWord editor

For more information, see http://www.abisource.com.

Emacs

Emacs (Editor macros) is a powerful and extendable editor that's available on many systems. Although it can be initially confusing, Emacs offers a wide variety of useful builtin features to supplement its text-editing capabilities, including searching and mail. You can also expand Emacs's core functionality by writing your own macros in Emacs Lisp.

To start Emacs, type:

emacs [filename]

Emacs commands are usually keychords or a series of keychords. For example, if you're told to press Ctrl-X Ctrl-C, you should press Ctrl-X, release it, and then press and release Ctrl-C. The Ctrl key is frequently abbreviated as simply C, so the above command could be written as C-X C-C. If a command starts with Esc, you press and release the Esc key, and then press the next key in the command.

Here are some of the commands:

To: Press:
Leave Emacs Ctrl-X Ctrl-C
Open a file Ctrl-X Ctrl-F filename
or Ctrl-X 4 f filename
Save a file Ctrl-X Ctrl-S
Move to the end of the current word Esc F
Move to the beginning of the current word Esc B
Page back Esc V
Page forward Ctrl-V
Delete the current word Ctrl-D
Delete to the end of the current line Ctrl-K
Set a mark Ctrl-@ (i.e. Ctrl-Shift-2)
Copy text from the mark to the cursor Ctrl-W
Paste text Ctrl-Y

To learn more about Emacs, see:

JED

JED is a lightweight implementation of Emacs designed to operate in a command window. All of the commands and comments for Emacs apply to JED, but JED is more flexible because it doesn't require a windowing environment.

To start JED, choose Editors-->JED from the desktop's Launch menu, or type:

jed [filename]

For more information about JED, see www.jedsoft.org/jed/.

Vim

Vim (vi Improved) expands on the power and speed of vi, but makes the user experience more comfortable, by including:

Vim has a gentler learning curve than vi and tolerates or minimizes the effects of common mistakes, without losing any of vi's speed, flexibility, or power.

To start Vim, choose Editors-->Vim from the desktop's Launch menu, or type:

vim [filename]

To learn more about Vim, see www.vim.org.

Workspace (ws)

Workspace is a Photon-based editor that accommodates many programming languages, but is particularly useful for developing in C. Workspace uses the make, gdb, and ctags utilities. The editor also incorporates terminals, web browsers, an image viewer, a file manager, an archive viewer, and other extras:

Editors; Workspace

Workspace provides font support and word-wrapping, and lets you edit hundreds of files simultaneously. You can use regular expressions when searching.

Workspace supports context highlighting, and you can customize it. This can make your code more readable and reduces the likelihood of coding errors. You can configure individual colors for dozens of cases, but the interface can make customizations time-consuming.

New users might find that the friendly interface "hides" some of the more powerful features, although the basic features are intuitive.

Workspace supports various languages, including English, French, Japanese, Chinese, and Russian. To type international characters, use the compose sequences described in "Photon compose sequences" in the Unicode Multilingual Support appendix of the Photon Programmer's Guide.

To start Workspace, select Editors-->Workspace from the desktop's Launch menu, or type:

ws [filename] &

on the command line. The basic commands are the same as ped's.

For more information, or to download the latest version of Workspace, see http://pages.infinit.net/micbel/.

Specifying the default editor

Some system processes ask you to use an editor to provide some information. For example, if you check something into a version-control system such as CVS, you're asked to explain the changes you made. Such processes use the VISUAL or EDITOR environment variable -- or both -- to determine which editor to use; the default is vi.

Historically, you used EDITOR to specify a line-oriented editor, and VISUAL to specify a fullscreen editor. Applications might use one or or both of these variables. Some applications that use both use VISUAL in preference to EDITOR when a fullscreen editor is required, or EDITOR in preference to VISUAL when a line-oriented editor is required.

Few modern applications invoke line-oriented editors, and few users set EDITOR to one, so you can't rely on applications to give preference one way or the other. For most uses, we recommend that you set VISUAL and EDITOR to the same value.

Once you've tried various editors, you can set these environment variables so that your favorite editor becomes the default. At the command-line prompt, type:

export VISUAL=path
export EDITOR=path

where path is the path to the executable for the editor. For example, if you want to use jed as the default editor, type:

$ which jed
/usr/local/bin/jed
$ export VISUAL=/usr/local/bin/jed
$ export EDITOR=/usr/local/bin/jed

To check the value of the EDITOR environment variable, type:

echo $EDITOR

You'll likely want to set these variables in your profile, $HOME/.profile, so that they're set whenever you log in. For more information, see "$HOME/.profile" in Configuring Your Environment.