Skip to content

Latest commit

 

History

History
222 lines (162 loc) · 3.97 KB

README.adoc

File metadata and controls

222 lines (162 loc) · 3.97 KB

LED

led is a line editor based around the GNU Readline library. Basically, it is an ed clone with Readline usability.

The main use case is when you want to quickly open and make a small change to a file without opening a full-screen editor. You can quickly jump to a certain line number or pattern and make a change without leaving your shell/terminal!

Use example

Inside led, use h for help.

Basic use:

# Start led to edit a file:
$ led myfile.txt
new file: myfile.txt
: a
   1> hello
: wq
backup: current file does not yet exist...
wrote:  myfile.txt

# Show the file using cat
$ cat myfile.txt
hello

# Re-open file and search for "hello"
$ led myfile.txt /hello
opened: myfile.txt
   1@ hello
# Append "bye"
: a
   2> bye
# Print the file
: n
   1: hello
   2@ bye

# Save and exit
: wq
backup: myfile.txt~
wrote:  myfile.txt

Programmer example:

$ make
src/main.c:1234:10: fatal error: ‘xyz’ undeclared here

# Jump in to edit the line!
$ led src/main.c 1234

# or
$ led src/main.c /xyz

Installation

Install GNU Readline and History support for your system with the development packages.

This is:

  • APT package: libreadline-dev

  • Homebrew: readline

led uses a standard Autotools build.

$ git clone [email protected]:j-woz/led.git
$ cd led
$ ./bootstrap
$ ./configure --prefix=[PREFIX] ...
$ make
$ make install

Use ./configure --help for help.

Non-standard libreadline location

If you have libreadline/libhistory in a non-standard location, such as a from-source installation or an Anaconda environment, use something like:

Anaconda

This pattern works for Linux or Mac.

$ C=$HOME/path/to/conda"
$ export CFLAGS="-I$C/include"
$ export LDFLAGS="-L$C/lib -Wl,-rpath -Wl,$C/lib"
$ export LIBS="-lhistory"
$ ./configure --prefix=...
$ make install

Mac Homebrew

$ C=/usr/local/opt/readline
$ export CFLAGS="-I$C/include"
$ export LDFLAGS="-L$C/lib"
$ export LIBS="-lhistory -lreadline"
$ ./configure --prefix=...
$ make install

Usage

Key commands

.

Edit file

_

Evaluate Tcl code. This could be used to implement macros and other extension features. Example:

: _ puts hello
hello
a

Append text after current line. Uses Readline.

c

Change line interactively with Readline.

d

Delete line

e [FILENAME]

Edit the given file. Use . for interactive prompt. If no filename is given, it reports the current filename. Re-reads the file. If there are unsaved changes to the file, led reports a warning and does nothing.

E [FILENAME]

Edit the given file like e but unconditionally.

f [FILENAME]

Set the current file name. If no argument is given, simply print current file name. If FILENAME is ., get filename from interactive prompt with Readline completion.

F [FILENAME]

Set current file name like f but unconditionally.

i

Insert text before current line. Uses Readline.

k[X]

Set bookmark X. Can be used to save important places in a file. X must be a single character. Bookmarks can be listed with K or jumped to with '.

k-[X]

Unset bookmark X.

K

Show all marks.

n

Print lines with line numbers

p

Print lines in raw format.

r [FILENAME]

Read given file, appending after current line. Use FILENAME . for interactive prompt. If no argument is given, uses current file.

q

Quit.

Q

Quit unconditionally without saving.

w [FILENAME]

Write file. If given an argument, writes to that file.

wq

Write and quit.

x

Paste cut buffer

y

Yank (copy) to cut buffer.

Y

Show cut buffer

/[PATTERN]

Search for PATTERN. If PATTERN is omitted, repeats last search.

\[PATTERN]

Reverse search. If PATTERN is omitted, repeats last search.

=

Show current line number, filename, and say if file is modified.

'[X]

Jump to mark X.

Addressing

Key commands can be prefixed with line addresses: