home        

The pad editor

1  Introduction
2  Installation
3  Working with pad
4  Command description

 

1  Introduction


What is pad?

Pad is a file editor for Unix. It is built on the ncurses library to run on a console or in an xterm window. Though pad is relativly small in size and modest in resource consumption it is pretty complete.

I've written pad mainly for personal use. There are enough ideas for enhancements, but on one hand I'm too lazy to add them and on the other hand I don't want pad to grow fat. If you're happy with your editor there is no need to use pad.

YES: large files, long lines, binary clean, multiple files, mouse support, cut/paste, search/replace, undo, autoindent, key macro, bracket matching, ...

No: scripting language, regular expression searching, overtype mode, syntax highlighting, text formatting ...


Copyright and Warranty

Pad is free software; you may redistribute and/or modify it under the terms of the GNU General Public License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License published by the Free Software Foundation for more details.


History

After reading newsgroups about editors, searching the net and installing several editors for Linux I had the idea that writing my own editor was much more fun than customizing vim or learning emacs.

The name "pad" has nothing to do with pcb or chip design. There is no relation to the famous notepad editor, the palm address dumper or any other product with the same or a similar name. Pad does not use ncurses pads. The name was choosen to be short for typing and easy to remember; it's the first three letters of my calling name (I have a bad memory for names but usually remember this).

On DOS my favorite editor was Point supplied with the Logitech Modula compiler. Point allowed quick working with a few mouse clicks. It was even ported for TCL/TK, but this does not run on a console. Pad looks similar to Point but I'm not an experienced programmer nor do I like late-night hacking so it lacks some nice features.

Jul-1999: Planned to write the editor, read a lot about console programming, first steps with ncurses, initial version for editing multiple files given at the command line, saving files at exit, scrolling, selecting text, cut/copy/paste.

Aug-1999: Fixed some problems with recognition of function keys, search, search/replace, enhanced file access, open/save/close from within the editor.

Sep-1999: Autoindent, indent/outdent of selection, key macro, interface to gpm mouse driver, commandline options, run shell commands, html page.

Oct-1999: (0.54) Changed edit buffers for multiple undo, delete without overwriting clipboard.

Nov-1999: (0.69) Change case, tab handling, ascii table, fixed backwards selection with mouse, dos/mac modes.

Jan-2000: (0.72) Bug fixes (scrolling, backspace, dos mode) and cosmetic changes.

Feb-2000: (0.74) Window resizing, toolbar, fixed some bugs (and introduced some new ones).

May-2000: (0.77) Simple file browser to open files, resolving symbolic links for backup files, execute selection.

Jul-2000: (0.78) Scroll bar added to file browser. Cut/copy/paste now end keyboard selection mode.

Sep-2000: (0.79) Bug fixes (backspace after paste, function keys with caps locked).


Problems

-no recognition of already opened files.
-handling of xterm resizing not stable.
-changes are lost after a crash (no error recovery).
-no check for file size limits (approx 2GB).
-no check of available memory or disk space.
-no configure script and no makefile available.


Thanks

Thanks to Charlie Crowley (Point), Zeyd M. Ben-Halim and Eric S. Raymond (ncurses) and to Alessandro Rubini (gpm).

Thanks to Anton, Peter and Urs for proof reading, discussion of problems and for testing.

Thanks to all folks working on Linux and contributing free software to the public.


Bug reports and other input

As already mentionned I don't want to add a lot of new features to pad. But if you find a bug or have an idea how to make pad more reliable please let me know.

email: paddy.strebel@tiscali.ch, please write in easy english or german.


 

2  Installation

There is a single source file: pad.c (0.79)

Pad was compiled with gcc on different Pentium PC's (Linux 2.2.x) and on some Suns (Solaris 2.6). Other compilers or other hardware may work. Pad needs the ncurses library (4.2, 5.0) and for console mouse support the gpm library. Verify that ncurses.h and gpm.h are in the include path. Compile with:

gcc -g -Wall -o pad pad.c -lncurses -lgpm

Or if gpm mouse support is not needed:

gcc -g -Wall -o pad pad.c -lncurses -DNO_GPM

The -g option is for support with the gnu debugger. When pad recognizes an error it dies with an error message and then forces a core dump for locating the problem with gdb.

After successfully building the program try it out with some filenames as arguments. Get help with "ESC h". Quit with "ESC q".

The environment variable TERM must be set appropriately for proper function of display and keyboard (see termcap resp. terminfo). Try TERM=linux on a text console or TERM=xterm in an X-Terminal.
Correct TERM setting is essential: e.g. a gnome terminal was not cleanly updated after scrolling (blank regions still contained old text). The problem was solved with "export TERM=color_xterm".


 

3  Working with pad


A short tutorial

If everything is set up properly editing may be started with

pad myfile

Writing will insert text just before the cursor. Use the BackSpace key to correct typos.

Move around with cursor keys or place the write cursor with the mouse.

To scroll full pages use the PageUp/PageDown keys.
Or click on the scrollbar at the left boarder.

Select Text with the mouse, cut the selection with DEL and paste it with INS.

When you're finished press F10. Confirm you want to save the file with Enter.


Commandline parameters

Usage: pad [options] [files]

When pad is started with no arguments a help screen is displayed. Files may then be opened with ALT-o.

Normally pad will be started with a filename. If an existing file can't be opened for reading or a new file cannot be created pad will terminate with an error message.

Commandline options start with a minus "-". Filenames and options may appear in any order. Options are globally and not related to a file.
All options may also be changed on the fly with the editor command ALT-o.

-a, -A Autoindent off, on. With default setting (-A), when inserting a newline, leading spaces and tabs from the previous line are duplicated.
-b, -B Backup file off, on. Per default (-B) whenever a file is saved to an existing file (usually to itself) a backup of the old file is created with '~' appended to the filename. With the -b option that backup file will be removed.
-c, -C Case sensitive searching off, on. Default setting (-c) ignores upper/lower case for all searches (also for search/replace).
-k, -K Black screen off, on. Text display is white on a black background (-K) if the terminal allows. Option -k turns the display to black on white.
-p, -P Mouse off, on. With the default (-P) pad tries to get mouse events. Unfortunately pad does not interface with default select/paste mechanism of external text: To get this partly working, the mouse may be turned off with -p.
-x, -X Open files full size off, on. By default (-X) the window of a newly opened file expands over the full screen. When -x is specified new file windows do not cover the top line (toolbar).
-i string Pad allows quick indenting of a selected text area with ALT-i. The reverse may be done by ALT-j. The default indent string is two spaces. Any other string may be defined: For example a string "> " may be used for quotations in a email reply.
-m command Default command is "padmak". The command may be run from within pad and gets the name of the current file as parameter. First the current file is saved, then the command is run and it's screen output is logged to a temporary file: This allows for compilation while working on a source file without leaving the editor and location of numbered errors with ALT-n (next error).
-r command Default command is "padrun". Similar to the -m option this command may be run from within pad and gets the name of the currently edited file. But the current file is not saved and output is not logged.
-t n Tab width. n is 8 by default and must be in range 0..100. When set to 0, tabs are shown as a "right tee" symbol instead of blank space.
-U, -D, -M End of line code Unix (LF), Dos (CR+LF) or Mac (CR). Default (-U) is Unix file format. If setting is wrong, line ends are visible and sometimes the whole file is on a single line.


The pad screen

  toolbar: commands
 
options: autoindent, case sense, background  
 
 help wtop undo  open save quit  cut paste copy  fwd bwd rpl       A c K
 
+ file3 (read only) ------------- L:1 C:1 0:101=65=41 +
| ..................                                  |
| .......                                             |
| .............   + file2 (new) ------------------ L:1 C:1 0:040=32=20 +
| .....           | ......                                             |
| .......         | .......................                            |
| ..              |                                                    |
| ... + file1 -------------------------- L:3 C:7 0:141=97=61 +         |
| ..  | ...............                                      |         |
| ... | ....................                                 |         |
| ... | ........                                             |         |
+-----| ............                                         |         |
      | ..................                                   |         |
      | ..........                                           |         |
      | .....                                                |---------+
      | .............                                        |
      | ...                                                  |
      |                                                      |
      +------------------------------------------------------+
      
 not found: quite an ugly search string ...
message and command line
 


A file window

  filename
 
line, column, offset : oct=hex=dec  
 
scrollbar
up/down

 
+ foobar (new) --------------------- L:1 C:1 0:040=32=20 +
| ..................                                     |
| .............                                          |
| ................                                       |
| ..........                                             |
| ............                                           |
| ..........                                             |
| ....................                                   |
| ..............                                         |
| ............                                           |
| ...                                                    |
| ...............                                        |
| ........                                               |
+--------------------------------------------------------+
searchbar
bwd/fwd

 
scrollbar (left/right)
 


Text display

Every byte takes exactly one character cell on the display. This is even true for tabs when the tab width is set to 0 with the -t option: then tabs are displayed as a "right tee". Carriage returns are displayed as a "lower right corner" and linefeeds as a "lower left corner" but when acting as newline code these are shown as a space at the end of the line. Nulls are displayed as "degree" signs and other codes below 32 (space) as a "tee" sign.

A bytecode of 127 is displayed as an "upside-down tee" and all codes from 128 to 255 are shown as a "large plus" sign.

If unsure move the cursor to a character position and read the code from the upper right corner of the file window.


Keyboard entry

For moving the cursor the keys left/right/up/down and for scrolling through pages PageUp/PageDown should work.
In an emergency CTRL-l, CTRL-r, CTRL-u, CTRL-d, CTRL-n and CTRL-p do the same but better check the terminal settings to get the former keys working.

Commands are inwoked by the ALT- (or META-) key combined with a single letter a-z. If this does not work ESC followed by the letter can be used.
For conveniance some commands are additionally available on function keys F1 to F12. The DEL and INS keys serve also for cut and paste.

Example: switch to next file window with ALT-w or ESC w or F8

ESC will also cancel any command that is waiting for input.
(a command may also be cancelled with the right mouse button or entered with the left one!)


CTRL Keys

Some CTRL keys have special meanings:
 
^cterminate (this is ignored)
^hbackspace
^itabulator
^jnewline
^mreturn (will insert a newline, not a carriage return)
^qxon (start transmission)
^sxof (stop transmission, resume with ^q)
^zstop (resume with shell command fg)

The null character CTRL-` (CTRL-backtick; CTRL-Space on some keyboards) changes the case of all alphabetic characters within the selection.

CTRL-a shows an ascii code table (see also: man ascii).

CTLR-y is reserved for debugging.

CTRL-e, CTRL-g, CTRL-k, CTRL-o, CTRL-t, CTRL-v, CTRL-w and CTRL-x are currently not used.


Selecting text with the mouse

Click the left mouse button on the text location you want to insert text. Clicking twice selects the word and clicking a third time selects the line. Selected text is shown with reversed colors. Dragging expands the selection (hold the left mouse key and release it at the desired location). The selection can also be adjusted with a right mouse click. This will even work after scrolling so the selection can be much larger than just a screenful of text.

When you expand a selection with the mouse and you entered word or line selection mode by double or tripple clicking, the selection is expanded to full words or lines: ALT-y or F6 cancels this mode.

The selected area may be cut or copied to the clipboard and inserted anywhere within the text even in another file window. You may also search for another occurence of the selected text. The search/replace command can do replacements limited to the selected area if you wish. And finally the indent and outdent commands work within selected text.


Scrolling with the mouse

Scrollbars are most easily located when running pad in console mode since the mouse cursor won't go beyond screen borders.

There is a scrollbar at the left margin to scroll up and down, and a scrollbar at the bottom to scroll left and right. Scrolling is disabled if the file has less lines or columns than half the display height or width. It is useful to have a three button mouse for scrolling.

If the right mouse button is clicked at top of the scrollbar the file window scrolls down one line. To scroll more lines click the right button on the scrollbar beneath the line you want to move to the top. The left button works likewise but in the other direction.

Click the middle mouse button at top of the scrollbar to display the top of file or at the other end to see the end of file. To move somewhere in between click the middle mouse button on the scrollbar between top and bottom. Warning: if the file is large scrolling may take a long time.

The bottom line acts as a scrollbar for horizontal scrolling. The three mouse buttons may be used to scroll left or right or to move quickly to some column within a long line.


Searching selected text

If the right mouse button is clicked on the right margin the selected text is copied to the search buffer (or part of it if the selection is too large) and this pattern is searched forwards. The left button does the same but searching is done backwards.


Resizing and moving file windows

To resize a file window click with the right mouse button on a corner an drag it to a new location. To move the window drag its title bar with the right mouse button. There is a toolbar with frequently used commands on the topmost line in background. File windows may overlap the toolbar to get a larger area for viewing edited data.


Owner and Group

Owner and group change to user settings when a file is saved. The backup file keeps owner and group of the edited file.

If pad runs with user id root, owner and group of the modified file are not changed but the backup file gets owner root.


File locking

Pad does not recognize when a file is already open. When the same file is modified from different processes all changes may be lost but for the last save.

Pad works on the original file but does not change it. When saving the original file is renamed and becomes the backup file. The changed file is newly written. When the original file has been changed from somewhere else since start of editing, pad will complain. (this may happen when an editor that saves to the original file, like vi, changed the file; but when the file is renamed or deleted it stays available as long as pad has it opened)

Saving a file does not replace the original file atomically. This is critical for files that should always be available like /etc/passwd.


Hints for users of the Point editor

Pad is similar to point but there are some traps caused by different key bindings:

CTRL-d is used by Point to enter a string to search for. When you do this in pad CTRL-d moves the cursor down a line and then the entered string is inserted into text. But that's not what you aimed for. If you want to search for a string you must move your left hand a bit more to the right and type ALT-f. Think of FIND! or FORWARDS!

Save & exit with F9 and close a file with F3: these keys are exchanged.
Bracket matching is done with ALT-m (not ALT-b).
Locating a line is ALT-l (not ALT-n).

When the editor is left with F10 (ALT-q) it is asked whether to save and not wheter to discard changes.

F5 starts keyboard selection mode. Even though the F6 key displays the file status it may still be used to end keyboard selection mode.


 

4  Command description

help, status
open, close, save
keyboard selection
end, quit
next window
cut, copy, paste, delete
search forwards, search backwards
search/replace
goto line, goto byte
undo
ascii insert
match bracket
indent, outdent
key recording, key playback
execute, next error

help (F1) (ALT-h),  status (F6) (ALT-y)

ALT-h displays a command summary. There are only a few commands so after some short time working with pad you will no longer need this quick guide.

ALT-y displays the current size (number of bytes) and lines count (number of newlines).

Internal status (shown in parantheses): bufcnt is total number of edit buffers. These buffers are kept in memory and point to a chunk of file data on disk. Data is either in the original file or in the temporary edit file (inserts and clipboard). While editing bufcnt grows and editing speed will decrease. When saving a file its data chunks are gathered and edit buffers are freed. ncol is number of columns from the longest line on the screen. tln is the topmost line on display (first line is 0). sft (shift) is the leftmost column on display (starting at 0). chg is increased by each edit step and decreased with undo.


open (F2) (ALT-o),  close (F3) (ALT-z),  save (F4) (ALT-s)

To open a file from within the editor type ALT-o and choose a file or enter a filename. When the file exists and access is permitted the file is opened. When the file does not exist it will be created if possible.

The open command allows also for changing options the same way options are given at the commandline. It is allowed to enter more than one filename but no wildcard expansion is done.

With ALT-z the current file is closed. When the file was changed you will be asked whether to save it or not.

Save the file with ALT-s. You are asked for a filename. If saved to another file the original file will be closed and the file with the new name is kept open.


keyboard selection (F5) (ALT-t)

ALT-t starts keyboard selection mode. Moving left/right/up/down and scrolling with PageUp/PageDown expands the selection.
Another ALT-t command or most other keys (except those commands related to the selection) end the keyboard selection mode.

end (F9) (ALT-e),  quit (F10) (ALT-q)

ALT-e saves all changed files and leaves the editor.

Alt-q leaves the editor asking for each changed file whether to save it or not.

If a read-only file was changed you are always asked whether to save it and to what file. It is possible to ignore the write protection if access rights are sufficient.


next window (F8) (ALT-w)

If more than one file is open, ALT-w circularly raises the next file window.

cut (DEL) (ALT-x),  copy (ALT-c),  paste (INS) (ALT-v),  delete (ALT-d)

With ALT-x the selected text is copied to the clipboard and deleted.

ALT-c copies the selected text to the clipboard.

ALT-v inserts the clipboard contents from the last cut or copy right before the text cursor.

Alt-d deletes selected text without saving it to the clipboard. To delete some text without loosing the clipboard contents you may also use the BackSpace key.


search forwards (ALT-f) (CTRL-f),  search backwards (ALT-b) (CTRL-b)

Type ALT-f and enter a string to search for.
CTRL-f repeats the last search.

ALT-b let you define a string to search backwards.
CTRL-b repeats the last search backwards.

When entering the search pattern ALT-a may be used to define any byte code.

If the -c option is set (default) upper case text is changed to lower case and searching is not case sensitive.
For case sensitive searching type ALT-o and enter -C (if not already done on the commandline).


search/replace (ALT-r)

You are prompted to enter the pattern to be replaced and the pattern to be inserted instead. ALT-a may be used for binary input (same as when editing the file). Search/replace may be done from the position of the text cursor to the end of the file or within the selected text area. Then you are asked whether you want to confirm each substitution.

Example: delete carriage-returns from a DOS text file
 

1.Go to top of file e.g. with ALT-l, ENTER
2.Call search/replace with ALT-r
3.replace what? : ALT-a, 13, ENTER, ENTER
4.replace with? : empty string (hit DEL if there is a string), ENTER
5.to end of file [e] or within selection [s]? : ENTER (defaults to [e])
6.Verify each change? [y/n] : n

goto line (ALT-l),  goto byte (ALT-g)

Locate a line with Alt-l. The file starts with line 1. When no line number is given the top line is located. When the number is too large the last line is located.

ALT-g goes to the byte with a specified offset from filestart. When no number is entered the first byte is located. A number larger than the file size goes to the file end.


undo (ALT-u)

Undo the last edit. This may be repeated until the file is in its original state. There is no redo command to make an undo command undone.

Insertion of text at a new location is treated as a single editor step including corrections with backspace. A newline introduces another editor step.

When search/replace is done without confirmation all replacements are undone at once. When replacements have been confirmed, the most recent change is restored with every undo, so it is possible to restore only part of the replacements.


ascii insert (ALT-a)

Insert any byte in the range 0..255. The code may also be entered octal (with a leading 0) or hexadecimal (starting with 0x).

match bracket (ALT-m)

Place the cursor on a bracket: { } ( ) [ ]. ALT-m searches the matching bracket, skipping enclosed bracket pairs. The function may fail when an bracket occures in a string or char constant or in a comment, since there is no special handling for quotation and comments.

indent (ALT-i),  outdent (ALT-j)

ALT-i inserts the indent string (default: two spaces) at the current position or at every line within the selection. The starting column of the selection determines at what column on each line the indent string is inserted. This is useful when a block of program code must be nested one level deeper.

ALT-j deletes n characters (n is the length of the indent string) at the current position or at every line within the selection. The starting column of the selection determines at what column on each line characters are removed. When a line end is reached no more characters are deleted.

With the option -i <string> the default indent string may be redefined.


key recording (ALT-k),  key playback (ALT-p)

Start key recording with Alt-k. All keystrokes (except ALT-k and ALT-p) are recorded while you are editing. Type Alt-k again to stop recording. Recording is also stopped when the key buffer is full (256 keys) or after typing Alt-p.

Alt-p starts playback of the previously recorded key sequence.


execute (F12) (ALT-`),  next error (F11) (ALT-n)

ALT-` (Alt-backtick; or ESC ` is quite comfortable on an US keyboard) let you choose from three options m, r, s:

m: save & make
The current file is saved. Then the command "padmak" is run with current filename as argument. Screen output is logged to a temporary file. This allows for compilation of a source file without leaving the editor and locating numbered errors with ALT-n (next error).
The default command "padmak" may be a script that starts a compiler. With the option -m <command> any command that takes a filename as argument may be specified.

Example 1: simple "padmak" script that was used to compile pad.c:

#!/bin/sh
gcc -g -Wall -lncurses -lgpm $1
An option -m "gcc -g -Wall -lncurses -lgpm" would have done the same, without an external script.

Example 2: "padmak" script to compile a sourcefile with extension .c or .java:

#!/bin/sh
srcname=$1
basname=`echo $srcname|sed -e 's|\..*$||'`
extensn=`echo $srcname|sed -e "s|$basname||"`
if [ $extensn = ".c" ]
then
  gcc -g -Wall $srcname -o $basname -lncurses -lgpm
fi
if [ $extensn = ".java" ]
then
  javac $srcname
fi

r: run
By default "padrun" is run with current filename as argument. The file is not saved and output is not logged.
The option -r <command> allows to specify any command that takes a filename as argument.

Example: simple "padrun" script that runs a previously compiled program:

#!/bin/sh
a.out

x: exec sel
Takes the selected text from the current editor window as a command to execute in a subshell.

s: shell
Starts a subshell by executing /bin/sh. Return to the editor with with the command exit or with CTRL-d.


 
(updated: 18-Mar-2005)