ne Quick Reference

John Gabriele

2020-01

ne, the “nice editor”, is a simple, small, lightning fast, terminal-based (“TUI”) text editor that is very easy to use.

ne embraces the regular named keys on your keyboard for navigation (Arrow keys, PgUp/PgDn, Home/End). Its license is GPLv3. For complete docs see the official ne manual.

On Debian and Debian-based OS’s you may install via apt install ne (and optionally, to get the manual, apt install ne-doc). If your OS doesn’t come with a current ne package, or if you’d just rather build and install from source, doing so 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 (which is usually /usr/share/ne or /usr/local/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 own macros — more on those later). If you can’t run a particular command via a ctrl/alt key combo, and if it’s not present in a menu (note: you can edit those), 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 see and 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. Use the arrow keys to navigate the menus. If you hit ^[ ^[ (or <Esc> <Esc>) the menu comes up instantly.

Hit ^[ ^[ to dismiss the menu.

Getting Help

^k h (the h is short for 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 (at least, its default setting), 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 that it’s bound to ^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. For more info, see ^k h Flags.

Preferences

ne can save global 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, you can do ^k flag to see what each place 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:

Note, in my own personal settings (described further down), I’ve unmapped a handful of these below as I found them too confusing or else not useful. I stick with the simple set described in the above “Executive Summary”.

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 different things, though they’re both auto-selected by filename extension. File type is about which autopref to use (ex. ~/.ne/hx#ap for .hx files), whereas you run the Syntax command to set syntax highlighting (ex. Syntax haxe).

Incidentally, my ~/.ne/hx#ap file has only one line: Syntax haxe

Paragraph (reflow, justify)

Use [p (the Paragraph command) to “reflow/justify” the current paragraph (put in newlines to break lines at the right line width). 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 regularly 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, though I’ve unmapped these in my own personal settings).

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 My Config
forward-/back-by-word [f, [b Ctrl-Right/Left
forward-/back-by-para   Ctrl-Up/Down
start-/end-of-line ^a, ^e Home/End
start-/end-of-document [a, [e  
go to matching bracket ^]  
go to line num ^j  
go to column num [j  

There’s no built-in command for navigating up and down by-paragraph — I use macros for that (again, see further below for all goodies)).

Deleting

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

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

There is no default key-binding for backspace-by-word, though there’s a command for it. You can assign [<BackSpace> 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 My Config
scroll to put cursor middle [c  
scroll to put cursor top ^^ (^6 works as well)  
scroll window up/down   Alt-Up/Down

See also ^k h av.

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

Change Case

Description Key Combo My Config
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. Further, 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 first temporarily toggle autoindent off: ^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 My Config
comment/uncomment   [x, [w
indent/unindent ^k sh, ^k sh <  
through (see below) [t {cmd}  

Currently no built-in comment/uncomment — using a macro for this that works line-at-a-time.

To indent/unindent selected text, 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 again — your macro is now 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, one per line. You can write them by-hand, or else you can record them in the editor and save them (as described above).

The name of the macro is the name of the saved file, and you run a macro by doing ^k {macro-name} (just like built-in ne commands).

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 into it put 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). I can get that from a menu
# if I need it.
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

# To select a paragraph and then use my own `wrap` util:
#
#     [h [t wrap <Ret>

# 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 already use
# it 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

# Alt-^ (well, Alt-6) to capitalize
KEY 1b6 Capitalize

# 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`. Useful for when you want
# to pipe the whole current paragraph through a shell script.
KEY 1e8 select-para

# `[]` (`Alt-]`) to delete trailing whitespace in the entire file.
# You don't need to select anything --- it just does the entire file,
# though shows it as modified even if no line had trailing whitespace.
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, but have unmapped some infrequently-used defaults. Not listing any of the named Arrow/PgUp/Home/etc Ctrl/Alt key combos.

Legend:

More legend:


Key Ctrl Alt
@ MarkVert  
a SOL MoveSOF
b Mark ###
c Copy Middle View
d dup-line NextDoc
e ### MoveEOF
f Find ###
g RepeatLast GotoBookmark
h <Backspace> select-paragraph
i <Tab> AutoComplete
j GotoLine GotoColumn
k Exec SetBookmark
l Refresh ToLower
m <Ret> Play once
n ### OpenNew (doc+file)
o new-empty-line OpenClip
p ### Paragraph
q CloseDoc ###
r Replace Redo
s Save SaveClip
t Start/Stop Rec Through
u UndelLine Undo
v Paste ToUpper
w PasteVert uncomment-line
x Cut comment-line
y DeleteLine DeleteEOL
z Suspend ###
] MatchBracket delete-trailing-whitespace
^ AdjustView Capitalize
_ FindRegExp  

Notes: