1MLE(1) BSD General Commands Manual MLE(1)
2
4 mle — flexible terminal-based text editor
5
7 mle [-abceHhiKklMmNnpSstuvwxyz] [file[:line]] ...
8
10 mle is a small, flexible, terminal-based text editor written in C. It
11 runs on Linux, Windows (Cygwin or WSL), FreeBSD, macOS, and more.
12
13 Basic usage
14 $ mle # Open blank buffer
15 $ mle one.c # Edit one.c
16 $ mle one.c:100 # Edit one.c at line 100
17 $ mle one.c two.c # Edit one.c and two.c
18 $ mle -h # Show command line help
19
20 The default key bindings are intuitive. Input text as normal, use direc‐
21 tional keys to move around, use `Ctrl-S` to save, `Ctrl-O` to open,
22 `Ctrl-X` to exit.
23
24 Press `F2` for full help.
25
26 Options
27 -h Show help
28
29 -a ⟨1|0⟩ Enable/disable tab to space (default: 1)
30
31 -b ⟨1|0⟩ Enable/disable highlight bracket pairs (default: 1)
32
33 -c column Color column (default: -1, disabled)
34
35 -e ⟨1|0⟩ Enable/disable mouse support (default: 0)
36
37 -H ⟨1|0⟩ Enable/disable headless mode (default: 1 if no tty,
38 else 0)
39
40 -i ⟨1|0⟩ Enable/disable auto indent (default: 0)
41
42 -K kdef Make a kmap definition (use with -k).
43
44 kdef is formatted as
45 `<name>,<default_cmd>,<allow_fallthru>`, where name
46 is the name of the kmap, default_cmd is the default
47 command handler (can be empty), and allow_fallthru is
48 a 0 or 1 specifying whether unhandled key input
49 should be forwarded to the previous kmap on the stack
50 or not.
51
52 -k kbind Add key binding to current kmap definition (use after
53 -K).
54
55 kbind is formatted as `<cmd>,<key>,<param>`, where
56 cmd is a command name, key is a key name, and param
57 is a static parameter passed to the command (can be
58 empty).
59
60 -l ltype Set linenum type (default: 0, absolute).
61
62 ltype can be 0 (absolute), 1 (relative), or 2 (both)
63
64 -M macro Add a macro.
65
66 macro is formatted as `<name> <key1> <key2> ...
67 <keyN>`, where name is the name of the macro, and
68 keyN are space-separated key names.
69
70 -m key Set macro toggle key (default: M-r). key is a key
71 name.
72
73 -N Skip reading of rc file
74
75 -n kmap Set init kmap (default: mle_normal). kmap is a kmap
76 name.
77
78 -p macro Set startup macro. macro is a macro name.
79
80 -S syndef Make a syntax definition (use with -s).
81
82 syndef is formatted as
83 `<name>,<path_pattern>,<tab_width>,<tab_to_space>`,
84 where name is a syntax name, path_pattern is a path
85 matching regex (PCRE), tab_width is the default tab
86 width, tab_to_space is a 0 or 1 specifying whether to
87 convert tabs to spaces or not.
88
89 -s synrule Add syntax rule to current syntax definition (use af‐
90 ter -S).
91
92 synrule is formatted as `<start>,<end>,<fg>,<bg>`,
93 where start and end are text matching regexes (PCRE),
94 and fg and bg are attributes to apply to matching
95 text.
96
97 If both start and end are supplied, the rule applies
98 to all text matched in between the regexes, poten‐
99 tially spanning multiple lines. If only start is
100 specified, the rule applies to text matched by the
101 regex on a single line.
102
103 Attributes for fg and bg are as follows:
104
105 0 default
106
107 1 black
108
109 2 red
110
111 4 yellow
112
113 5 blue
114
115 6 magenta
116
117 7 cyan
118
119 8 white
120
121 256 bold
122
123 512 underline
124
125 1024 reverse
126
127 2048 italic
128
129 -t size Set tab size (default: 4)
130
131 -u ⟨1|0⟩ Enable/disable coarse undo/redo (default: 0)
132
133 -v Print version and exit
134
135 -w ⟨1|0⟩ Enable/disable soft word wrap (default: 0)
136
137 -x uscript Run a Lua user script (experimental)
138
139 -y syntax Set override syntax for files opened at start up. If
140 '-' is specified, use the built-in generic syntax.
141 syntax is any syntax name.
142
143 -z ⟨1|0⟩ Enable/disable trimmed paste (default: 1)
144
146 Key names for -k, -M, and -m are formatted as `<key>` or `<mod>-<key>`.
147
148 key is any character or one of the following: space, tab, enter,
149 backspace, comma, up, down, left, right, insert, delete, home, end, pgup,
150 pgdn, backtab, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12.
151
152 mod is one of
153
154 S Shift
155
156 M Alt (Meta)
157
158 MS Alt-Shift
159
160 C Ctrl
161
162 CS Ctrl-Shift
163
164 CM Ctrl-Alt
165
166 CMS Ctrl-Alt-Shift
167
168 Not all key names are valid or supported by all terminals. Run with
169 `-Qk` to display key names for given input.
170
172 Below are some advanced things you can do with mle.
173
174 rc file
175 To customize the editor, make an rc file named ~/.mlerc or /etc/mlerc.
176 The contents of the rc file are any number of cli options separated by
177 newlines. Lines that begin with a semi-colon are interpreted as com‐
178 ments.
179
180 If the rc file is executable, mle executes it and interprets the result‐
181 ing stdout as described above. For example, consider the following snip‐
182 pet from an executable ~/.mlerc bash(1) script:
183
184 ...
185 # Define 'test' kmap
186 echo '-Ktest,,1'
187
188 # M-q: replace grep with git grep if `.git` exists
189 if [ -d ".git" ]; then
190 echo '-kcmd_grep,M-q,git grep --color=never -P -i -I -n %s 2>/dev/null'
191 fi
192
193 # Set default kmap
194 echo '-n test'
195 ...
196
197 This overrides the built-in grep command with `git grep` if .git exists
198 in the current working directory.
199
200 Shell command integration
201 The following programs will enable or enhance certain features of mle if
202 they exist in PATH.
203
204 bash(1) file tab completion
205
206 fzf(1) fuzzy file search
207
208 grep(1) file grep
209
210 less(1) less integration
211
212 perl(1) perl 1-liners
213
214 readtags(1) ctags integration
215
216 tree(1) file browsing
217
218 Arbitrary shell commands can also be run via `cmd_shell` (M-e by de‐
219 fault). If any text is selected, it is sent to stdin of the command. Any
220 resulting stdout is inserted into the text buffer.
221
222 Headless mode
223 mle provides support for non-interactive editing which may be useful for
224 using the editor as a regular command line tool. In headless mode, mle
225 reads stdin into a buffer, applies a startup macro if specified, and then
226 writes the buffer contents to stdout. For example:
227
228 $ echo -n hello | mle -M 'test C-e space w o r l d enter' -p test
229 hello world
230
231 If stdin is a pipe, mle goes into headless mode automatically. Headless
232 mode can be explicitly enabled or disabled with the `-H` option.
233
234 If stdin is a pipe and headless mode is disabled via -H0, mle reads stdin
235 into a new buffer and then runs as normal in interactive mode.
236
237 Scripting (experimental)
238 mle is extensible via the Lua programming language. Scripts are loaded
239 via the `-x` cli option. Commands registered by scripts can be mapped to
240 keys as normal via `-k`. See https://github.com/adsr/mle for more info.
241
243 mle makes extensive use of the following libraries.
244
245 uthash for hash maps and linked lists
246
247 termbox2 for TUI
248
249 PCRE2 for syntax highlighting and search
250
251BSD March 1, 2023 BSD