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!
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
Install SWIG.
Install GNU Readline and History support for your system with the development packages.
This is:
-
APT package:
libreadline-dev -
Homebrew:
readline -
Anaconda:
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.
If you have libreadline/libhistory in a non-standard location, such as a from-source installation or an Anaconda environment, use something like:
This pattern works for Linux or Mac.
$ C=$HOME/path/to/conda # or $ C=$CONDA_PREFIX $ export CFLAGS="-I$C/include" $ export LDFLAGS="-L$C/lib -Wl,-rpath -Wl,$C/lib" $ export LIBS="-lreadline -lhistory" $ ./configure --prefix=... $ make install
.-
Edit file
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,
ledreports a warning and does nothing. E [FILENAME]-
Edit the given file like
ebut unconditionally. f [FILENAME]-
Set the current file name. Uses Readline for filename completion. If no argument is given, simply print current file name. If
FILENAMEis., get filename from interactive prompt with Readline completion. If the file already exists,ledreports a warning and does nothing. F [FILENAME]-
Set current file name like
fbut unconditionally. Uses Readline for filename completion. i-
Insert text before current line. Uses Readline.
k[X]-
Set bookmark X. Can be used to save important places in a file.
Xmust be a single character. Bookmarks can be listed withKor 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. Uses Readline for filename completion. Use
FILENAME.for interactive prompt. If no argument is given, uses current file. q-
Quit. If there are unsaved changes,
ledreports a warning and does nothing. Q-
Quit unconditionally without saving.
w [FILENAME]-
Write file. If given an argument, writes to that file, and set the current file 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. IfPATTERNis omitted, repeats last search. \[PATTERN]-
Reverse search. If
PATTERNis omitted, repeats last search. =-
Show current line number, filename, and say if file is modified.
'[X]-
Jump to mark
X. _-
Evaluate Tcl code and print result. Useful examples:
: _ puts hello hello : _ cd .. # or anywhere : _ pwd /home/self/dir : _ puts $led::text # the text buffer, a list of string : _ puts $led::cln # the current line number : _ set v [ lindex $led::text 123 ] # extract a line of text as a variable : _ a $v # append text (similar to the led command `a`) : _ i $v # insert text (similar to the led command `i`)
This could also be used to implement macros and other extension features.