[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

# 3. Reference

In this chapter we shall methodically overview each part of `ne`. It is required reading for becoming an expert user because some commands and features are not available through menus.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.1 Arguments

The main arguments you can give to `ne` are the names of files you want to edit. They will be loaded into separate documents. If you specifiy `--help` anywhere on the command line, a simple help text describing `ne`'s arguments will be printed.

The `+N` option causes `ne` to advance to the Nth line of the first document loaded. This option is fairly common among editors and text display programs like `vi` and `less`.

The `--no-config` option skips the reading of the key bindings and menu configuration files (see section Configuration). This is essential if you are experimenting with a new configuration and you make mistakes in it.

The `--macro filename` option specifies the name of a macro that will be started just after all documents have been loaded. A typical macro would move the cursor to a certain line.

The `--keys filename` option and the `--menus filename` option specify a name different from the default one (`'.keys'` and `'.menus'`, respectively) for the key bindings and the menu configuration files. Note that `ne` searches for these files first in the current directory, and then in your `'~/.ne'` directory.

The `--ansi` and the `--no-ansi` options manage `ne`'s built-in ANSI sequences. Usually `ne` tries to retrieve from your system some information that is necessary to handle your terminal. If for some reason this is impossible, you can ask `ne` to use a built-in set of sequences that will work on many terminals using the `--ansi` option (to be true, `ne` can be even compiled so that it uses directly the built-in set, but you need not know this). If you want to be sure (usually for debugging purposes) that `ne` is not using the built-in set, you can specify `--no-ansi`.

The `--no-syntax` option disables `ne`'s normal syntax highlighting capability. For most editing situations, this would be unnecessary, but for extremely large files it may be helpful. Syntax highlighting incurs small memory usage and processor overhead penalties for each line of text. The `--no-syntax` option eliminates that overhead.

Finally, the `--utf8` and `--no-utf8` options can be used to force or inhibit UTF-8 I/O, overriding the choice imposed by the system locale. Note, however, that in general it is more advisable to set the `LANG` environment variable to a locale supporting UTF-8 (you can usually see the locale list with `locale -a`). See section UTF-8 Support.

If you need to open a file whose name starts with `'--'`, you can put before the filename `'--'`, which will skip command recognition for the next word.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.2 The Status Bar

The last line of the screen, the status bar, is reserved by `ne` for displaying some information about its internal state. Note that on most terminals it is physically impossible to write a character on the last column of the last line, so we are not stealing precious editing space.

The status bar looks more or less like this:

    L:      31  C:      25   12% iabcwfpvurBMRPC*@8       20 /foo/bar

The numbers after `'L:'` and `'C:'` are the line and column of the cursor position. The first line and the first column are both number 1. Then, `ne` shows the percentage of lines before the current line (it will be 0% on the first line, and 100% on the last line).

Following that are a sequence of letters or dashes. These indicate the status of a series of flags which we shall look at later.

The hexidecimal digits following the flags give the code for the character at the cursor, and are displayed optionally (see section HexCode). If your cursor is at or beyond the right end of the current line, the code disappears.

The file name appearing after the character code is the file name of the current document. The left end of very long file names may be truncated to keep the right end visible. Of course, `ne` is keeping track internally of the complete file name. It is used by the `Save` command and as the default input for the `SaveAs` command. See section Save, and SaveAs.

The displayed line and column numbers, the percentage indicator and the character code change when the cursor moves. This fact can really slow down cursor movement if you are using `ne` through a slow connection. If you find this to be a problem, it is a good idea to turn off the status bar using either the `'Status Bar'` menu item of the `'Prefs'` menu or the `StatusBar` command. See section StatusBar. Alternatively you can turn on the fast GUI mode using either the `'Fast GUI'` menu item of the `'Prefs'` menu or the `FastGUI` command (see section FastGUI). In fast GUI mode the status bar is not draw in reverse, so some additional optimization can be done when refreshing it.

The letters after the line and column number represent the status of the flags associated with the current document. Flags that are off display a `'-'` instead of a letter. Each flag also has an associated command. The `Flags` command describes them all when you don't have this manual handy. Here's the list in detail:

`'i'`

  appears if the insert flag is true. See section Insert.

`'a'`

  appears if the auto indent flag is true. See section AutoIndent.

`'b'`

  appears if the back search flag is true. See section SearchBack.

`'c'`

  appears if the case sensitive search flag is true. See section CaseSearch.

`'w'`

  appears if the word wrap flag is true. See section WordWrap.

`'f'`

  appears if the free form flag is true. See section FreeForm.

`'p'`

  appears if the automatic preferences flag is true. See section AutoPrefs.

`'v'`

  appears if the verbose macros flag is true. See section VerboseMacros.

`'u'`

  appears if the undo flag is true. See section DoUndo.

`'r'`

  appears if the read only flag is true. See section ReadOnly.

`'B'`

  appears if the binary flag is true. See section Binary.

`'M'`

  appears if you are currently marking a block. See section Mark.

`'V'`

  can appear in place of `'M'` if you are currently marking a vertical block. See section MarkVert.

`'R'`

  appears if you are currently recording a macro. See section Record.

`'P'`

  appears if the PreserveCR flag is true. See section PreserveCR.

`'C'`

  appears if the CRLF flag is true. See section CRLF.

`'*'`

  appears if the document has been modified since the last save, or if the `Modified` command was issued to set this flag. See section Modified.

`'@'`

  appears if UTF-8 I/O is enabled. See section UTF8IO.

`'A/8/U'`

  denotes the current buffer encoding--US-ASCII, 8-bit or UTF-8. See section UTF8.

Note that sometimes `ne` needs to communicate some message to you. The message is usually written over the status bar, where it stays until you do something. Any action such as moving the cursor or inserting a character will restore the normal status bar.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.3 The Input Line

The bottom line of the screen is usually occupied by the status bar (see section The Status Bar). However, whenever `ne` prompts you for a command or file name or asks you to confirm some action, the bottom line becomes the input line. You can see this because a prompt is displayed at the start of the line, suggesting what kind of input is required. (Prompts always ends with a colon, so it is easy to distinguish them from error messages, which overwrite the status line from time to time.)

`ne` uses the input line in two essentially different ways: immediate input and long input. You can easily distinguish between these two modes because in immediate input mode the cursor is not on the input line, while for long input mode it is.

Immediate input is used whenever `ne` needs you to specify a simple choice that can be expressed by one character (for example, `'y'` or `'n'`). When you type the character, `ne` will immediately accept and use your input. Most immediate inputs display a character just after the prompt. This character is the default response, which is used if you just press the `Return` key. Note that immediate input is not case sensitive. Moreover, if a yes/no choice is requested, anything other than `'y'` will be considered a negative response.

Long input is used when a whole string is required. You can enter and edit your response to long inputs like a line of text in a document. Most key bindings related to line editing work on the command line exactly as they do in a document. This is true even of custom key bindings. Just edit as you are used to. Moreover, the you can paste the first line of the current clip using the keystroke that is bound to the `Paste` command, usually ``Control`-V`. If your long input is longer than the screen width, the input line scrolls to accomodate your text so you can input very long lines even on small monitors. (There is a limit of 2048 characters.)

The default response to a long input is the response you gave to the previous long input. Your first action when presented with a long input will either erase the default response or allow you to edit it. If the first thing you type is a printing character, the default response will be erased. Anything else (cursor movement for example) will allow you to edit it further.

Long input also lets you access your previous long input responses with the up and down cursor commands (or with wider movement commands, such as start/end of file, page up/down, etc.). Once you find a previous input you like, you can edit it further. Long input history is not document specific, so you can recall any of your inputs regardless of which document was active when you entered it. Furthermore, `ne` saves the most recent long inputs in `'~/.ne/.history'` when you end your `ne` session and loads them again when you begin another `ne` session.

When asked to input a number, you can choose between decimal, octal and hexadecimal notation in the standard way: a number starting with `'0'` is considered in octal, a number starting with `'0x'` is considered in hexadecimal, and in all other cases decimal base is assumed.

Whenever a file name is requested, you can type a partial file name and complete it with the `Tab` key. `ne` will scan the current directory (or the directory that you partially specified) and search for the files matching your partial suggestion. The longest prefix common to all such files will be copied on the input line (`ne` will beep if no completion exists). It's easier done than said--just try. If you press `Tab` again, you will be brought into the file requester: only the files and directories matching your partial specification will appear, and as usual you will be able to navigate and select a file or escape. See section The Requester. Note that `ne` considers the last word on the input line the partial file name to complete, no matter where the cursor is currently (you must use quotes if the name contains spaces, even if it is the only item on the input line).

Complete long input with the `Return` key. You can cancel a long input using `f1`, `Escape`, `Escape`-`Escape` or any key that is bound to the `Escape` command. The effect will vary depending on what your were requested to input, but the execution of the command requiring the input will stop.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.4 The Command Line

The command line is a typical (topical) way of controlling an editor on character driven systems. It has some advantages over menus in terms of access speed, but it is not desirable from a user interface point of view. `ne` has a command line that should be used whenever strange features have to be accessed, or whenever you want to use a command that you are familiar with and that is not bound to any key.

You have two ways to access the command line: by activating the menu and typing a colon (`':'`) or by typing ``Control`-K` (or any key that is bound to the `Exec` command; see section Exec). The first method will work regardless of any key binding configuration if you activate the menus with the `Escape` key since that key cannot be reconfigured. Of course, there is also a menu entry that does the same job.

Once you activate the command line, the status bar will turn into an input line (see section The Input Line) with a `'Command:'` prompt waiting for you to do a long input. In other words, you can now type any command (possibly with arguments), and when you press `Return`, the command will be executed.

If the command you specify does not appear in `ne`'s internal tables, it is considered to be the name of a macro. See section Basic Macros, for details.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.5 The Requester

In various situations, `ne` needs to ask you to choose one string from several (where "several" can mean a lot). For this kind of event, the requester is issued. The requester displays the strings in as many columns as possible and lets you move with the cursor from one string to another. The strings can fill many screens, which are handled as consecutive pages. Most navigation keys work exactly as in normal editing. This is true even of custom key bindings. Thus, for instance, you can page up and down through the list with ``Control`-P` and ``Control`-N` (in the standard keyboard configuration).

As with the input line (see section The Input Line), you can confirm your input with `Return` or escape the requester with `f1` or the `Escape` key (or whatever has been bound to the `Escape` command). Moreover, if you are selecting a file name there is a third possibility: by escaping with the `Tab` key, the file or directory name that the cursor is currently on will be copied on the input line. This allows to choose an existing name and modify it.

A special feature is bound to alphabetic characters: they move you to the next entry starting with the letter you typed. The search is case insensitive, and it continues on to the first string after having passed the last one.

An example of a requester is the list of commands appearing when you use the `Help` command. Another example is the file requester that `ne` issues whenever a file operation is going to take place. In this case, pressing `Return` while on a directory name will enter the directory. Note also that, should the requester take too long to appear, you can interrupt the directory scanning with ``Control`-\`. However, the listing will likely be incomplete.

Note that there are two items that always appear in the file requester: `'./'` and `'../'`. The first one represents the current directory and can be used to force a reread of the directory. The second one represents the parent directory and can be used to move up by one directory level.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.6 Menus

`ne`'s menus are extremely straightforward. The suggested way of learning their use is by trial and error, with a peek here and there at this manual when some doubts arise.

You activate menus with the `f1` key, or in case your keyboard does not have such a key, `Escape`, `Escape`-`Escape` or any key that is bound to the `Escape` command. Move around the menus pressing with the cursor keys and the page up/down keys (which move to the first or last menu item in a menu). You can also move around menus and menu items by pressing the alphabetic keys; a lower case letter will move to the first item in the current menu whose name starts with the given letter; an upper case letter will move to the first menu whose name starts with the given letter.

Each menu item of `ne`'s standard menu corresponds to a single command. In explaining what each menu item allows you to do, we shall simply refer you to the section that explains the command relative to the menu item.

If you plan to change `ne`'s menu (see section Changing Menus), you should take a look at the file `'default.menus'` that comes with `ne`'s distribution. It contains a complete menu configuration that clones the standard one.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.6.1 File

The File menu contains standard items that allow loading and saving files. Quitting `ne` (which doesn't save changes) or exiting `ne` (which does save changes) is also possible.

`'Open…'`

  See section Open.

`'Open New…'`

  See section OpenNew.

`'Save'`

  See section Save.

`'Save As…'`

  See section SaveAs.

`'Quit Now'`

  See section Quit.

`'Save&Exit'`

  See section Exit.

`'About'`

  See section About.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.6.2 Documents

The Documents menu contains commands that create new documents, destroy them, and browse through them.

`'New'`

  See section NewDoc.

`'Clear'`

  See section Clear.

`'Close'`

  See section CloseDoc.

`'Next'`

  See section NextDoc.

`'Prev'`

  See section PrevDoc.

`'Select…'`

  See section SelectDoc.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.6.3 Edit

The Edit menu contains commands related to cutting and pasting text.

`'Mark Block'`

  See section Mark.

`'Cut'`

  See section Cut.

`'Copy'`

  See section Copy.

`'Paste'`

  See section Paste.

`'Erase'`

  See section Erase.

`'Through'`

  See section Through.

`'Delete Line'`

  See section DeleteLine.

`'Delete EOL'`

  See section DeleteEOL.

`'Mark Vert'`

  See section MarkVert.

`'Paste Vert'`

  See section PasteVert.

`'Open Clip…'`

  See section OpenClip.

`'Save Clip…'`

  See section SaveClip.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.6.4 Search

The Search menu contains commands related to searching for specific contents or locations within a document.

`'Find…'`

  See section Find.

`'Find RegExp…'`

  See section FindRegExp.

`'Replace…'`

  See section Replace.

`'Replace Once…'`

  See section ReplaceOnce.

`'Replace All…'`

  See section ReplaceAll.

`'Repeat Last'`

  See section RepeatLast.

`'Goto Line…'`

  See section GotoLine.

`'Goto Col…'`

  See section GotoColumn.

`'Goto Mark…'`

  See section GotoMark.

`'Match Bracket'`

  See section MatchBracket.

`'Set Bookmark'`

  See section SetBookmark.

`'Unset Bookmark'`

  See section UnsetBookmark.

`'Goto Bookmark'`

  See section GotoBookmark.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.6.5 Macros

The Macros menu contains commands related to creating and using macros.

`'Record'`

  See section Record.

`'Stop'`

  See section Record.

`'Replace…'`

  See section Replace.

`'Play Once'`
`'Play Many…'`

  See section Play.

`'Play Macro…'`

  See section Macro.

`'Open Macro…'`

  See section OpenMacro.

`'Save Macro…'`

  See section SaveMacro.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.6.6 Extras

This menu contains a few special items that don't fit in obvious ways into other menus.

`'Exec…'`

  See section Exec.

`'Suspend'`

  See section Suspend.

`'Help…'`

  See section Help.

`'Refresh'`

  See section Refresh.

`'Undo'`

  See section Undo.

`'Redo'`

  See section Redo.

`'Undel Line'`

  See section UndelLine.

`'Center'`

  See section Center.

`'Paragraph'`

  See section Paragraph.

`'Adjust View'`
`'Center View'`

  See section AdjustView.

`'ToUpper'`

  See section ToUpper.

`'ToLower'`

  See section ToLower.

`'Capitalize'`

  See section Capitalize.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.6.7 Navigation

The Navigation menu contains commands related moving around in a document.

`'Move Left'`

  See section MoveLeft.

`'Move Right'`

  See section MoveRight.

`'Line Up'`

  See section LineUp.

`'Line Down'`

  See section LineDown.

`'Prev Page'`

  See section PrevPage.

`'Next Page'`

  See section NextPage.

`'Page Up'`

  See section PageUp.

`'Page Down'`

  See section PageDown.

`'Start Of File'`

  See section MoveSOF.

`'End Of File'`

  See section MoveEOF.

`'Start Of Line'`

  See section MoveSOL.

`'End Of Line'`

  See section MoveEOL.

`'Top Of Screen'`

  See section MoveTOS.

`'Bottom Of Screen'`

  See section MoveBOS.

`'Incr Up'`

  See section MoveIncUp.

`'Incr Down'`

  See section MoveIncDown.

`'Prev Word'`

  See section PrevWord.

`'Next Word'`

  See section NextWord.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.6.8 Prefs

The Prefs menu contains commands related to setting, storing, and using your prefered document flags.

`'Tab Size…'`

  See section TabSize.

`'Insert/Over'`

  See section Insert.

`'Free Form'`

  See section FreeForm.

`'Status Bar'`

  See section StatusBar.

`'Hex Code'`

  See section HexCode.

`'Fast GUI'`

  See section FastGUI.

`'Word Wrap'`

  See section WordWrap.

`'Right Margin'`

  See section RightMargin.

`'Auto Indent'`

  See section AutoIndent.

`'Preserve CR'`

  See section PreserveCR.

`'Save CR/LF'`

  See section CRLF.

`'Visual Bell'`

  See section VisualBell.

`'Load Prefs…'`

  See section LoadPrefs.

`'Save Prefs…'`

  See section SavePrefs.

`'Load AutoPrefs'`

  See section LoadAutoPrefs.

`'Save AutoPrefs'`

  See section SaveAutoPrefs.

`'Save Def Prefs'`

  See section SaveDefPrefs.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.7 Syntax Highlighting

Syntax highlighting is particularly useful for programming language text or other types of documents which have a strictly defined syntax. Colors indicate different syntactic categories of text according to the syntax definition in use.

Syntax definitions are stored in separate files. `ne` comes with a suite of syntax definitions for many popular programming languages. When you load a file, `ne` selects the appropriate syntax definition as determined by the filename extension in much the same way autoprefs are loaded.

If there is no matching syntax definition for the filename extension, or if the buffer you are editing has no filename yet, or you just want to try a different syntax definition, you can load and use the syntax definition of your choice with the `Syntax` command. It takes the syntax name as a parameter (for example, "`c`" for C syntax, "`cobol`" for COBOL, and "`perl`" for Perl) and searches first in your `~/.ne/syntax` directory, and if necessary the `syntax` subdirectory of `ne`'s global directory (`/usr/local/lib/ne` by default) for the syntax definition file.

Syntax definition files have a `.jsf` extension. Do not include that extension when using the `Syntax` command. The current distribution includes definitions for the following syntaxes: `4gl`, `ada`, `asm`, `awk`, `c`, `cobol`, `conf`, `csh`, `css`, `diff`, `fortran`, `haskell`, `html`, `java`, `joerc`, `jsf_check`, `jsf`, `lisp`, `lua`, `m4`, `mail`, `mason`, `matlab`, `ocaml`, `pascal`, `perl`, `php`, `ps`, `python`, `rexx`, `ruby`, `sed`, `sh`, `skill`, `sml`, `spec`, `sql`, `tcl`, `tex`, `troff`, `verilog`, `vhdl`, and `xml`.

You can of course create your own syntax definitions and store them in your `~/.ne/syntax` directory. A complete explanation of syntax specifications is beyond the scope of this document, but the existing definition files should prove to be useful examples. In particular, the `syntax/c.jsf` file contains some particularly helpful comments.

Syntax highlighting does incur a slight penalty in memory used per line of text, and it also consumes some CPU resources. For small to medium sized files you'll probably never notice. But for extremely large files--on the order of the size of your system's RAM--the difference could be significant. If you invoke `ne` with the `--no-syntax` parameter, `ne` will disable the syntax highlighting mechanism entirely, freeing up the memory and CPU otherwised consumed. (Note that if you are that tight on memory, you may need to disable the undo buffer as well. See section DoUndo.)

`ne` uses code from another editor--the GPL-licensed `joe`--for its syntax highlighting capabilities. Because of this fact, the syntax definition files are identical, even to the `.jsf` extention, which is an acronym for Joe's Syntax File. It's possible that if both `joe` and `ne` are installed on your system that they share the same syntax file directory. In any case, you can always use a syntax files conceived for `joe` with `ne`.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.8 Regular Expressions

Regular expressions are a powerful way of specifying complex search and replace operations. `ne` supports the full regular expression syntax on US-ASCII and 8-bit buffers, but has to impose a restriction on character sets when searching in UTF-8 text. See section UTF-8 Support.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.8.1 Syntax

The following section is taken (with minor modifications) from the GNU regular expression library documentation and is Copyright © Free Software Foundation.

A regular expression describes a set of strings. The simplest case is one that describes a particular string; for example, the string `'foo'` when regarded as a regular expression matches `'foo'` and nothing else. Nontrivial regular expressions use certain special constructs so that they can match more than one string. For example, the regular expression `'foo|bar'` matches either the string `'foo'` or the string `'bar'`; the regular expression `'c[ad]*r'` matches any of the strings `'cr'`, `'car'`, `'cdr'`, `'caar'`, `'cadddar'` and all other such strings with any number of `'a'`'s and `'d'`'s.

Regular expressions have a syntax in which a few characters are special constructs and the rest are ordinary. An ordinary character is a simple regular expression which matches that character and nothing else. The special characters are `'$'`, `'^'`, `'.'`, `'*'`, `'+'`, `'?'`, `'['`, `']'` , `'('`, `')'` and `'\'`. Any other character appearing in a regular expression is ordinary, unless a `'\'` precedes it.

For example, `'f'` is not a special character, so it is ordinary, and therefore `'f'` is a regular expression that matches the string `'f'` and no other string. (It does not match the string `'ff'`.) Likewise, `'o'` is a regular expression that matches only `'o'`.

Any two regular expressions a and b can be concatenated. The result is a regular expression that matches a string if a matches some amount of the beginning of that string and b matches the rest of the string.

As a simple example, we can concatenate the regular expressions `'f'` and `'o'` to get the regular expression `'fo'`, which matches only the string `'fo'`. Still trivial.

Note: special characters are treated as ordinary ones if they are in contexts where their special meanings make no sense. For example, `'*foo'` treats `'*'` as ordinary since there is no preceding expression on which the `'*'` can act. It is poor practice to depend on this behavior; better to quote the special character anyway, regardless of where is appears.

The following are the characters and character sequences that have special meaning within regular expressions. Any character not mentioned here is not special; it stands for exactly itself for the purposes of searching and matching.

`'.'`

  is a special character that matches anything except a newline. Using concatenation, we can make regular expressions like `'a.b'`, which matches any three-character string which begins with `'a'` and ends with `'b'`.

`'*'`

  is not a construct by itself; it is a suffix, which means the preceding regular expression is to be repeated as many times as possible. In `'fo*'`, the `'*'` applies to the `'o'`, so `'fo*'` matches `'f'` followed by any number of `'o'`'s.

  The case of zero `'o'`'s is allowed: `'fo*'` does match `'f'`.

  `'*'` always applies to the smallest possible preceding expression. Thus, `'fo*'` has a repeating `'o'`, not a repeating `'fo'`.

`'+'`

  `'+'` is like `'*'` except that at least one match for the preceding pattern is required for `'+'`. Thus, `'c[ad]+r'` does not match `'cr'` but does match anything else that `'c[ad]*r'` would match.

`'?'`

  `'?'` is like `'*'` except that it allows either zero or one match for the preceding pattern. Thus, `'c[ad]?r'` matches `'cr'` or `'car'` or `'cdr'`, and nothing else.

`'[ … ]'`

  `'['` begins a character set, which is terminated by a `']'`. In the simplest case, the characters between the two form the set. Thus, `'[ad]'` matches either `'a'` or `'d'`, and `'[ad]*'` matches any string of `'a'`'s and `'d'`'s (including the empty string), from which it follows that `'c[ad]*r'` matches `'car'`, et cetera.

  Character ranges can also be included in a character set, by writing two characters with a `'-'` between them. Thus, `'[a-z]'` matches any lower-case letter. Ranges may be intermixed freely with individual characters, as in `'[a-z$%.]'`, which matches any lower case letter or `'$'`, `'%'` or period.

  Note that the usual special characters are not special any more inside a character set. A completely different set of special characters exists inside character sets: `']'`, `'-'` and `'^'`.

  To include a `']'` in a character set, you must make it the first character. For example, `'[]a]'` matches `']'` or `'a'`. To include a `'-'`, you must use it in a context where it cannot possibly indicate a range: that is, as the first character, or immediately after a range.

  Note that when searching in UTF-8 text, a character set may contain US-ASCII characters only.

`'[^ … ]'`

  `'[^'` begins a complement character set, which matches any character except the ones specified. Thus, `'[^a-z0-9A-Z]'` matches all characters except letters and digits. Also in this case, when searching in UTF-8 text a complemented character set may contain US-ASCII characters only.

  `'^'` is not special in a character set unless it is the first character. The character following the `'^'` is treated as if it were first (it may be a `'-'` or a `']'`).

`'^'`

  is a special character that matches the empty string - but only if at the beginning of a line in the text being matched. Otherwise it fails to match anything. Thus, `'^foo'` matches a `'foo'` that occurs at the beginning of a line.

`'$'`

  is similar to `'^'` but matches only at the end of a line. Thus, `'xx*$'` matches a string of one or more `'x'`'s at the end of a line.

`'\'`

  has two functions: it quotes the above special characters (including `'\'`), and it introduces additional special constructs.

  Because `'\'` quotes special characters, `'\$'` is a regular expression that matches only `'$'`, and `'\['` is a regular expression that matches only `'['`, and so on.

  For the most part, `'\'` followed by any character matches only that character. However, there are several exceptions: characters which, when preceded by `'\'`, are special constructs. Such characters are always ordinary when encountered on their own.

`'|'`

  specifies an alternative. Two regular expressions a and b with `'|'` in between form an expression that matches anything that either a or b will match.

  Thus, `'foo|bar'` matches either `'foo'` or `'bar'` but no other string.

  `'|'` applies to the largest possible surrounding expressions. Only a surrounding `'( … )'` grouping can limit the grouping power of `'|'`.

`'( … )'`

  is a grouping construct that serves three purposes:

  1. To enclose a set of `'|'` alternatives for other operations. Thus, `'(foo|bar)x'` matches either `'foox'` or `'barx'`.
  2. To enclose a complicated expression for the postfix `'*'` to operate on. Thus, `'ba(na)*'` matches `'bananana'` et cetera, with any (zero or more) number of `'na'`'s.
  3. To mark a matched substring for future reference.

  This last application is not a consequence of the idea of a parenthetical grouping; it is a separate feature that happens to be assigned as a second meaning to the same `'( … )'` construct because there is no conflict in practice between the two meanings. Here is an explanation of this feature:

`'\digit'`

  After the end of a `'( … )'` construct, the matcher remembers the beginning and end of the text matched by that construct. Then, later on in the regular expression, you can use `'\'` followed by digit to mean "match the same text matched the digit'th time by the `'( … )'` construct." The `'( … )'` constructs are numbered in order of commencement in the regexp.

  The strings matching the first nine `'( … )'` constructs appearing in a regular expression are assigned numbers 1 through 9 in order of their beginnings. `'\1'` through `'\9'` may be used to refer to the text matched by the corresponding `'( … )'` construct.

  For example, `'(.+)\1'` matches any non empty string that is composed of two identical halves. The `'(.+)'` matches the first half, which may be anything non empty, but the `'\1'` that follows must match the same exact text.

`'\b'`

  matches the empty string, but only if it is at the beginning or end of a word. Thus, `'\bfoo\b'` matches any occurrence of `'foo'` as a separate word. `'\bball(s|)\b'` matches `'ball'` or `'balls'` as a separate word.

`'\B'`

  matches the empty string, provided it is not at the beginning or end of a word.

`'\<'`

  matches the empty string, but only if it is at the beginning of a word.

`'\>'`

  matches the empty string, but only if it is at the end of a word.

`'\w'`

  matches any word-constituent character. These are US-ASCII letters, numbers and the underscore, independently on the buffer encoding.

`'\W'`

  matches any character that is not a word-constituent.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 3.8.2 Replacing regular expressions

Also the replacement string has some special feature when doing a regular expression search and replace. Exactly as during the search, `'\'` followed by digit stands for "the text matched the digit'th time by the `'( … )'` construct in the search expression". Moreover, `'\0'` represent the whole string matched by the regular expression. Thus, for instance, the replace string `'\0\0'` has the effect of doubling any string matched.

Another example: if you search for `'(a+)(b+)'`, replacing with `'\2x\1'`, you will match any string composed by a series of `'a'`'s followed by a series of `'b'`'s, and you will replace it with the string obtained by moving the `'a'` in front of the `'b'`'s, adding moreover `'x'` inbetween. For instance, `'aaaab'` will be matched and replaced by `'bxaaaa'`.

Note that the backslash character can escape itself. Thus, to put a backslash in the replacement string, you have to use `'\\'`.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.9 Automatic Preferences

Automatic preferences let you set up a custom configuration that is automatically used whenever you open a file with a given extension. For instance, you may prefer a TAB size of three when editing C sources, but eight could be more palatable when writing electronic mail.

The use of autoprefs is definitely straightforward. You simply use the `'Save AutoPrefs'` menu item (or the `SaveAutoPrefs` command; see section SaveAutoPrefs) when the current document has the given extension and the current configuration suits your tastes. The internal state of a series of options will be recorded as a macro containing commands that reproduce the current configuration. The macro is then saved in the `'~/.ne'` directory (which is created if necessary) with the name given by the extension, postfixed with `'#ap'`. Thus, the C sources automatic preferences file will be named `'c#ap'`, the one for TeX files `'tex#ap'`, and so on.

Macros are generated with short or long command names depending on the status of the verbose macros flag. See section VerboseMacros.

Automatic preferences files are loaded and executed whenever a file with a known extension is opened. Note that you can manually edit such files, and even insert commands, but any command that does something other than setting a flag will be rejected, and an error message will be issued.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.10 Emergency Save

When `ne` is interrupted by an abnormal event (for instance, the crash of your terminal), it will try to save all unsaved documents in its current directory. Named documents will have their names prefixed with a `'#'`. Unnamed documents will be given names made up of hexadecimal numbers obtained by some addresses in memory that will make them unique.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 3.11 UTF-8 Support

Since version 1.30, `ne` can manipulate UTF-8 files and supports UTF-8 when communicating with the user. At startup, `ne` fetches the system locale description, and checks whether it contains the string `'utf8'` or `'utf-8'`. In this case, it starts communicating with the user using UTF-8. This behaviour can be modified either using a suitable command line option (see see section Arguments), or using UTF8IO. This makes it possible to display and read from the keyboard a wide range of characters.

Independently of the input/output encoding, `ne` keeps track of the encoding of each buffer. `ne` does not try to select a particular coding on a buffer, unless it is forced to do so, for instance because a certain character is inserted. Once a buffer has a definite encoding, however, it keeps it forever.

More precisely, every buffer may be in one of three encoding modes: US-ASCII, when it is entirely composed of US-ASCII characters; 8-bit, if it contains also other characters, but it is not UTF-8 encoded; and finally, UTF-8, if it is UTF-8-encoded.

The behaviour of `ne` in US-ASCII and 8-bit mode is similar to previous versions: each byte in the buffer is considered a separate character.

There are, however, two important differences: first, if I/O is not UTF-8 encoded, any encoding of the ISO-8859 family will work flawlessly, as `ne` merely reads bytes from the keyboard and displays bytes on the screen. On the contrary, in the case of UTF-8 input/output `ne` must take a decision as to which encoding is used for non-UTF-8 buffers, and presently this is hardwired to ISO-8859-1. Second, since version 1.34, 8-bit buffers use localised casing and character type functions. This means that case-insensitive searches or case foldings will work with, say, cyrillic characters, provided that your locale is set correctly.

In UTF-8 mode, instead, `ne` interprets the bytes in the buffer in a different way--several bytes may encode a single character. The whole process is completely transparent to the user, but if you really want to look at the buffer content, you can switch to 8-bit mode (see see section UTF8).

For most operations, UTF-8 support should be transparent. However, in some cases, in particular when mixing buffers with different encodings, `ne` will refuse to perform certain operations because of incompatible encodings.

The main limitation of UTF-8 buffers is that when searching for a regular expression in a UTF-8 text, character sets may only contain US-ASCII characters (see see section Regular Expressions). You can, of course, partially emulate a full UTF-8 character set implementation specifying the possible alternatives using `'|'` (but you have no ranges).

[ << ] | [ >> ] |  |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated by Sebastiano Vigna on February, 7 2009 using texi2html 1.76.