ne Quick Reference

John Gabriele

2019-08

ne, the “nice editor”, is a simple, small, lightning fast, terminal-based (“TUI”) text editor. ne embraces the regular named keys on your keyboard for navigation (Arrow keys, PgUp/PgDn, Home/End). License is GPLv3. For complete docs see the official ne manual.

On Debian and Debian-based OS’s, install: apt install ne (and optionally, to get the manual, apt install ne-doc). If your OS doesn’t come with a current ne package, building it from source is a snap.

ne operates on text using its collection of built-in text-editing commands, though you can also create and save your own “macros” (sequences of ne text editing commands) — more on those later.

Terminal Settings

Many terminals use the traditional 16-color display colors. In the Xfce terminal, to adjust these default colors, go to the Terminal Preferences (“right-click –> Preferences…”), Colors tab, and for the Pallette load the Dark Pastels preset. (After that I like to also lighten the background just a bit.)

For a nice font, try Hack: apt install fonts-hack

For older terminals, to properly display multiple colors, you may need to add this to your ~/.bashrc:

export TERM=xterm-color    # or maybe
export TERM=xterm-256color

Running ne

If you start ne with no args, you get its About screen. See the “status bar” (bottom line) for version info and for the location of its global config directory (usually /usr/share/ne).

Terminology

You open files into a “document”. You edit documents, then save them back to files.

Commands in ne

After you open a file, there are three user interfaces, and they all do the same thing under the hood:

All of the above execute built-in ne text-editing commands (or your macros). If you can’t run a particular command via a ctrl/alt key combo, and if it’s not present in a menu, you can run it using the ne command line (^k {the-command} <Ret> or ^k {the-command-abbrev} <Ret>).

The ne command line remembers the last command you ran (hit ^k <Ret> to run it).

ne uses the familiar GUI-like keyboard keys: arrow keys, home, end, etc., all work as you’d expect.

Some notes about key combos in the terminal window:

Menus

Hitting <Esc> causes the menu to come up after a moment. You can hit ^[ to get an <Esc> as well. If you hit ^[ ^[ (or <Esc> <Esc>) the menu comes up instantly.

Hit ^[ ^[ to dismiss the menu.

Getting Help

^k h (short for ^k help) to get help on any ne command. Note that some commands may take arguments (see the docs for that command) — for example ^k lu 4 moves the cursor up 4 lines.

To see the command (or macro) that a key combination would invoke — and also to see the numerical keycode it produces — do ^k kc <Ret> then the key combo, then <Ret>.

To see what command a menu item would run, look at https://github.com/vigna/ne/blob/master/doc/default.menus.

To see what (if any) key a command is bound to, look at its help docs (ex. ^k h save shows it’s ^s).

To see what command a command abbreviation refers to, look at its help docs (ex. ^k h s says it’s the Save command).

For a full listing of what keycodes are bound to which commands (by default), see https://github.com/vigna/ne/blob/master/doc/default.keys. This is handy if you’d like to make some of your own custom key bindings.

Status Bar

After you start ne, it lets you know what many of its current settings are via flags in the status bar at the bottom of the screen. See ^k h Flags.

Preferences

ne can save globals prefs (aka “default prefs”) as well as filetype-specific prefs (aka “autoprefs”).

Global Prefs

To set and save global prefs: use the Prefs menu (or command line commands) to get things how you like, then choose “Save Def Prefs” (prefs will be saved in ~/.ne/.default#ap file).

I’ve found these global settings helpful:

Incidentally, given my global prefs, my status bar usually looks like:

ia----pvu--d-----@U-

Again, see ^k flag to sese what each spot indicates.

Filetype-specific Prefs

To set filetype-specific prefs, use the Prefs menu again, but this time choose “Save Auto Prefs” (will be saved in ~/.ne/{filetype-ext}#ap files).

Open, Close, Multiple-Docs, and Exiting

Executive summary: to open multiple docs after you’ve already started ne: use [n. Close them each with ^q. Cycle through them with [d. Use ^q repeatedly to close docs one-by-one and then subsequently quit ne.

More about the related menu items:

File menu:

Document menu:

Regarding exiting ne:

Syntax Highlighting

ne decides which syntax highlighting to use by looking at the filename extension. See ^k h sy for more info.

To change which syntax highlighting is used, do ^k sy {lang}. To shut off highlighting, do ^k sy *.

“File type” and “which syntax highlighting used” are two separate things, though they’re both auto-selected by filename extension. File type is about which autopref to use.

Paragraph (reflow, justify)

Use [p (the Paragraph command) to “reflow/justify” the current paragraph. It will use the current value of RightMargin for max line width.

Note, when viewing files with long lines, ne will not “soft wrap” them in the display to show you the whole line.

Unrelated to the Paragraph command is WordWrap. Enable WordWrap (under menu prefs) if you’d like ne to automatically add in newlines as you type, so you don’t have to hit <Ret> when typing out long passages.

Some Editing Commands

Use arrow keys to move fwd-/back-by-char, up-/down-by-line.

Use <PgUp> and <PgDn> to move by page (you can also use ^n and ^p).

Note that <Home> and <End> are by default mapped to special commands. If you hit <Home> repeatedly, it will take you to start-of-line, then top-of-page, then finally to the start of the document. Personally, I like to remap them to just go to beginning- and end-of-line.

Description Key Combo
forward-/back-by-word [f, [b
start-/end-of-line ^a, ^e
start-/end-of-document [a, [e
go to matching bracket ^]
go to line num ^j

There’s no built-in command for navigating up and down by-paragraph — you might use search for that.

Deleting

Use <Delete> and <BackSpace> to delete-by-char.

Description Key Combo
delete-/undelete curr-line ^y, ^u
delete to EOL [y
backspace-by-word

There is no default key-binding for backspace-by-word, though there’s a command for it. You can assign [<BackSpcae> to run it. See some customizations.

Misc

Undo/Redo: [u, [r

Duplicate current line: ^y ^u, then ^u multiple times.

Redraw the screen: ^l

Scroll Window

Description Key Combo
scroll to put cursor middle [c
scroll to put cursor top ^^ (^6 works as well)

See ^k h av.

Note, you can scroll by using your mouse as if ne were a GUI!

Change Case

Description Key Combo
uppercase next word [v
lowercase next word [l
capitalize next word ^k ca

Cut, Copy, Paste

Do ^b to “set the mark” (start the selection), then navigate to where you want the selection to end. Use ^x to cut or ^c to copy (or else (optionally) ^k m 0 to cancel selection). Use ^v to paste.

ne doesn’t highlight text when you select it, so you’ll have to use your imagination here.

Use ^@ to set the mark for a rectangular selection. Note, there’s a special “Paste Vert” command for when you’ve just cut or copied a rectangular selection and want to paste it in.

If you forget where you set the mark, you can go back to it with ^k gm (menu: “Search –> Goto Mark”), and note that this won’t unset the mark.

When pasting blocks of text, it’s usually a good idea to disable autoindent: ^k ai.

Bookmarks

Description Key Combo
set bookmark [k
goto bookmark [g

You can have up to 10 numbered bookmarks set. [k sets the zeroth bookmark.

Set bookmark by number: ^k sbm {n} (where {n}: 0 –> 9)

Go to numbered bookmark: ^k gbm {n}

There’s a special “previous location” bookmark (“-”) that gets automatically set every time to jump to a bookmark. Do ^k gbm - to go to your previous location. (Bounce back and forth with ^k <Ret>, since the command prompt remembers the last command you ran).

Search and Replace

Find: ^f, with ^g to repeat the last find/replace operation.

There’s no incremental search, however, after you hit ^f, you can then use autocomplete ([i) right there in the Find prompt.

Find by regex: ^_

Toggle search direction: ^k sb. Remember to toggle it back when you’re done with your reverse search.

To do a search and replace: ^f to search. Then ^r to replace what you just found, and hit y/n/l/a/q to proceed.

Programming Commands

Description Key Combo
comment/uncomment
indent/unident ^k sh, ^k sh <
through (see below) [t {cmd}

Currently no comment/uncomment — use a macro for this.

To indent/unindent, use the Shift (sh) command. You can pass in the number of how many in-/de-dents you want, for example:

^k sh >3
^k sh <2

and you can run those multiple times without needing to re-select the area.

To send (pipe) selected text through an external shell command, replacing the selection with the results: [t {shell-command} <Ret>. For example: select some lines, then [t sort <Ret> to sort them. Note, some commands may ignore stdin and just print out results, and that’s fine too: [t date.

ne doesn’t seem to support autoclosing of matching brackets.

Autocomplete

[i to autocomplete. Nothing else to say — works beautifully.

Macros

Macros are recorded (or manually typed in) sequences of ne commands.

Unnamed Macro

To create (record) a macro while editing (not one you want to save), hit ^t, do some operations, then ^t — your macro is ready to use. Hit [m to use it.

Saved Macros

After recording a macro, you can save it to a file via the menu item: “Macros –> Save Macro”.

Macros are stored in files (one per macro) in your ~/.ne dir. They look like little scripts consisting of ne commands. You can write them by-hand, or else you can record them in the editor and save them.

The name of the macro is the name of the saved file, and you run a macro by doing ^k {macro-name}.

You can set a keyboard shortcut for a macro in the same way you do for a regular ne command:

KEY {some-keycode} {some-macro-name}

Example macros

move-dn-by-para:

PushPrefs
SearchBack 0
FindRegExp ^[    ]*$
FindRegExp [^    ]
PopPrefs

That space in the square brackets ia a <Tab> and then a space character. You can get a Tab character by running ^k ic 9 (that’s “InsertChar”, and decimal 9, or 0x09 — an ascii <Tab> character).

move-up-by-para looks like this:

PushPrefs
SearchBack 1
FindRegExp ^[    ]*$
FindRegExp [^    ]
MoveSOL
PopPrefs

Save those macros into ~/.ne as we’ll use them in the next section.

Clipboard

You can use the default clipboard (n = 0), or if you specify the clipboard number, a numbered one.

To copy (^c) into a numbered clipboard: ^k c {n}

To paste (^v) from a numbered clipboard: ^k p {n}

Use ^k e to erase a selection and not touch the clipboard.

Also:

If you don’t want to use the default (n = 0) clipboard for those, you can first run ^k cn (ClipNumber).

Some Customizations

To set your own key bindings, create a ~/.ne/.keys file, and put into it lines like:

KEY {n} {some-command}

The number n is a hex number sans the leading “0x”. To figure out what to put for n, do ^k kc <Ret> {key-combo} <Ret> and see the status bar.

My .keys File

I think a handful of commands don’t actually need key combos for them, and so un-map them. I like the following customizations:

# Change PageUp/PageDown behaviour ...
KEY 107 PageDown
KEY 108 PageUp

# Let's use ^n and ^p for something else at some point.
KEY e NOP
KEY 10 NOP

# Since we'll be using Ctrl-Arrow keys to move-by-word,
# unmap `[f` and `[b`.
KEY 1e6 NOP
KEY 1e2 NOP

# Change Home/End to work the way I like.
KEY 105 smart-home
KEY 106 MoveEOL

# And we won't need `^e`, since we have `End` for that.
KEY 5 NOP

# Un-bind `[q` and `[x`. We can manually type these in if we want them.
KEY 1f1 NOP
KEY 1f8 NOP

# Un-bind word-wrap from `[w`.
KEY 1f7 NOP

# Un-bind `[z` (Save CR/LF).
KEY 1fa NOP

# I almost never use `^o` (Open into this doc), so let's use
# it to "open a new empty line here":
KEY f new-empty-line

# Ctrl-Up
SEQ  "\x1b[1;5A"  20
KEY  20  up-by-para

# Ctrl-Down
SEQ  "\x1b[1;5B"  21
KEY  21  dn-by-para

# Ctrl-Right
SEQ  "\x1b[1;5C"  22
KEY  22  NextWord

# Ctrl-Left
SEQ  "\x1b[1;5D"  23
KEY  23  PrevWord

# Note, there is no special ctrl-backspace keycode.
# Alt-Backspace
KEY  1ff  DeletePrevWord

# I don't think I'd use an Alt-Delete.
# so, not adding that. Also, Xfce seems to use
# it already to downsize number of virtual desktops.

# Alt-Up to scroll the window up.
SEQ  "\x1b[1;3A"  24
KEY  24  Adjustview B1

# Alt-Down to scroll down.
SEQ  "\x1b[1;3B"  25
KEY  25  AdjustView T1

# Some macros I like. `[x` and `[w` ("// " comments)
KEY 1f8 comment-haxe-line
KEY 1f7 uncomment-haxe-line

# Dup curr line, `^d`.
KEY 4 dup-line

# select curr paragraph, `[h`.
KEY 1e8 select-para

# `[]` (`Alt-]`)
KEY 1dd delete-trailing-whitespace

Editing Tables and/or ASCII-art

When writing markdown tables, you might try first toggling Insert (^k i) and FreeForm (^k ff). Toggle them both back when you’re done.

Summary of key combos

These include my conservative changes (in my ~/.ne/.keys). I’ve tried not to change any ne defaults where it would cause confusion (for example, I’m not changing ^o to OpenNew, even though that’s tempting) but have unmapped a few defaults. Not listing any of the named Arrow/PgUp/Home/etc Ctrl/Alt key combos.

Legend:

Key Ctrl Alt
@ Mark Vert  
a SOL Start of File
b Mark ###
c Copy Middle View
d dup line Next Doc
e ### End of File
f Find ###
g Repeat Last Goto Bookmark (gbm)
h <Backspace> select-paragraph
i <Tab> AutoComplete
j Goto Line Goto Column
k Exec Set Bookmark (sbm)
l Refresh ToLower
m <Ret> Play Once
n ### Open New Doc+File
o new-empty-line Open Clip
p ### Paragraph
q Close doc ###
r Replace Redo
s Save Save Clip
t Start/Stop Rec Through
u Undel Line Undo
v Paste ToUpper
w Paste Vert uncomment-line
x Cut comment-line
y Delete Line DeleteEOL
z Suspend ###
] Match Bracket del trailing whitespace
^ Adjust View  
_ Find RegExp  

Notes: