Using editors

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:

  • Do you want to use a mouse or other pointer, or do you want to use just the keyboard?
  • Do you need to type international characters, accents, and diacritical marks, or just ASCII?
  • How do you like to invoke commands? In some editors, you type a single character, in others, you press a keychord, and in yet others, you click a button or select an item from a menu.

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, 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.

If you start a graphical editor from the command line, you 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.

Supported editors

The BlackBerry 10 OS includes and supports these editors:

vi (or elvis)
A powerful, but somewhat cryptic text-based editor found in most—if not all—UNIX-style operating systems. It's actually the Visual Interface to an editor called ex.

On BlackBerry 10 OS, vi is a symbolic link to elvis. To start vi, type:

elvis 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:

  • I or i to insert at the beginning of the current line or before the cursor
  • A or a to append text at the end of the current line or after the cursor
  • O or o to open a new line above or below the cursor

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 common vi commands:

To: Press:
Leave vi without saving any changes :q!
Save the current file :w
Save the current file, and then exit :wq, :x, or ZZ
Move the cursor to the left h
Move the cursor to the right l
Move the cursor up one line k
Move the cursor down one line j
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

In some implementations of vi—including BlackBerry 10 OS'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 BlackBerry 10 OS, vi is actually a link to elvis in Utilities.

Integrated Development Environment (IDE) editors
On Linux and Windows, the Integrated Development Environment (IDE) incorporates various specialized editors for creating C and C++ programs, buildfiles, and so on. For more information, see Build, test, and deploy your app.

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, 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

Last modified: 2014-11-17



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus