Debian Codegraph @

doc.md

raw
1 # NAME
2
3 lf - terminal file manager
4
5 # SYNOPSIS
6
7 **lf**
8 [**-command** *command*]
9 [**-config** *path*]
10 [**-cpuprofile** *path*]
11 [**-doc**]
12 [**-help**]
13 [**-last-dir-path** *path*]
14 [**-log** *path*]
15 [**-memprofile** *path*]
16 [**-print-last-dir**]
17 [**-print-selection**]
18 [**-remote** *command*]
19 [**-selection-path** *path*]
20 [**-server**]
21 [**-single**]
22 [**-version**]
23 [*cd-or-select-path*]
24
25 # DESCRIPTION
26
27 lf is a terminal file manager.
28
29 The source code can be found in the repository at https://github.com/gokcehan/lf
30
31 This documentation can either be read from the terminal using `lf -doc` or online at https://github.com/gokcehan/lf/blob/master/doc.md
32 You can also use the `help` command (default `<f-1>`) inside lf to view the documentation in a pager.
33 A man page with the same content is also available in the repository at https://github.com/gokcehan/lf/blob/master/lf.1
34
35 # OPTIONS
36
37 ## POSITIONAL ARGUMENTS
38
39 **cd-or-select-path**
40
41 Set the starting location. If *path* is a directory, start in there. If it's a file, start in the file's parent directory and select the file. When no *path* is supplied, lf uses the current directory. Only accepts one argument.
42
43 ## META OPTIONS
44
45 **-doc**
46
47 Show lf's documentation (same content as this file) and exit.
48
49 **-help**
50
51 Show command-line usage and exit.
52
53 **-version**
54
55 Show version information and exit.
56
57 ## STARTUP & CONFIGURATION
58
59 **-command** *command*
60
61 Execute *command* during client initialization (i.e. after reading configuration, before `on-init`). To execute more than one command, you can either use the **-command** flag multiple times or pass multiple commands at once by chaining them with ";".
62
63 **-config** *path*
64
65 Use the config file at *path* instead of the normal search locations. This only affects which `lfrc` is read at startup.
66
67 ## SHELL INTEGRATION
68
69 **-print-last-dir**
70
71 Print the last directory to stdout when lf exits. This can be used to let lf change your shell's working directory. See `CHANGING DIRECTORY` for more details.
72
73 **-last-dir-path** *path*
74
75 Same as **-print-last-dir**, but write the directory to *path* instead of stdout.
76
77 **-print-selection**
78
79 Print selected files to stdout when opening a file in lf. This can be used to use lf as an "open file" dialog. First, select the files you want to pass to another program. Then, confirm the selection by opening a file. This causes lf to quit and print out the selection. Quitting lf prematurely discards the selection.
80
81 **-selection-path** *path*
82
83 Same as **-print-selection**, but write the newline-separated list to *path* instead of stdout.
84
85 ## SERVER
86
87 **-remote** *command*
88
89 Send *command* to the running server (i.e. `send`, `query`, `list`, `quit`, or `quit!`). See `REMOTE COMMANDS` for more details.
90
91 **-server**
92
93 Start the (headless) server process explicitly. Runs in the foreground and writes server logs to stderr (or the file set with **-log**). Clients auto-start a server if none is running unless **-single** is used.
94
95 **-single**
96
97 Start a stand-alone client without a server. Disables remote control.
98
99 ## DIAGNOSTICS
100
101 **-log** *path*
102
103 Append runtime log messages to *path*.
104
105 **-cpuprofile** *path*
106
107 Write a CPU profile to *path*. The profile can be used by `go tool pprof`.
108
109 **-memprofile** *path*
110
111 Write a memory profile to *path*. The profile can be used by `go tool pprof`.
112
113 ## EXAMPLES
114
115 Use `lf` to select files (while hiding certain file types):
116
117 lf -command 'set nohidden' -command 'set hiddenfiles "*mp4:*pdf:*txt"' -print-selection
118
119 Another sophisticated "open file" dialog focusing on design:
120
121 lf -command 'set nopreview; set ratios 1; set drawbox; set promptfmt "Select files [%w] %S q: cancel, l: confirm"' -print-selection
122
123 Open Downloads and set `sortby` and `info` to creation date:
124
125 lf -command 'set sortby btime; set info btime' ~/Downloads
126
127 Temporarily prevent `lf` from modifying the command history:
128
129 lf -command 'set nohistory'
130
131 Use default settings and log current session:
132
133 lf -config /dev/null -log /tmp/lf.log
134
135 Force-quit the server:
136
137 lf -remote 'quit!'
138
139 Inherit lf's working directory in your shell:
140
141 cd "$(lf -print-last-dir)"
142
143 # QUICK REFERENCE
144
145 The following commands are provided by lf:
146
147 quit (default 'q')
148 up (default 'k' and '<up>')
149 half-up (default '<c-u>')
150 page-up (default '<c-b>' and '<pgup>')
151 scroll-up (default '<c-y>')
152 down (default 'j' and '<down>')
153 half-down (default '<c-d>')
154 page-down (default '<c-f>' and '<pgdn>')
155 scroll-down (default '<c-e>')
156 updir (default 'h' and '<left>')
157 open (default 'l' and '<right>')
158 jump-next (default ']')
159 jump-prev (default '[')
160 top (default 'gg' and '<home>')
161 bottom (default 'G' and '<end>')
162 high (default 'H')
163 middle (default 'M')
164 low (default 'L')
165 toggle
166 invert (default 'v')
167 unselect (default 'u')
168 glob-select
169 glob-unselect
170 copy (default 'y')
171 cut (default 'd')
172 paste (default 'p')
173 clear (default 'c')
174 sync
175 draw
176 redraw (default '<c-l>')
177 load
178 reload (default '<c-r>')
179 delete (modal)
180 rename (modal) (default 'r')
181 read (modal) (default ':')
182 shell (modal) (default '$')
183 shell-pipe (modal) (default '%')
184 shell-wait (modal) (default '!')
185 shell-async (modal) (default '&')
186 find (modal) (default 'f')
187 find-back (modal) (default 'F')
188 find-next (default ';')
189 find-prev (default ',')
190 search (modal) (default '/')
191 search-back (modal) (default '?')
192 search-next (default 'n')
193 search-prev (default 'N')
194 filter (modal)
195 setfilter
196 mark-save (modal) (default 'm')
197 mark-load (modal) (default "'")
198 mark-remove (modal) (default '"')
199 tag
200 tag-toggle (default 't')
201 echo
202 echomsg
203 echoerr
204 cd
205 select
206 source
207 push
208 addcustominfo
209 calcdirsize
210 clearmaps
211 tty-write
212 visual (default 'V')
213
214 The following Visual mode commands are provided by lf:
215
216 visual-accept (default 'V')
217 visual-unselect
218 visual-discard (default '<esc>')
219 visual-change (default 'o')
220
221 The following Command-line mode commands are provided by lf:
222
223 cmd-insert
224 cmd-escape (default '<esc>')
225 cmd-complete (default '<tab>')
226 cmd-menu-complete
227 cmd-menu-complete-back
228 cmd-menu-accept
229 cmd-menu-discard
230 cmd-enter (default '<c-j>' and '<enter>')
231 cmd-interrupt (default '<c-c>')
232 cmd-history-next (default '<c-n>' and '<down>')
233 cmd-history-prev (default '<c-p>' and '<up>')
234 cmd-left (default '<c-b>' and '<left>')
235 cmd-right (default '<c-f>' and '<right>')
236 cmd-home (default '<c-a>' and '<home>')
237 cmd-end (default '<c-e>' and '<end>')
238 cmd-delete (default '<c-d>' and '<delete>')
239 cmd-delete-back (default '<backspace>')
240 cmd-delete-home (default '<c-u>')
241 cmd-delete-end (default '<c-k>')
242 cmd-delete-unix-word (default '<c-w>')
243 cmd-yank (default '<c-y>')
244 cmd-transpose (default '<c-t>')
245 cmd-transpose-word (default '<a-t>')
246 cmd-word (default '<a-f>')
247 cmd-word-back (default '<a-b>')
248 cmd-delete-word (default '<a-d>')
249 cmd-delete-word-back (default '<a-backspace>')
250 cmd-capitalize-word (default '<a-c>')
251 cmd-uppercase-word (default '<a-u>')
252 cmd-lowercase-word (default '<a-l>')
253
254 The following options can be used to customize the behavior of lf:
255
256 anchorfind bool (default true)
257 autoquit bool (default true)
258 borderfmt string (default "\033[0m")
259 borderstyle string (default 'box')
260 cleaner string (default '')
261 copyfmt string (default "\033[7;33m")
262 cursoractivefmt string (default "\033[7m")
263 cursorparentfmt string (default "\033[7m")
264 cursorpreviewfmt string (default "\033[4m")
265 cutfmt string (default "\033[7;31m")
266 dircounts bool (default false)
267 dirfirst bool (default true)
268 dironly bool (default false)
269 dirpreviews bool (default false)
270 drawbox bool (default false)
271 dupfilefmt string (default '%f.~%n~')
272 errorfmt string (default "\033[7;31;47m")
273 filesep string (default "\n")
274 filtermethod string (default 'text')
275 findlen int (default 1)
276 hidden bool (default false)
277 hiddenfiles []string (default '.*' for Unix and '' for Windows)
278 history bool (default true)
279 icons bool (default false)
280 ifs string (default '')
281 ignorecase bool (default true)
282 ignoredia bool (default true)
283 incfilter bool (default false)
284 incsearch bool (default false)
285 info []string (default '')
286 infotimefmtnew string (default 'Jan _2 15:04')
287 infotimefmtold string (default 'Jan _2 2006')
288 menufmt string (default "\033[0m")
289 menuheaderfmt string (default "\033[1m")
290 menuselectfmt string (default "\033[7m")
291 mergeindicators bool (default false)
292 mouse bool (default false)
293 number bool (default false)
294 numbercursorfmt string (default '')
295 numberfmt string (default "\033[33m")
296 period int (default 0)
297 preload bool (default false)
298 preserve []string (default "mode")
299 preview bool (default true)
300 previewer string (default '')
301 promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m")
302 ratios []int (default '1:2:3')
303 relativenumber bool (default false)
304 reverse bool (default false)
305 rulerfile string (default "")
306 rulerfmt string (default "")
307 scrolloff int (default 0)
308 searchmethod string (default 'text')
309 selectfmt string (default "\033[7;35m")
310 selmode string (default 'all')
311 shell string (default 'sh' for Unix and 'cmd' for Windows)
312 shellflag string (default '-c' for Unix and '/c' for Windows)
313 shellopts []string (default '')
314 showbinds bool (default true)
315 sizeunits string (default 'binary')
316 smartcase bool (default true)
317 smartdia bool (default false)
318 sortby string (default 'natural')
319 sortignorecase bool (default true)
320 sortignoredia bool (default true)
321 statfmt string (default "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l")
322 tabstop int (default 8)
323 tagfmt string (default "\033[31m")
324 tempmarks string (default '')
325 terminalcursor string (default 'default')
326 timefmt string (default 'Mon Jan _2 15:04:05 2006')
327 truncatechar string (default '~')
328 truncatepct int (default 100)
329 visualfmt string (default "\033[7;36m")
330 waitmsg string (default 'Press any key to continue')
331 watch bool (default false)
332 wrapscan bool (default true)
333 wrapscroll bool (default false)
334 user_{option} string (default none)
335
336 The following environment variables are exported for shell commands:
337
338 f
339 fs
340 fv
341 fx
342 id
343 PWD
344 OLDPWD
345 LF_LEVEL
346 OPENER
347 VISUAL
348 EDITOR
349 PAGER
350 SHELL
351 lf
352 lf_{option}
353 lf_user_{option}
354 lf_flag_{flag}
355 lf_width
356 lf_height
357 lf_count
358 lf_mode
359
360 The following special shell commands are used to customize the behavior of lf when defined:
361
362 open
363 paste
364 rename
365 delete
366 pre-cd
367 on-cd
368 on-load
369 on-focus-gained
370 on-focus-lost
371 on-init
372 on-select
373 on-redraw
374 on-quit
375
376 The following commands/keybindings are provided by default:
377
378 Unix
379 cmd open &$OPENER "$f"
380 map e $$EDITOR "$f"
381 map i $$PAGER "$f"
382 map w $$SHELL
383 cmd help $$lf -doc | $PAGER
384 map <f-1> help
385 cmd maps $lf -remote "query $id maps" | $PAGER
386 cmd nmaps $lf -remote "query $id nmaps" | $PAGER
387 cmd vmaps $lf -remote "query $id vmaps" | $PAGER
388 cmd cmaps $lf -remote "query $id cmaps" | $PAGER
389 cmd cmds $lf -remote "query $id cmds" | $PAGER
390
391 Windows
392 cmd open &%OPENER% %f%
393 map e $%EDITOR% %f%
394 map i !%PAGER% %f%
395 map w $%SHELL%
396 cmd help !%lf% -doc | %PAGER%
397 map <f-1> help
398 cmd maps !%lf% -remote "query %id% maps" | %PAGER%
399 cmd nmaps !%lf% -remote "query %id% nmaps" | %PAGER%
400 cmd vmaps !%lf% -remote "query %id% vmaps" | %PAGER%
401 cmd cmaps !%lf% -remote "query %id% cmaps" | %PAGER%
402 cmd cmds !%lf% -remote "query %id% cmds" | %PAGER%
403
404 The defaults for Windows are using `cmd` syntax.
405 A `PowerShell` compatible configuration file can be found at
406 https://github.com/gokcehan/lf/blob/master/etc/lfrc.ps1.example
407
408 The following additional keybindings are provided by default:
409
410 map zh set hidden!
411 map zr set reverse!
412 map zn set info
413 map zs set info size
414 map zt set info time
415 map za set info size:time
416 map sn :set sortby natural; set info
417 map ss :set sortby size; set info size
418 map st :set sortby time; set info time
419 map sa :set sortby atime; set info atime
420 map sb :set sortby btime; set info btime
421 map sc :set sortby ctime; set info ctime
422 map se :set sortby ext; set info
423 map gh cd ~
424 nmap <space> :toggle; down
425
426 If the `mouse` option is enabled, mouse buttons have the following default effects:
427
428 Left mouse button
429 Click on a file or directory to select it.
430
431 Right mouse button
432 Enter a directory or open a file. Also works on the preview pane.
433
434 Scroll wheel
435 Move up or down. If Ctrl is pressed, scroll up or down.
436
437 # CONFIGURATION
438
439 Configuration files should be located at:
440
441 OS system-wide user-specific
442 Unix /etc/lf/lfrc ~/.config/lf/lfrc
443 Windows C:\ProgramData\lf\lfrc C:\Users\<user>\AppData\Roaming\lf\lfrc
444
445 The colors file should be located at:
446
447 OS system-wide user-specific
448 Unix /etc/lf/colors ~/.config/lf/colors
449 Windows C:\ProgramData\lf\colors C:\Users\<user>\AppData\Roaming\lf\colors
450
451 The icons file should be located at:
452
453 OS system-wide user-specific
454 Unix /etc/lf/icons ~/.config/lf/icons
455 Windows C:\ProgramData\lf\icons C:\Users\<user>\AppData\Roaming\lf\icons
456
457 The selection file should be located at:
458
459 Unix ~/.local/share/lf/files
460 Windows C:\Users\<user>\AppData\Local\lf\files
461
462 The marks file should be located at:
463
464 Unix ~/.local/share/lf/marks
465 Windows C:\Users\<user>\AppData\Local\lf\marks
466
467 The tags file should be located at:
468
469 Unix ~/.local/share/lf/tags
470 Windows C:\Users\<user>\AppData\Local\lf\tags
471
472 The history file should be located at:
473
474 Unix ~/.local/share/lf/history
475 Windows C:\Users\<user>\AppData\Local\lf\history
476
477 You can configure these locations with the following variables given with their order of precedences and their default values:
478
479 Unix
480 $LF_CONFIG_HOME
481 $XDG_CONFIG_HOME
482 ~/.config
483
484 $LF_DATA_HOME
485 $XDG_DATA_HOME
486 ~/.local/share
487
488 Windows
489 %LF_CONFIG_HOME%
490 %XDG_CONFIG_HOME%
491 %APPDATA%
492
493 %LF_DATA_HOME%
494 %XDG_DATA_HOME%
495 %LOCALAPPDATA%
496
497 A sample configuration file can be found at
498 https://github.com/gokcehan/lf/blob/master/etc/lfrc.example
499
500 # COMMANDS
501
502 This section shows information about built-in commands.
503 Modal commands do not take any arguments, but instead change the operation mode to read their input conveniently, and so they are meant to be assigned to keybindings.
504
505 ## quit (default `q`)
506
507 Quit lf and return to the shell.
508
509 ## up (default `k` and `<up>`), half-up (default `<c-u>`), page-up (default `<c-b>` and `<pgup>`), scroll-up (default `<c-y>`), down (default `j` and `<down>`), half-down (default `<c-d>`), page-down (default `<c-f>` and `<pgdn>`), scroll-down (default `<c-e>`)
510
511 Move/scroll the current file selection upwards/downwards by one/half a page/full page.
512
513 ## updir (default `h` and `<left>`)
514
515 Change the current working directory to the parent directory.
516
517 ## open (default `l` and `<right>`)
518
519 If the current file is a directory, then change the current directory to it, otherwise, execute the `open` command.
520 A default `open` command is provided to call the default system opener asynchronously with the current file as the argument.
521 A custom `open` command can be defined to override this default.
522
523 ## jump-next (default `]`), jump-prev (default `[`)
524
525 Change the current working directory to the next/previous jumplist item.
526
527 ## top (default `gg` and `<home>`), bottom (default `G` and `<end>`)
528
529 Move the current file selection to the top/bottom of the directory.
530 A count can be specified to move to a specific line, for example, use `3G` to move to the third line.
531
532 ## high (default `H`), middle (default `M`), low (default `L`)
533
534 Move the current file selection to the high/middle/low of the screen.
535
536 ## toggle
537
538 Toggle the selection of the current file or files given as arguments.
539
540 ## invert (default `v`)
541
542 Reverse the selection of all files in the current directory (i.e. `toggle` all files).
543 Selections in other directories are not affected by this command.
544 You can define a new command to select all files in the directory by combining `invert` with `unselect` (i.e. `cmd select-all :unselect; invert`), though this will also remove selections in other directories.
545
546 ## unselect (default `u`)
547
548 Remove the selection of all files in all directories.
549
550 ## glob-select, glob-unselect
551
552 Select/unselect files that match the given glob.
553
554 ## copy (default `y`)
555
556 Save the paths of selected files to the clipboard as files to be copied.
557 If there are no selected files, the path of the current file is used instead.
558
559 ## cut (default `d`)
560
561 Save the paths of selected files to the clipboard as files to be moved.
562 If there are no selected files, the path of the current file is used instead.
563
564 ## paste (default `p`)
565
566 Copy/Move files in the clipboard to the current working directory.
567 A custom `paste` command can be defined to override this default.
568
569 ## clear (default `c`)
570
571 Clear file paths in the clipboard.
572
573 ## sync
574
575 Synchronize copied/cut files with the server.
576 This command is automatically called when required.
577
578 ## draw
579
580 Draw the screen.
581 This command is automatically called when required.
582
583 ## redraw (default `<c-l>`)
584
585 Synchronize the terminal and redraw the screen.
586
587 ## load
588
589 Load modified files and directories.
590 This command is automatically called when required.
591
592 ## reload (default `<c-r>`)
593
594 Flush the cache and reload all files and directories.
595
596 ## delete (modal)
597
598 Remove the current file or selected file(s).
599 A custom `delete` command can be defined to override this default.
600
601 ## rename (modal) (default `r`)
602
603 Rename the current file using the built-in method.
604 A custom `rename` command can be defined to override this default.
605
606 ## read (modal) (default `:`)
607
608 Read a command to evaluate.
609
610 ## shell (modal) (default `$`)
611
612 Read a shell command to execute.
613
614 ## shell-pipe (modal) (default `%`)
615
616 Read a shell command to execute piping its standard I/O to the bottom statline.
617
618 ## shell-wait (modal) (default `!`)
619
620 Read a shell command to execute and wait for a key press at the end.
621
622 ## shell-async (modal) (default `&`)
623
624 Read a shell command to execute asynchronously without standard I/O.
625
626 ## find (modal) (default `f`), find-back (modal) (default `F`), find-next (default `;`), find-prev (default `,`)
627
628 Read key(s) to find the appropriate filename match in the forward/backward direction and jump to the next/previous match.
629
630 ## search (default `/`), search-back (default `?`), search-next (default `n`), search-prev (default `N`)
631
632 Read a pattern to search for a filename match in the forward/backward direction and jump to the next/previous match.
633
634 ## filter (modal), setfilter
635
636 Command `filter` reads a pattern to filter out and only view files matching the pattern.
637 Command `setfilter` does the same but uses an argument to set the filter immediately.
638 You can supply an argument to `filter` to use as the starting prompt.
639
640 ## mark-save (modal) (default `m`)
641
642 Save the current directory as a bookmark assigned to the given key.
643
644 ## mark-load (modal) (default `'`)
645
646 Change the current directory to the bookmark assigned to the given key.
647 A special bookmark `'` holds the previous directory after a `mark-load`, `cd`, or `select` command.
648
649 ## mark-remove (modal) (default `"`)
650
651 Remove a bookmark assigned to the given key.
652
653 ## tag
654
655 Tag a file with `*` or a single-width character given in the argument.
656 You can define a new tag-clearing command by combining `tag` with `tag-toggle` (i.e. `cmd tag-clear :tag; tag-toggle`).
657
658 ## tag-toggle (default `t`)
659
660 Tag a file with `*` or a single-width character given in the argument if the file is untagged, otherwise remove the tag.
661
662 ## echo
663
664 Print the given arguments to the message line at the bottom.
665
666 ## echomsg
667
668 Print the given arguments to the message line at the bottom and also to the log file.
669
670 ## echoerr
671
672 Print given arguments to the message line at the bottom as `errorfmt` and also to the log file.
673
674 ## cd
675
676 Change the working directory to the given argument.
677
678 ## select
679
680 Change the current file selection to the given argument.
681
682 ## source
683
684 Read the configuration file given in the argument.
685
686 ## push
687
688 Simulate key pushes given in the argument.
689
690 ## addcustominfo
691
692 Update the `custom` info and `.Stat.CustomInfo` field of the given file with the given string.
693 The info string may contain ANSI escape codes to further customize its appearance.
694 If no info is provided, clear the file's info instead.
695
696 ## calcdirsize
697
698 Calculate the total size for each of the selected directories.
699 Option `info` should include `size` and option `dircounts` should be disabled to show this size.
700 If the total size of a directory is not calculated, it will be shown as `-`.
701
702 ## clearmaps
703
704 Remove all keybindings associated with the `map`, `nmap` and `vmap` command.
705 This command can be used in the config file to remove the default keybindings.
706 For safety purposes, `:` is left mapped to the `read` command, and `cmap` keybindings are retained so that it is still possible to exit `lf` using `:quit`.
707
708 ## tty-write
709
710 Write the given string to the tty.
711 This is useful for sending escape sequences to the terminal to control its behavior (e.g. OSC 0 to set the window title).
712 Using `tty-write` is preferred over directly writing to `/dev/tty` because the latter is not synchronized and can interfere with drawing the UI.
713
714 ## visual (default `V`)
715
716 Switch to Visual mode.
717 If already in Visual mode, discard the visual selection and stay in Visual mode.
718
719 # VISUAL MODE COMMANDS
720
721 ## visual-accept (default `V`)
722
723 Add the visual selection to the selection list, quit Visual mode and return to Normal mode.
724
725 ## visual-unselect
726
727 Remove the visual selection from the selection list, quit Visual mode and return to Normal mode.
728
729 ## visual-discard (default `<esc>`)
730
731 Discard the visual selection, quit Visual mode and return to Normal mode.
732
733 ## visual-change (default `o`)
734
735 Go to the other end of the current Visual mode selection.
736
737 # COMMAND-LINE MODE COMMANDS
738
739 The prompt character specifies which of the several Command-line modes you are in.
740 For example, the `read` command takes you to the `:` mode.
741
742 When the cursor is at the first character in `:` mode, pressing one of the keys `!`, `$`, `%`, or `&` takes you to the corresponding mode.
743 You can go back with `cmd-delete-back` (`<backspace>` by default).
744
745 The command line commands should be mostly compatible with readline keybindings.
746 A character refers to a Unicode code point, a word consists of letters and digits, and a Unix word consists of any non-blank characters.
747
748 ## cmd-insert
749
750 Insert the character given in the argument.
751 This command is automatically called when required.
752
753 ## cmd-escape (default `<esc>`)
754
755 Quit Command-line mode and return to Normal mode.
756
757 ## cmd-complete (default `<tab>`)
758
759 Autocomplete the current word.
760
761 ## cmd-menu-complete, cmd-menu-complete-back
762
763 Autocomplete the current word with the menu selection.
764 You need to assign keys to these commands (e.g. `cmap <tab> cmd-menu-complete; cmap <backtab> cmd-menu-complete-back`).
765 You can use the assigned keys to display the menu and then cycle through completion options.
766
767 ## cmd-menu-accept
768
769 Accept the currently selected match in menu completion and close the menu.
770
771 ## cmd-menu-discard
772
773 Discard the currently selected match in menu completion and close the menu.
774
775 ## cmd-enter (default `<c-j>` and `<enter>`)
776
777 Execute the current line.
778
779 ## cmd-interrupt (default `<c-c>`)
780
781 Interrupt the current shell-pipe command and return to the Normal mode.
782
783 ## cmd-history-next (default `<c-n>` and `<down>`), cmd-history-prev (default `<c-p>` and `<up>`)
784
785 Go to the next/previous entry in the command history.
786 If part of the command is already typed, then only matching entries will be considered, and consecutive duplicate entries are skipped.
787
788 ## cmd-left (default `<c-b>` and `<left>`), cmd-right (default `<c-f>` and `<right>`)
789
790 Move the cursor to the left/right.
791
792 ## cmd-home (default `<c-a>` and `<home>`), cmd-end (default `<c-e>` and `<end>`)
793
794 Move the cursor to the beginning/end of the line.
795
796 ## cmd-delete (default `<c-d>` and `<delete>`)
797
798 Delete the next character.
799
800 ## cmd-delete-back (default `<backspace>`)
801
802 Delete the previous character.
803 When at the beginning of a prompt, returns either to Normal mode or to `:` mode.
804
805 ## cmd-delete-home (default `<c-u>`), cmd-delete-end (default `<c-k>`)
806
807 Delete everything up to the beginning/end of the line.
808
809 ## cmd-delete-unix-word (default `<c-w>`)
810
811 Delete the previous Unix word.
812
813 ## cmd-yank (default `<c-y>`)
814
815 Paste the buffer content containing the last deleted item.
816
817 ## cmd-transpose (default `<c-t>`)
818
819 Swap the characters before and after the cursor, then move the cursor forward.
820 If there is no character after the cursor, swap the previous two characters instead.
821
822 ## cmd-transpose-word (default `<a-t>`)
823
824 Swap the words before and after the cursor, then move the cursor forward.
825 If there is no word after the cursor, swap the previous two words instead.
826
827 ## cmd-word (default `<a-f>`), cmd-word-back (default `<a-b>`)
828
829 Move the cursor by one word in the forward/backward direction.
830
831 ## cmd-delete-word (default `<a-d>`)
832
833 Delete the next word in the forward direction.
834
835 ## cmd-delete-word-back (default `<a-backspace>`)
836
837 Delete the previous word in the backward direction.
838
839 ## cmd-capitalize-word (default `<a-c>`), cmd-uppercase-word (default `<a-u>`), cmd-lowercase-word (default `<a-l>`)
840
841 Capitalize/uppercase/lowercase the current word and jump to the next word.
842
843 # SETTINGS
844
845 This section shows information about options to customize the behavior.
846 Character `:` is used as the separator for list options `[]int` and `[]string`.
847
848 ## anchorfind (bool) (default true)
849
850 When this option is enabled, the find command starts matching patterns from the beginning of filenames, otherwise, it can match at an arbitrary position.
851
852 ## autoquit (bool) (default true)
853
854 Automatically quit the server when there are no clients left connected.
855
856 ## borderfmt (string) (default `\033[0m`)
857
858 Format string of border characters.
859
860 ## borderstyle (string) (default `box`)
861
862 Border style used by `drawbox`.
863
864 The following styles are supported:
865
866 box outline around all panes and separators between them
867 roundbox like `box`, but with rounded outer corners
868 outline outline around all panes
869 roundoutline like `outline`, but with rounded outer corners
870 separators separators between panes
871
872 ## cleaner (string) (default ``) (not called if empty)
873
874 Set the path of a cleaner file.
875 The file should be executable.
876 This file is called if previewing is enabled, the previewer is set, and the previously selected file has its preview cache disabled.
877 The following arguments are passed to the file, (1) current filename, (2) width, (3) height, (4) horizontal position, (5) vertical position of preview pane and (6) next filename to be previewed respectively.
878 Preview cleaning is disabled when the value of this option is left empty.
879
880 ## copyfmt (string) (default `\033[7;33m`)
881
882 Format string of the indicator for files to be copied.
883
884 ## cursoractivefmt (string) (default `\033[7m`), cursorparentfmt (string) (default `\033[7m`), cursorpreviewfmt (string) (default `\033[4m`)
885
886 Format strings for highlighting the cursor.
887 `cursoractivefmt` applies in the current directory pane,
888 `cursorparentfmt` applies in panes that show parents of the current directory,
889 and `cursorpreviewfmt` applies in panes that preview directories.
890
891 The default is to make the active cursor and the parent directory cursor inverted. The preview cursor is underlined.
892
893 Some other possibilities to consider for the preview or parent cursors: an empty string for no cursor, `\033[7;2m` for dimmed inverted text (visibility varies by terminal), `\033[7;90m` for inverted text with grey (aka "brightblack") background.
894
895 If the format string contains the characters `%s`, it is interpreted as a format string for `fmt.Sprintf`. Such a string should end with the terminal reset sequence.
896 For example, `\033[4m%s\033[0m` has the same effect as `\033[4m`.
897
898 ## cutfmt (string) (default `\033[7;31m`)
899
900 Format string of the indicator for files to be cut.
901
902 ## dircounts (bool) (default false)
903
904 When this option is enabled, directory sizes show the number of items inside instead of the total size of the directory, which needs to be calculated for each directory using `calcdirsize`.
905 This information needs to be calculated by reading the directory and counting the items inside.
906 Therefore, this option is disabled by default for performance reasons.
907 This option only has an effect when `info` has a `size` field and the pane is wide enough to show the information.
908 9999 items are counted per directory at most, and bigger directories are shown as `9999+`.
909
910 ## dirfirst (bool) (default true)
911
912 Show directories first above regular files.
913 With `dircounts` enabled, sorting by `size` always separates directories and files, regardless of `dirfirst`.
914
915 ## dironly (bool) (default false)
916
917 Show only directories.
918
919 ## dirpreviews (bool) (default false)
920
921 If enabled, directories will also be passed to the previewer script. This allows custom previews for directories.
922
923 ## drawbox (bool) (default false)
924
925 Draw borders around panes using box drawing characters.
926
927 ## dupfilefmt (string) (default `%f.~%n~`)
928
929 Format string of filename when creating duplicate files. With the default format, copying a file `abc.txt` to the same directory will result in a duplicate file called `abc.txt.~1~`.
930 Special expansions are provided, `%f` as the file name, `%b` for the base name (file name without extension), `%e` as the extension (including the dot) and `%n` as the number of duplicates.
931
932 ## errorfmt (string) (default `\033[7;31;47m`)
933
934 Format string of error messages shown in the bottom message line.
935
936 If the format string contains the characters `%s`, it is interpreted as a format string for `fmt.Sprintf`. Such a string should end with the terminal reset sequence.
937 For example, `\033[4m%s\033[0m` has the same effect as `\033[4m`.
938
939 ## filesep (string) (default `\n`)
940
941 File separator used in environment variables `fs`, `fv` and `fx`.
942
943 ## filtermethod (string) (default `text`)
944
945 How filter command patterns are treated.
946 Currently supported methods are `text` (i.e. string literals), `glob` (i.e. shell globs) and `regex` (i.e. regular expressions).
947 See `SEARCHING FILES` for more details.
948
949 ## findlen (int) (default 1)
950
951 Number of characters prompted for the find command.
952 When this value is set to 0, find command prompts until there is only a single match left.
953
954 ## hidden (bool) (default false)
955
956 Show hidden files.
957 On Unix systems, hidden files are determined by the value of `hiddenfiles`.
958 On Windows, files with hidden attributes are also considered hidden files.
959
960 ## hiddenfiles ([]string) (default `.*` for Unix and `` for Windows)
961
962 List of hidden file glob patterns.
963 Patterns can be given as relative or absolute paths.
964 Globbing supports the usual special characters, `*` to match any sequence, `?` to match any character, and `[...]` or `[^...]` to match character sets or ranges.
965 In addition, if a pattern starts with `!`, then its matches are excluded from hidden files. To add multiple patterns, use `:` as a separator. Example: `.*:lost+found:*.bak`
966
967 ## history (bool) (default true)
968
969 Save command history.
970
971 ## icons (bool) (default false)
972
973 Show icons before each item in the list.
974
975 ## ifs (string) (default ``)
976
977 Sets `IFS` variable in shell commands.
978 It works by adding the assignment to the beginning of the command string as `IFS=...; ...`.
979 The reason is that `IFS` variable is not inherited by the shell for security reasons.
980 This method assumes a POSIX shell syntax so it can fail for non-POSIX shells.
981 This option has no effect when the value is left empty.
982 This option does not have any effect on Windows.
983
984 ## ignorecase (bool) (default true)
985
986 Ignore case in search patterns. See also `sortignorecase`.
987
988 ## ignoredia (bool) (default true)
989
990 Ignore diacritics in search patterns. See also `sortignoredia`.
991
992 ## incfilter (bool) (default false)
993
994 Apply filter pattern after each keystroke during filtering.
995
996 ## incsearch (bool) (default false)
997
998 Jump to the first match after each keystroke during searching.
999
1000 ## info ([]string) (default ``)
1001
1002 A list of information that is shown for directory items at the right side of the pane.
1003
1004 The following information types are supported:
1005
1006 perm file permission
1007 user user name
1008 group group name
1009 size file size
1010 time time of last data modification
1011 atime time of last access
1012 btime time of file birth
1013 ctime time of last status (inode) change
1014 custom property defined via `addcustominfo` (empty by default)
1015
1016 Information is only shown when the pane width is more than twice the width of information.
1017
1018 ## infotimefmtnew (string) (default `Jan _2 15:04`)
1019
1020 Format string of the file time shown in the info column when it matches this year.
1021
1022 ## infotimefmtold (string) (default `Jan _2 2006`)
1023
1024 Format string of the file time shown in the info column when it doesn't match this year.
1025
1026 ## menufmt (string) (default `\033[0m`)
1027
1028 Format string of the menu.
1029
1030 ## menuheaderfmt (string) (default `\033[1m`)
1031
1032 Format string of the header row in the menu.
1033
1034 ## menuselectfmt (string) (default `\033[7m`)
1035
1036 Format string of the currently selected item in the menu.
1037
1038 ## mergeindicators (bool) (default false)
1039
1040 When `mergeindicators` is enabled, tag and selection indicators are drawn in a single column to reduce the gap before filenames.
1041 If a file is both tagged and selected, the tag uses the selection format (e.g. `copyfmt`) instead of `tagfmt`.
1042
1043 ## mouse (bool) (default false)
1044
1045 Send mouse events as input.
1046
1047 ## number (bool) (default false)
1048
1049 Show the position number for directory items on the left side of the pane.
1050 When the `relativenumber` option is enabled, only the current line shows the absolute position and relative positions are shown for the rest.
1051
1052 ## numberfmt (string) (default `\033[33m`), numbercursorfmt (string) (default ``)
1053
1054 Format strings for highlighting line numbers.
1055 `numberfmt` applies to all lines.
1056 `numbercursorfmt` applies to the cursor line and falls back to `numberfmt` when left empty.
1057
1058 ## period (int) (default 0)
1059
1060 Set the interval in seconds for periodic checks of directory updates.
1061 This works by periodically calling the `load` command.
1062 Note that directories are already updated automatically in many cases.
1063 This option can be useful when there is an external process changing the displayed directory and you are not doing anything in lf.
1064 Periodic checks are disabled when the value of this option is set to zero.
1065
1066 ## preload (bool) (default false)
1067
1068 Allow previews to be generated in advance using the `previewer` script as the user navigates through the filesystem.
1069
1070 ## preserve ([]string) (default `mode`)
1071
1072 List of attributes that are preserved when copying files.
1073 Currently supported attributes are `mode` (i.e. access mode) and `timestamps` (i.e. modification time and access time).
1074 Note that preserving other attributes like ownership or change/birth timestamps is desirable, but not portably supported in Go.
1075
1076 ## preview (bool) (default true)
1077
1078 Show previews of files and directories at the rightmost pane.
1079 If the file has more lines than the preview pane, the rest of the lines are not read.
1080 Files are considered binary and displayed as `binary` if the read portion contains a control character other than bell, backspace, tab, newline, vertical tab, form feed, carriage return, escape or delete.
1081
1082 ## previewer (string) (default ``) (not filtered if empty)
1083
1084 Set the path of a previewer file to filter the content of regular files for previewing.
1085 The file should be executable.
1086 The following arguments are passed to the file, (1) current filename, (2) width, (3) height, (4) horizontal position, (5) vertical position, and (6) mode ("preview" or "preload").
1087 SIGPIPE signal is sent when enough lines are read.
1088 If the previewer returns a non-zero exit code, then the preview cache for the given file is disabled.
1089 This means that if the file is selected in the future, the previewer is called once again.
1090 Preview filtering is disabled and files are displayed as they are when the value of this option is left empty.
1091 If the `preload` option is enabled, then this will be called with `preload` as the mode when preloading file previews.
1092 Refer to the [PREVIEWING FILES section](https://github.com/gokcehan/lf/blob/master/doc.md#previewing-files) for more information about how to configure custom previews.
1093
1094 ## promptfmt (string) (default `\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m`)
1095
1096 Format string of the prompt shown in the top line.
1097
1098 The following special expansions are supported:
1099
1100 %f file name
1101 %h host name
1102 %u user name
1103 %w working directory
1104 %d working directory (with trailing path separator)
1105 %F current filter
1106 %S spacer to right-align the following parts (can be used once)
1107
1108 The home folder is shown as `~` in the working directory expansion.
1109 Directory names are automatically shortened to a single character starting from the leftmost parent when the prompt does not fit the screen.
1110
1111 ## ratios ([]int) (default `1:2:3`)
1112
1113 List of ratios of pane widths.
1114 Number of items in the list determines the number of panes in the UI.
1115 When the `preview` option is enabled, the rightmost number is used for the width of the preview pane.
1116
1117 ## relativenumber (bool) (default false)
1118
1119 Show the position number relative to the current line.
1120 When `number` is enabled, the current line shows the absolute position, otherwise nothing is shown.
1121
1122 ## reverse (bool) (default false)
1123
1124 Reverse the direction of sort.
1125
1126 ## rulerfile (string) (default ``)
1127
1128 Set the path of the ruler file.
1129 If not set, then a default template will be used for the ruler.
1130 Refer to the [RULER section](https://github.com/gokcehan/lf/blob/master/doc.md#ruler) for more information about how the ruler file works.
1131
1132 ## rulerfmt (string) (default ``)
1133
1134 Format string of the ruler shown in the bottom right corner.
1135 When set, it will be used along with `statfmt` to draw the ruler, and `rulerfile` will be ignored.
1136 However, using `rulerfile` is preferred and this option is provided for backwards compatibility.
1137
1138 The following special expansions are supported:
1139
1140 %a pressed keys
1141 %p progress of file operations
1142 %m number of files to be cut (moved)
1143 %c number of files to be copied
1144 %s number of selected files
1145 %v number of visually selected files
1146 %t number of shown files in the current directory
1147 %h number of hidden files in the current directory
1148 %f current filter
1149 %i cursor position
1150 %P scroll percentage
1151 %d amount of free disk space
1152
1153 Additional expansions are provided for environment variables exported by lf, in the form `%{lf_<name>}` (e.g. `%{lf_selmode}`). This is useful for displaying the current settings.
1154 Expansions are also provided for user-defined options, in the form `%{lf_user_<name>}` (e.g. `%{lf_user_foo}`).
1155 The `|` character splits the format string into sections. Any section containing a failed expansion (result is a blank string) is discarded and not shown.
1156
1157 ## scrolloff (int) (default 0)
1158
1159 Minimum number of offset lines shown at all times at the top and bottom of the screen when scrolling.
1160 The current line is kept in the middle when this option is set to a large value that is bigger than half the number of lines.
1161 A smaller offset can be used when the current file is close to the beginning or end of the list to show the maximum number of items.
1162
1163 ## searchmethod (string) (default `text`)
1164
1165 How search command patterns are treated.
1166 Currently supported methods are `text` (i.e. string literals), `glob` (i.e. shell globs) and `regex` (i.e. regular expressions).
1167 See `SEARCHING FILES` for more details.
1168
1169 ## selectfmt (string) (default `\033[7;35m`)
1170
1171 Format string of the indicator for files that are selected.
1172
1173 ## selmode (string) (default `all`)
1174
1175 Selection mode for commands.
1176 When set to `all` it will use the selected files from all directories.
1177 When set to `dir` it will only use the selected files in the current directory.
1178
1179 ## shell (string) (default `sh` for Unix and `cmd` for Windows)
1180
1181 Shell executable to use for shell commands.
1182 Shell commands are executed as `shell shellopts shellflag command -- arguments`.
1183
1184 ## shellflag (string) (default `-c` for Unix and `/c` for Windows)
1185
1186 Command line flag used to pass shell commands.
1187
1188 ## shellopts ([]string) (default ``)
1189
1190 List of shell options to pass to the shell executable.
1191
1192 ## showbinds (bool) (default true)
1193
1194 Show bindings associated with pressed keys.
1195
1196 ## sizeunits (string) (default `binary`)
1197
1198 Determines whether file sizes are displayed using binary units (`1K` is 1024 bytes) or decimal units (`1K` is 1000 bytes).
1199
1200 ## smartcase (bool) (default true)
1201
1202 Override `ignorecase` option for searching when the pattern contains an uppercase character.
1203 This option has no effect when `ignorecase` is disabled.
1204
1205 ## smartdia (bool) (default false)
1206
1207 Override `ignoredia` option when the pattern contains a character with diacritic.
1208 This option has no effect when `ignoredia` is disabled.
1209
1210 ## sortby (string) (default `natural`)
1211
1212 Sort type for directories.
1213
1214 The following sort types are supported:
1215
1216 natural file name (track_2.flac comes before track_10.flac)
1217 name file name (track_10.flac comes before track_2.flac)
1218 ext file extension
1219 size file size
1220 time time of last data modification
1221 atime time of last access
1222 btime time of file birth
1223 ctime time of last status (inode) change
1224 custom property defined via `addcustominfo` (empty by default)
1225
1226 ## sortignorecase (bool) (default true)
1227
1228 Ignore case when sorting. See also `ignorecase`.
1229
1230 ## sortignoredia (bool) (default true)
1231
1232 Ignore diacritics when sorting. See also `ignoredia`.
1233
1234 ## statfmt (string) (default `\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l`)
1235
1236 Format string of the file info shown in the bottom left corner.
1237 This option has no effect unless `rulerfmt` is also set.
1238 Using `rulerfile` is preferred and this option is provided for backwards compatibility.
1239
1240 The following special expansions are supported:
1241
1242 %p file permission
1243 %c link count
1244 %u user name
1245 %g group name
1246 %s file size
1247 %S file size (left-padded with spaces to a fixed width of 5 characters)
1248 %t time of last data modification
1249 %l link target
1250 %m current mode
1251 %M current mode (displaying `NORMAL` instead of a blank string in Normal mode)
1252
1253 The `|` character splits the format string into sections. Any section containing a failed expansion (result is a blank string) is discarded and not shown.
1254
1255 ## tabstop (int) (default 8)
1256
1257 Number of space characters to show for horizontal tabulation (U+0009) character.
1258
1259 ## tagfmt (string) (default `\033[31m`)
1260
1261 Format string of the tags.
1262
1263 If the format string contains the characters `%s`, it is interpreted as a format string for `fmt.Sprintf`. Such a string should end with the terminal reset sequence.
1264 For example, `\033[4m%s\033[0m` has the same effect as `\033[4m`.
1265
1266 ## tempmarks (string) (default ``)
1267
1268 Marks to be considered temporary (e.g. `abc` refers to marks `a`, `b`, and `c`).
1269 These marks are not synced to other clients and they are not saved in the bookmarks file.
1270 Note that the special bookmark `'` is always treated as temporary and it does not need to be specified.
1271
1272 ## terminalcursor (string) (default `default`)
1273
1274 Set the appearance of the terminal cursor for prompts shown in the bottom line.
1275 Currently supported values are `default`, `block`, `underline`, `bar`, `blinkblock`, `blinkunderline` and `blinkbar`.
1276
1277 ## timefmt (string) (default `Mon Jan _2 15:04:05 2006`)
1278
1279 Format string of the file modification time shown in the bottom line.
1280
1281 ## truncatechar (string) (default `~`)
1282
1283 The truncate character that is shown at the end when the filename does not fit into the pane.
1284
1285 ## truncatepct (int) (default 100)
1286
1287 When a filename is too long to be shown completely, the available space will be partitioned into two parts.
1288 `truncatepct` is a percentage value between 0 and 100 that determines the size of the first part, which will be shown at the beginning of the filename.
1289 The second part uses the rest of the available space, and will be shown at the end of the filename.
1290 Both parts are separated by the truncation character (`truncatechar`).
1291 Truncation is not applied to the file extension.
1292
1293 For example, with the filename `very_long_filename.txt`:
1294
1295 - `set truncatepct 100` -> `very_long_filena~.txt` (default)
1296
1297 - `set truncatepct 50` -> `very_lon~filename.txt`
1298
1299 - `set truncatepct 0` -> `~ry_long_filename.txt`
1300
1301 ## visualfmt (string) (default `\033[7;36m`)
1302
1303 Format string of the indicator for files that are visually selected.
1304
1305 ## waitmsg (string) (default `Press any key to continue`)
1306
1307 String shown after commands of shell-wait type.
1308
1309 ## watch (bool) (default false)
1310
1311 Watch the filesystem for changes using `fsnotify` to automatically refresh file information.
1312 FUSE is currently not supported due to limitations in `fsnotify`.
1313
1314 ## wrapscan (bool) (default true)
1315
1316 Searching can wrap around the file list.
1317
1318 ## wrapscroll (bool) (default false)
1319
1320 Scrolling can wrap around the file list.
1321
1322 ## user_{option} (string) (default none)
1323
1324 Any option that is prefixed with `user_` is a user-defined option and can be set to any string.
1325 Inside a user-defined command, the value will be provided in the `lf_user_{option}` environment variable.
1326 These options are not used by lf and are not persisted.
1327
1328 # ENVIRONMENT VARIABLES
1329
1330 The following variables are exported for shell commands:
1331 These are referred to with a `$` prefix on POSIX shells (e.g. `$f`), between `%` characters on Windows cmd (e.g. `%f%`), and with a `$env:` prefix on Windows PowerShell (e.g. `$env:f`).
1332
1333 ## f
1334
1335 Current file selection as a full path.
1336
1337 ## fs
1338
1339 Selected file(s) separated with the value of `filesep` option as full path(s).
1340
1341 ## fv
1342
1343 Visually selected file(s) separated with the value of `filesep` option as full path(s).
1344
1345 ## fx
1346
1347 Selected file(s) (i.e. `fs`, never `fv`) if there are any selected files, otherwise current file selection (i.e. `f`).
1348
1349 ## id
1350
1351 Id of the running client.
1352
1353 ## PWD
1354
1355 Present working directory.
1356
1357 ## OLDPWD
1358
1359 Initial working directory.
1360
1361 ## LF_LEVEL
1362
1363 The value of this variable is set to the current nesting level when you run lf from a shell spawned inside lf.
1364 You can add the value of this variable to your shell prompt to make it clear that your shell runs inside lf.
1365 For example, with POSIX shells, you can use `[ -n "$LF_LEVEL" ] && PS1="$PS1""(lf level: $LF_LEVEL) "` in your shell configuration file (e.g. `~/.bashrc`).
1366
1367 ## OPENER
1368
1369 If this variable is set in the environment, use the same value. Otherwise, this is set to `start` in Windows, `open` in macOS, `xdg-open` in others.
1370
1371 ## EDITOR
1372
1373 If VISUAL is set in the environment, use its value. Otherwise, use the value of the environment variable EDITOR. If neither variable is set, this is set to `vi` on Unix, `notepad` in Windows.
1374
1375 ## PAGER
1376
1377 If this variable is set in the environment, use the same value. Otherwise, this is set to `less` on Unix, `more` in Windows.
1378
1379 ## SHELL
1380
1381 If this variable is set in the environment, use the same value. Otherwise, this is set to `sh` on Unix, `cmd` in Windows.
1382
1383 ## lf
1384
1385 Absolute path to the currently running lf binary, if it can be found. Otherwise, this is set to the string `lf`.
1386
1387 ## lf_{option}
1388
1389 Value of the {option}.
1390
1391 ## lf_user_{option}
1392
1393 Value of the user_{option}.
1394
1395 ## lf_flag_{flag}
1396
1397 Value of the command line {flag}.
1398
1399 ## lf_width, lf_height
1400
1401 Width/Height of the terminal.
1402
1403 ## lf_count
1404
1405 Value of the count associated with the current command.
1406
1407 ## lf_mode
1408
1409 Current mode that `lf` is operating in.
1410 This is useful for customizing keybindings depending on what the current mode is.
1411 Possible values are `compmenu`, `delete`, `rename`, `filter`, `find`, `mark`, `search`, `command`, `shell`, `pipe` (when running a shell-pipe command), `normal`, `visual` and `unknown`.
1412
1413 # SPECIAL COMMANDS
1414
1415 This section shows information about special shell commands.
1416
1417 ## open
1418
1419 This shell command can be defined to override the default `open` command when the current file is not a directory.
1420
1421 ## paste
1422
1423 This shell command can be defined to override the default `paste` command.
1424
1425 ## rename
1426
1427 This shell command can be defined to override the default `rename` command.
1428
1429 ## delete
1430
1431 This shell command can be defined to override the default `delete` command.
1432
1433 ## pre-cd
1434
1435 This shell command can be defined to be executed before changing a directory.
1436
1437 ## on-cd
1438
1439 This shell command can be defined to be executed after changing a directory.
1440
1441 ## on-load
1442
1443 This shell command can be defined to be executed after loading a directory.
1444 It provides the files inside the directory as arguments.
1445
1446 ## on-focus-gained
1447
1448 This shell command can be defined to be executed when the terminal gains focus.
1449
1450 ## on-focus-lost
1451
1452 This shell command can be defined to be executed when the terminal loses focus.
1453
1454 ## on-init
1455
1456 This shell command can be defined to be executed after initializing and connecting to the server.
1457
1458 ## on-select
1459
1460 This shell command can be defined to be executed after the selection changes.
1461
1462 ## on-redraw
1463
1464 This shell command can be defined to be executed after the screen is redrawn or if the terminal is resized.
1465
1466 ## on-quit
1467
1468 This shell command can be defined to be executed before quitting.
1469
1470 # PREFIXES
1471
1472 The following command prefixes are used by lf:
1473
1474 : read (default) built-in/custom command
1475 $ shell shell command
1476 % shell-pipe shell command running with the UI
1477 ! shell-wait shell command waiting for a key press
1478 & shell-async shell command running asynchronously
1479
1480 The same evaluator is used for the command line and the configuration file for reading shell commands.
1481 The difference is that prefixes are not necessary in the command line.
1482 Instead, different modes are provided to read corresponding commands.
1483 These modes are mapped to the prefix keys above by default.
1484 Visual mode mappings are defined the same way Normal mode mappings are defined.
1485
1486 # SYNTAX
1487
1488 Characters from `#` to newline are comments and ignored:
1489
1490 # comments start with `#`
1491
1492 The following commands (`set`, `setlocal`, `map`, `nmap`, `vmap`, `cmap`, and `cmd`) are used for configuration.
1493
1494 Command `set` is used to set an option which can be a boolean, integer, or string:
1495
1496 set hidden # boolean enable
1497 set hidden true # boolean enable
1498 set nohidden # boolean disable
1499 set hidden false # boolean disable
1500 set hidden! # boolean toggle
1501 set scrolloff 10 # integer value
1502 set sortby time # string value without quotes
1503 set sortby 'time' # string value with single quotes (whitespace)
1504 set sortby "time" # string value with double quotes (backslash escapes)
1505
1506 Command `setlocal` is used to set a local option for a directory which can be a boolean or string.
1507 Currently supported local options are `dircounts`, `dirfirst`, `dironly`, `hidden`, `info`, `reverse`, `sortby`, `sortignorecase` and `sortignoredia`.
1508
1509 setlocal /foo/bar hidden # boolean enable
1510 setlocal /foo/bar hidden true # boolean enable
1511 setlocal /foo/bar nohidden # boolean disable
1512 setlocal /foo/bar hidden false # boolean disable
1513 setlocal /foo/bar hidden! # boolean toggle
1514 setlocal /foo/bar sortby time # string value without quotes
1515 setlocal /foo/bar sortby 'time' # string value with single quotes (whitespace)
1516 setlocal /foo/bar sortby "time" # string value with double quotes (backslash escapes)
1517
1518 Command `map` is used to bind a key in Normal and Visual mode to a command which can be a built-in command, custom command, or shell command:
1519
1520 map gh cd ~ # built-in command
1521 map D trash # custom command
1522 map i $less $f # shell command
1523 map U !du -csh * # waiting shell command
1524
1525 Command `nmap` does the same but for Normal mode only.
1526
1527 Command `vmap` does the same but for Visual mode only.
1528
1529 Overview of which map command works in which mode:
1530
1531 map Normal, Visual
1532 nmap Normal
1533 vmap Visual
1534 cmap Command-line
1535
1536 Command `cmap` is used to bind a key on the command line to a command line command or any other command:
1537
1538 cmap <c-g> cmd-escape
1539 cmap <a-i> set incsearch!
1540
1541 You can delete an existing binding by leaving the expression empty:
1542
1543 map gh # deletes 'gh' mapping in Normal and Visual mode
1544 nmap v # deletes 'v' mapping in Normal mode
1545 vmap o # deletes 'o' mapping in Visual mode
1546 cmap <c-g> # deletes '<c-g>' mapping
1547
1548 Command `cmd` is used to define a custom command:
1549
1550 cmd usage $du -h -d1 | less
1551
1552 You can delete an existing command by leaving the expression empty:
1553
1554 cmd trash # deletes 'trash' command
1555
1556 If there is no prefix then `:` is assumed:
1557
1558 map zt set info time
1559
1560 An explicit `:` can be provided to group statements until a newline which is especially useful for `map` and `cmd` commands:
1561
1562 map st :set sortby time; set info time
1563
1564 If you need multiline you can wrap statements in `{{` and `}}` after the proper prefix.
1565
1566 map st :{{
1567 set sortby time
1568 set info time
1569 }}
1570
1571 # KEY MAPPINGS
1572
1573 Regular keys are assigned to a command with the usual syntax:
1574
1575 map a down
1576
1577 Keys combined with the Shift key simply use the uppercase letter:
1578
1579 map A down
1580
1581 Special keys are written in between `<` and `>` characters and always use lowercase letters:
1582
1583 map <enter> down
1584
1585 Angle brackets can be assigned with their special names:
1586
1587 map <lt> down
1588 map <gt> down
1589
1590 Function keys are prefixed with an `f` character:
1591
1592 map <f-1> down
1593
1594 Keys combined with the Ctrl key are prefixed with a `c` character:
1595
1596 map <c-a> down
1597
1598 Keys combined with the Alt key are assigned in two different ways depending on the behavior of your terminal.
1599 Older terminals (e.g. xterm) may set the 8th bit of a character when the Alt key is pressed.
1600 On these terminals, you can use the corresponding byte for the mapping:
1601
1602 map á down
1603
1604 Newer terminals (e.g. gnome-terminal) may prefix the key with an escape character when the Alt key is pressed.
1605 lf uses the escape delaying mechanism to recognize Alt keys in these terminals (delay is 100ms).
1606 On these terminals, keys combined with the Alt key are prefixed with an `a` character:
1607
1608 map <a-a> down
1609
1610 It is possible to combine special keys with modifiers:
1611
1612 map <a-enter> down
1613
1614 Combining multiple modifiers (e.g. `Ctrl+Shift+Space`) is not supported.
1615
1616 Note that lf's key mapping syntax is similar to Vim's, but not identical.
1617 Some special keys and modifiers use different names and separators, and key names are matched literally (i.e. no case-folding, no aliases), so some familiar forms will not work:
1618
1619 map <enter> down # not <Enter>, <Return> or <CR>
1620 map <f-1> down # not <F1>
1621 map <a-j> down # not <A-j> or <M-j> (Meta)
1622 map <m-2> down # not <RightMouse>
1623 map <m-up> down # not <ScrollWheelUp>
1624
1625 WARNING: Some key combinations will likely be intercepted by your OS, window manager, or terminal.
1626 Other key combinations may not be distinguishable by lf, depending on how the terminal reports them (e.g. `Ctrl+h` may be reported as `backspace` instead).
1627 The easiest way to find out the name of a key combination and whether it will work on your system is to press the key while lf is running and read the name from the `unknown mapping` error.
1628
1629 Mouse buttons are prefixed with an `m` character:
1630
1631 map <m-1> down # primary
1632 map <m-2> down # secondary
1633 map <m-3> down # middle
1634 map <m-4> down # thumb next
1635 map <m-5> down # thumb prev
1636 map <m-6> down
1637 map <m-7> down
1638 map <m-8> down
1639
1640 Mouse wheel events are also prefixed with an `m` character:
1641
1642 map <m-up> down
1643 map <m-down> down
1644 map <m-left> down
1645 map <m-right> down
1646
1647 # PUSH MAPPINGS
1648
1649 The usual way to map a key sequence is to assign it to a named or unnamed command.
1650 While this provides a clean way to remap built-in keys as well as other commands, it can be limiting at times.
1651 For this reason, the `push` command is provided by lf.
1652 This command is used to simulate key pushes given as its arguments.
1653 You can `map` a key to a `push` command with an argument to create various keybindings.
1654
1655 This is mainly useful for two purposes.
1656 First, it can be used to map a command with a command count:
1657
1658 map <c-j> push 10j
1659
1660 Second, it can be used to avoid typing the name when a command takes arguments:
1661
1662 map r push :rename<space>
1663
1664 One thing to be careful of is that since the `push` command works with keys instead of commands it is possible to accidentally create recursive bindings:
1665
1666 map j push 2j
1667
1668 These types of bindings create a deadlock when executed.
1669
1670 # SHELL COMMANDS
1671
1672 Regular shell commands are the most basic command type that is useful for many purposes.
1673 For example, we can write a shell command to move the selected file(s) to trash.
1674 A first attempt to write such a command may look like this:
1675
1676 cmd trash ${{
1677 mkdir -p ~/.trash
1678 if [ -z "$fs" ]; then
1679 mv "$f" ~/.trash
1680 else
1681 IFS="$(printf '\n\t')"; mv $fs ~/.trash
1682 fi
1683 }}
1684
1685 We check `$fs` to see if there are any selected files.
1686 Otherwise, we just delete the current file.
1687 Since this is such a common pattern, a separate `$fx` variable is provided.
1688 We can use this variable to get rid of the conditional:
1689
1690 cmd trash ${{
1691 mkdir -p ~/.trash
1692 IFS="$(printf '\n\t')"; mv $fx ~/.trash
1693 }}
1694
1695 The trash directory is checked each time the command is executed.
1696 We can move it outside of the command so it would only run once at startup:
1697
1698 ${{ mkdir -p ~/.trash }}
1699
1700 cmd trash ${{ IFS="$(printf '\n\t')"; mv $fx ~/.trash }}
1701
1702 Since these are one-liners, we can drop `{{` and `}}`:
1703
1704 $mkdir -p ~/.trash
1705
1706 cmd trash $IFS="$(printf '\n\t')"; mv $fx ~/.trash
1707
1708 Finally, note that we set the `IFS` variable manually in these commands.
1709 Instead, we could use the `ifs` option to set it for all shell commands (i.e. `set ifs "\n"`).
1710 This can be especially useful for interactive use (e.g. `$rm $f` or `$rm $fs` would simply work).
1711 This option is not set by default as it can behave unexpectedly for new users.
1712 However, use of this option is highly recommended and it is assumed in the rest of the documentation.
1713
1714 # PIPING SHELL COMMANDS
1715
1716 Regular shell commands have some limitations in some cases.
1717 When an output or error message is given and the command exits afterwards, the UI is immediately resumed and there is no way to see the message without dropping to shell again.
1718 Also, even when there is no output or error, the UI still needs to be paused while the command is running.
1719 This can cause flickering on the screen for short commands and similar distractions for longer commands.
1720
1721 Instead of pausing the UI, piping shell commands connect stdin, stdout, and stderr of the command to the statline at the bottom of the UI.
1722 This can be useful for programs following the Unix philosophy to give no output in the success case, and brief error messages or prompts in other cases.
1723
1724 For example, the following rename command prompts for overwrite in the statline if there is an existing file with the given name:
1725
1726 cmd rename %mv -i $f $1
1727
1728 You can also output error messages in the command and they will show up in the statline.
1729 For example, an alternative rename command may look like this:
1730
1731 cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
1732
1733 Note that input is line buffered and output and error are byte buffered.
1734
1735 # WAITING SHELL COMMANDS
1736
1737 Waiting shell commands are similar to regular shell commands except that they wait for a key press when the command is finished.
1738 These can be useful to see the output of a program before the UI is resumed.
1739 Waiting shell commands are more appropriate than piping shell commands when the command is verbose and the output is best displayed as multiline.
1740
1741 # ASYNCHRONOUS SHELL COMMANDS
1742
1743 Asynchronous shell commands are used to start a command in the background and then resume operation without waiting for the command to finish.
1744 Stdin, stdout, and stderr of the command are neither connected to the terminal nor the UI.
1745
1746 # REMOTE COMMANDS
1747
1748 One of the more advanced features in lf is remote commands.
1749 All clients connect to a server on startup.
1750 It is possible to send commands to all or any of the connected clients over the common server.
1751 This is used internally to notify file selection changes to other clients.
1752
1753 To use this feature, you need to use a client which supports communicating with a Unix domain socket.
1754 OpenBSD implementation of netcat (nc) is one such example.
1755 You can use it to send a command to the socket file:
1756
1757 echo 'send echo hello world' | nc -U ${XDG_RUNTIME_DIR:-/tmp/lf-$(id -u)}/lf.sock
1758
1759 Since such a client may not be available everywhere, lf comes bundled with a command line flag to be used as such.
1760 When using lf, you do not need to specify the address of the socket file.
1761 This is the recommended way of using remote commands since it is shorter and immune to socket file address changes:
1762
1763 lf -remote 'send echo hello world'
1764
1765 In this command `send` is used to send the rest of the string as a command to all connected clients.
1766 You can optionally give it an ID number to send a command to a single client:
1767
1768 lf -remote 'send 1234 echo hello world'
1769
1770 All clients have a unique ID number but you may not be aware of the ID number when you are writing a command.
1771 For this purpose, an `$id` variable is exported to the environment for shell commands.
1772 The value of this variable is set to the process ID of the client.
1773 You can use it to send a remote command from a client to the server which in return sends a command back to itself.
1774 So now you can display a message in the current client by calling the following in a shell command:
1775
1776 lf -remote "send $id echo hello world"
1777
1778 Since lf does not have control flow syntax, remote commands are used for such needs.
1779 For example, you can configure the number of columns in the UI with respect to the terminal width as follows:
1780
1781 cmd recol %{{
1782 if [ $lf_width -le 80 ]; then
1783 lf -remote "send $id set ratios 1:2"
1784 elif [ $lf_width -le 160 ]; then
1785 lf -remote "send $id set ratios 1:2:3"
1786 else
1787 lf -remote "send $id set ratios 1:2:3:5"
1788 fi
1789 }}
1790
1791 In addition, the `query` command can be used to obtain information about a specific lf instance by providing its ID:
1792
1793 lf -remote "query $id maps"
1794
1795 The following types of information are supported:
1796
1797 maps list of mappings created by the 'map', 'nmap' and 'vmap' command
1798 nmaps list of mappings created by the 'nmap' and 'map' command
1799 vmaps list of mappings created by the 'vmap' and 'map' command
1800 cmaps list of mappings created by the 'cmap' command
1801 cmds list of commands created by the 'cmd' command
1802 jumps contents of the jump list, showing previously visited locations
1803 history list of previously executed commands on the command line
1804 files list of files in the currently open directory as displayed by lf, empty if dir is still loading
1805
1806 When listing mappings the characters in the first column are:
1807
1808 n Normal
1809 v Visual
1810 c Command-line
1811
1812 This is useful for scripting actions based on the internal state of lf.
1813 For example, to select a previous command using fzf and execute it:
1814
1815 map <a-h> ${{
1816 clear
1817 cmd=$(
1818 lf -remote "query $id history" |
1819 awk -F'\t' 'NR > 1 { print $NF}' |
1820 sort -u |
1821 fzf --reverse --prompt='Execute command: '
1822 )
1823 lf -remote "send $id $cmd"
1824 }}
1825
1826 The `list` command prints the IDs of all currently connected clients:
1827
1828 lf -remote 'list'
1829
1830 There is also a `quit` command to quit the server when there are no connected clients left, and a `quit!` command to force quit the server by closing client connections first:
1831
1832 lf -remote 'quit'
1833 lf -remote 'quit!'
1834
1835 Lastly, the commands `conn` and `drop` connect or disconnect ID to/from the server:
1836
1837 lf -remote 'conn $id'
1838 lf -remote 'drop $id'
1839
1840 These are internal and generally not needed by users.
1841
1842 # FILE OPERATIONS
1843
1844 lf uses its own built-in copy and move operations by default.
1845 These are implemented as asynchronous operations and progress is shown in the bottom ruler.
1846 These commands do not overwrite existing files or directories with the same name.
1847 Instead, a suffix that is compatible with the `--backup=numbered` option in GNU cp is added to the new files or directories.
1848 Only file modes and (some) timestamps can be preserved (see `preserve` option), all other attributes are ignored including ownership, context, and xattr.
1849 Special files such as character and block devices, named pipes, and sockets are skipped and links are not followed.
1850 Moving is performed using the rename operation of the underlying OS.
1851 For cross-device moving, lf falls back to copying and then deletes the original files if there are no errors.
1852 Operation errors are shown in the message line as well as the log file and they do not prematurely terminate the corresponding file operation.
1853
1854 File operations can be performed on the currently selected file or on multiple files by selecting them first.
1855 When you `copy` a file, lf doesn't actually copy the file on the disk, but only records its name to a file.
1856 The actual file copying takes place when you `paste`.
1857 Similarly `paste` after a `cut` operation moves the file.
1858
1859 You can customize copy and move operations by defining a `paste` command.
1860 This is a special command that is called when it is defined instead of the built-in implementation.
1861 You can use the following example as a starting point:
1862
1863 cmd paste %{{
1864 load=$(cat ~/.local/share/lf/files)
1865 mode=$(echo "$load" | sed -n '1p')
1866 list=$(echo "$load" | sed '1d')
1867 if [ $mode = 'copy' ]; then
1868 cp -R $list .
1869 elif [ $mode = 'move' ]; then
1870 mv $list .
1871 rm ~/.local/share/lf/files
1872 lf -remote 'send clear'
1873 fi
1874 }}
1875
1876 Some useful things to be considered are to use the backup (`--backup`) and/or preserve attributes (`-a`) options with `cp` and `mv` commands if they support it (i.e. GNU implementation), change the command type to asynchronous, or use `rsync` command with progress bar option for copying and feed the progress to the client periodically with remote `echo` calls.
1877
1878 By default, lf does not assign `delete` command to a key to protect new users.
1879 You can customize file deletion by defining a `delete` command.
1880 You can also assign a key to this command if you like.
1881 An example command to move selected files to a trash folder and remove files completely after a prompt is provided in the example configuration file.
1882
1883 # SEARCHING FILES
1884
1885 There are two mechanisms implemented in lf to search a file in the current directory.
1886 Searching is the traditional method to move the selection to a file matching a given pattern.
1887 Finding is an alternative way to search for a pattern possibly using fewer keystrokes.
1888
1889 The searching mechanism is implemented with commands `search` (default `/`), `search-back` (default `?`), `search-next` (default `n`), and `search-prev` (default `N`).
1890 You can set `searchmethod` to `glob` to match using a glob pattern.
1891 Globbing supports `*` to match any sequence, `?` to match any character, and `[...]` or `[^...]` to match character sets or ranges.
1892 You can set `searchmethod` to `regex` to match using a regex pattern.
1893 For a full overview of Go's RE2 syntax, see https://pkg.go.dev/regexp/syntax.
1894 You can enable `incsearch` option to jump to the current match at each keystroke while typing.
1895 In this mode, you can either use `cmd-enter` to accept the search or use `cmd-escape` to cancel the search.
1896 You can also map some other commands with `cmap` to accept the search and execute the command immediately afterwards.
1897 For example, you can use the right arrow key to finish the search and open the selected file with the following mapping:
1898
1899 cmap <right> :cmd-enter; open
1900
1901 The finding mechanism is implemented with commands `find` (default `f`), `find-back` (default `F`), `find-next` (default `;`), `find-prev` (default `,`).
1902 You can disable `anchorfind` option to match a pattern at an arbitrary position in the filename instead of the beginning.
1903 You can set the number of keys to match using `findlen` option.
1904 If you set this value to zero, then the keys are read until there is only a single match.
1905 The default values of these two options are set to jump to the first file with the given initial.
1906
1907 Some options affect both searching and finding.
1908 You can disable `wrapscan` option to prevent searches from being wrapped around at the end of the file list.
1909 You can disable `ignorecase` option to match cases in the pattern and the filename.
1910 This option is already automatically overridden if the pattern contains uppercase characters.
1911 You can disable `smartcase` option to disable this behavior.
1912 Two similar options `ignoredia` and `smartdia` are provided to control matching diacritics in Latin letters.
1913
1914 # OPENING FILES
1915
1916 You can define an `open` command (default `l` and `<right>`) to configure file opening.
1917 This command is only called when the current file is not a directory, otherwise, the directory is entered instead.
1918 You can define it just as you would define any other command:
1919
1920 cmd open $vi $fx
1921
1922 It is possible to use different command types:
1923
1924 cmd open &xdg-open $f
1925
1926 You may want to use either file extensions or MIME types from `file` command:
1927
1928 cmd open ${{
1929 case $(file --mime-type -Lb $f) in
1930 text/*) vi $fx;;
1931 *) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
1932 esac
1933 }}
1934
1935 You may want to use `setsid` before your opener command to have persistent processes that continue to run after lf quits.
1936
1937 Regular shell commands (i.e. `$`) drop to the terminal which results in a flicker for commands that finish immediately (e.g. `xdg-open` in the above example).
1938 If you want to use asynchronous shell commands (i.e. `&`) but also want to use the terminal when necessary (e.g. `vi` in the above example), you can use a remote command:
1939
1940 cmd open &{{
1941 case $(file --mime-type -Lb $f) in
1942 text/*) lf -remote "send $id \$vi \$fx";;
1943 *) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
1944 esac
1945 }}
1946
1947 Note that asynchronous shell commands run in their own process group by default so they do not require the manual use of `setsid`.
1948
1949 The following command is provided by default:
1950
1951 cmd open &$OPENER $f
1952
1953 You may also use any other existing file openers as you like.
1954 Possible options are `libfile-mimeinfo-perl` (executable name is `mimeopen`), `rifle` (ranger's default file opener), or `mimeo` to name a few.
1955
1956 # PREVIEWING FILES
1957
1958 lf previews files on the preview pane by printing the file until the end or until the preview pane is filled.
1959 This output can be enhanced by providing a custom preview script for filtering.
1960 This can be used to highlight source code, list contents of archive files or view PDF or image files to name a few.
1961 For coloring lf recognizes ANSI escape codes.
1962
1963 To use this feature, you need to set the value of `previewer` option to the path of an executable file.
1964 The following arguments are passed to the file, (1) current filename, (2) width, (3) height, (4) horizontal position, (5) vertical position, and (6) mode ("preview" or "preload").
1965 The output of the execution is printed in the preview pane.
1966
1967 Different types of files can be handled by matching by extension (or MIME type from the `file` command):
1968
1969 #!/bin/sh
1970
1971 case "$1" in
1972 *.tar*) tar tf "$1";;
1973 *.zip) unzip -l "$1";;
1974 *.rar) unrar l "$1";;
1975 *.7z) 7z l "$1";;
1976 *.pdf) pdftotext "$1" -;;
1977 *) highlight -O ansi "$1";;
1978 esac
1979
1980 Because files can be large, lf automatically closes the previewer script output pipe with a SIGPIPE when enough lines are read.
1981 Note that some programs may not respond well to SIGPIPE and will exit with a non-zero return code, which avoids caching.
1982 You may add a trailing `|| true` command to avoid such errors:
1983
1984 highlight -O ansi "$1" || true
1985
1986 You may also want to use the same script in your pager mapping as well:
1987
1988 set previewer ~/.config/lf/pv.sh
1989 map i $~/.config/lf/pv.sh $f | less -R
1990
1991 For `less` pager, you may instead utilize `LESSOPEN` mechanism so that useful information about the file such as the full path of the file can still be displayed in the statusline below:
1992
1993 set previewer ~/.config/lf/pv.sh
1994 map i $LESSOPEN='| ~/.config/lf/pv.sh %s' less -R $f
1995
1996 Since the preview script is called for each file selection change, it may not generate previews fast enough if the user scrolls through files quickly.
1997 To deal with this, the `preload` option can be set to enable file previews to be preloaded in advance.
1998 If enabled, the preview script will be run on files in advance as the user navigates through them.
1999 In this case, if the exit code of the preview script is zero, then the output will be cached in memory and displayed by lf (useful for text or sixel previews).
2000 Otherwise, it will fall back to calling the preview script again when the file is actually selected (useful for previews managed by an external program).
2001
2002 # CHANGING DIRECTORY
2003
2004 lf changes the working directory of the process to the current directory so that shell commands always work in the displayed directory.
2005 After quitting, it returns to the original directory where it is first launched like all shell programs.
2006 If you want to stay in the current directory after quitting, you can use one of the example lfcd wrapper shell scripts provided in the repository at
2007 https://github.com/gokcehan/lf/tree/master/etc
2008
2009 There is a special command `on-cd` that runs a shell command when it is defined and the directory is changed.
2010 You can define it just as you would define any other command:
2011
2012 cmd on-cd &{{
2013 bash -c '
2014 # display git repository status in your prompt
2015 source /usr/share/git/completion/git-prompt.sh
2016 GIT_PS1_SHOWDIRTYSTATE=auto
2017 GIT_PS1_SHOWSTASHSTATE=auto
2018 GIT_PS1_SHOWUNTRACKEDFILES=auto
2019 GIT_PS1_SHOWUPSTREAM=auto
2020 git=$(__git_ps1 " (%s)")
2021 fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f$git\033[0m"
2022 lf -remote "send $id set promptfmt \"$fmt\""
2023 '
2024 }}
2025
2026 If you want to send escape sequences to the terminal, you can use the `tty-write` command to do so.
2027 The following xterm-specific escape sequence sets the terminal title to the working directory:
2028
2029 cmd on-cd &{{
2030 lf -remote "send $id tty-write \"\033]0;$PWD\007\""
2031 }}
2032
2033 This command runs whenever you change the directory but not on startup.
2034 You can add an extra call to make it run on startup as well:
2035
2036 cmd on-cd &{{ ... }}
2037 on-cd
2038
2039 Note that all shell command types can be used, but `%` and `&` are usually more appropriate, as `$` and `!` cause flickering and pauses respectively.
2040
2041 There is also a `pre-cd` command, that works like `on-cd`, but is run before the directory is actually changed.
2042 Another related command is `on-load` which gets executed when loading a directory.
2043
2044 # LOADING DIRECTORY
2045
2046 Similar to `on-cd` there also is `on-load` that when defined runs a shell command after loading a directory.
2047 It works well when combined with `addcustominfo`.
2048
2049 The following example can be used to display git indicators in the info column:
2050
2051 cmd on-load &{{
2052 cd "$(dirname "$1")" || exit 1
2053 [ "$(git rev-parse --is-inside-git-dir 2>/dev/null)" = false ] || exit 0
2054
2055 cmds=""
2056
2057 for file in "$@"; do
2058 case "$file" in
2059 */.git|*/.git/*) continue;;
2060 esac
2061
2062 status=$(git status --porcelain --ignored -- "$file" | cut -c1-2 | head -n1)
2063
2064 if [ -n "$status" ]; then
2065 cmds="${cmds}addcustominfo \"${file}\" \"$status\"; "
2066 else
2067 cmds="${cmds}addcustominfo \"${file}\" ''; "
2068 fi
2069 done
2070
2071 if [ -n "$cmds" ]; then
2072 lf -remote "send $id :$cmds"
2073 fi
2074 }}
2075
2076 Another use case could be showing the dimensions of images and videos:
2077
2078 cmd on-load &{{
2079 cmds=""
2080
2081 for file in "$@"; do
2082 mime=$(file --mime-type -Lb -- "$file")
2083 case "$mime" in
2084 # vector images cause problems
2085 image/svg+xml)
2086 ;;
2087 image/*|video/*)
2088 dimensions=$(exiftool -s3 -imagesize -- "$file")
2089 cmds="${cmds}addcustominfo \"${file}\" \"$dimensions\"; "
2090 ;;
2091 esac
2092 done
2093
2094 if [ -n "$cmds" ]; then
2095 lf -remote "send $id :$cmds"
2096 fi
2097 }}
2098
2099 # COLORS
2100
2101 lf tries to automatically adapt its colors to the environment.
2102 It starts with a default color scheme and updates colors using values of existing environment variables possibly by overwriting its previous values.
2103 Colors are set in the following order:
2104
2105 1. default
2106 2. LSCOLORS (macOS/BSD ls)
2107 3. LS_COLORS (GNU ls)
2108 4. LF_COLORS (lf specific)
2109 5. colors file (lf specific)
2110
2111 Please refer to the corresponding man pages for more information about `LSCOLORS` and `LS_COLORS`.
2112 `LF_COLORS` is provided with the same syntax as `LS_COLORS` in case you want to configure colors only for lf but not ls.
2113 This can be useful since there are some differences between ls and lf, though one should expect the same behavior for common cases.
2114 The colors file (refer to the [CONFIGURATION section](https://github.com/gokcehan/lf/blob/master/doc.md#configuration)) is provided for easier configuration without environment variables.
2115 This file should consist of whitespace-separated pairs with a `#` character to start comments until the end of the line.
2116
2117 You can configure lf colors in two different ways.
2118 First, you can only configure 8 basic colors used by your terminal and lf should pick up those colors automatically.
2119 Depending on your terminal, you should be able to select your colors from a 24-bit palette.
2120 This is the recommended approach as colors used by other programs will also match each other.
2121
2122 Second, you can set the values of environment variables or colors file mentioned above for fine-grained customization.
2123 Note that `LS_COLORS/LF_COLORS` are more powerful than `LSCOLORS` and they can be used even when GNU programs are not installed on the system.
2124 You can combine this second method with the first method for the best results.
2125
2126 Lastly, you may also want to configure the colors of the prompt line to match the rest of the colors.
2127 Colors of the prompt line can be configured using the `promptfmt` option which can include hardcoded colors as ANSI escapes.
2128 See the default value of this option to have an idea about how to color this line.
2129
2130 It is worth noting that lf uses as many colors as advertised by your terminal's entry in terminfo or infocmp databases on your system.
2131 If an entry is not present, it falls back to an internal database.
2132 If your terminal supports 24-bit colors but either does not have a database entry or does not advertise all capabilities, you can enable support by setting the `$COLORTERM` variable to `truecolor` or ensuring `$TERM` is set to a value that ends with `-truecolor`.
2133
2134 Default lf colors are mostly taken from GNU dircolors defaults.
2135 These defaults use 8 basic colors and bold attribute.
2136 Default dircolors entries with background colors are simplified to avoid confusion with current file selection in lf.
2137 Similarly, there are only file type matchings and extension matchings are left out for simplicity.
2138 Default values are as follows given with their matching order in lf:
2139
2140 ln 01;36
2141 or 31;01
2142 tw 01;34
2143 ow 01;34
2144 st 01;34
2145 di 01;34
2146 pi 33
2147 so 01;35
2148 bd 33;01
2149 cd 33;01
2150 su 01;32
2151 sg 01;32
2152 ex 01;32
2153 fi 00
2154
2155 Note that lf first tries matching file names and then falls back to file types.
2156 The full order of matchings from most specific to least are as follows:
2157
2158 1. Full Path (e.g. `~/.config/lf/lfrc`)
2159 2. Dir Name (e.g. `.git/`) (only matches dirs with a trailing slash at the end)
2160 3. File Type (e.g. `ln`) (except `fi`)
2161 4. File Name (e.g. `README*`)
2162 5. File Name (e.g. `*README`)
2163 6. Base Name (e.g. `README.*`)
2164 7. Extension (e.g. `*.txt`)
2165 8. Default (i.e. `fi`)
2166
2167 For example, given a regular text file `/path/to/README.txt`, the following entries are checked in the configuration and the first one to match is used:
2168
2169 1. `/path/to/README.txt`
2170 2. (skipped since the file is not a directory)
2171 3. (skipped since the file is of type `fi`)
2172 4. `README.txt*`
2173 5. `*README.txt`
2174 6. `README.*`
2175 7. `*.txt`
2176 8. `fi`
2177
2178 Given a regular directory `/path/to/example.d`, the following entries are checked in the configuration and the first one to match is used:
2179
2180 1. `/path/to/example.d`
2181 2. `example.d/`
2182 3. `di`
2183 4. `example.d*`
2184 5. `*example.d`
2185 6. `example.*`
2186 7. `*.d`
2187 8. `fi`
2188
2189 Note that glob-like patterns do not perform glob matching for performance reasons.
2190
2191 For example, you can set a variable as follows:
2192
2193 export LF_COLORS="~/Documents=01;31:~/Downloads=01;31:~/.local/share=01;31:~/.config/lf/lfrc=31:.git/=01;32:.git*=32:*.gitignore=32:*Makefile=32:README.*=33:*.txt=34:*.md=34:ln=01;36:di=01;34:ex=01;32:"
2194
2195 Having all entries on a single line can make it hard to read.
2196 You may instead divide it into multiple lines in between double quotes by escaping newlines with backslashes as follows:
2197
2198 export LF_COLORS="\
2199 ~/Documents=01;31:\
2200 ~/Downloads=01;31:\
2201 ~/.local/share=01;31:\
2202 ~/.config/lf/lfrc=31:\
2203 .git/=01;32:\
2204 .git*=32:\
2205 *.gitignore=32:\
2206 *Makefile=32:\
2207 README.*=33:\
2208 *.txt=34:\
2209 *.md=34:\
2210 ln=01;36:\
2211 di=01;34:\
2212 ex=01;32:\
2213 "
2214
2215 The `ln` entry supports the special value `target`, which will use the link target to select a style. Filename rules will still apply based on the link's name -- this mirrors GNU's `ls` and `dircolors` behavior.
2216 Having such a long variable definition in a shell configuration file might be undesirable.
2217 You may instead use the colors file (refer to the [CONFIGURATION section](https://github.com/gokcehan/lf/blob/master/doc.md#configuration)) for configuration.
2218 A sample colors file can be found at
2219 https://github.com/gokcehan/lf/blob/master/etc/colors.example
2220 You may also see the wiki page for ANSI escape codes
2221 https://en.wikipedia.org/wiki/ANSI_escape_code
2222
2223 # ICONS
2224
2225 Icons are configured using `LF_ICONS` environment variable or an icons file (refer to the [CONFIGURATION section](https://github.com/gokcehan/lf/blob/master/doc.md#configuration)).
2226 The variable uses the same syntax as `LS_COLORS/LF_COLORS`.
2227 Instead of colors, you should use single characters or symbols as values.
2228 The `ln` entry supports the special value `target`, which will use the link target to select an icon. Filename rules will still apply based on the link's name -- this mirrors GNU's `ls` and `dircolors` behavior.
2229 The icons file (refer to the [CONFIGURATION section](https://github.com/gokcehan/lf/blob/master/doc.md#configuration)) should consist of whitespace-separated arrays with a `#` character to start comments until the end of the line.
2230 Each line should contain 1-3 columns: a file type or file name pattern, the icon, and an optional icon color. Using only one column disables all rules for that type or name.
2231 Do not forget to add `set icons true` to your `lfrc` to see the icons.
2232 Default values are listed below in the order lf matches them:
2233
2234 ln l
2235 or l
2236 tw t
2237 ow d
2238 st t
2239 di d
2240 pi p
2241 so s
2242 bd b
2243 cd c
2244 su u
2245 sg g
2246 ex x
2247 fi -
2248
2249 A sample icons file can be found at
2250 https://github.com/gokcehan/lf/blob/master/etc/icons.example
2251
2252 A sample colored icons file can be found at
2253 https://github.com/gokcehan/lf/blob/master/etc/icons_colored.example
2254
2255 # RULER
2256
2257 The ruler can be configured using the `rulerfile` option (refer to the [CONFIGURATION section](https://github.com/gokcehan/lf/blob/master/doc.md#configuration)).
2258 The contents of the ruler file should be a Go template which is then rendered to create the actual output (refer to https://pkg.go.dev/text/template for more details on the syntax).
2259
2260 The following data fields are exported:
2261
2262 .Message string Includes internal messages, errors, and messages generated by the `echo`/`echomsg`/`echoerr` commands
2263 .Keys string Keys pressed by the user
2264 .Progress []string Progress indicators for copied, moved and deleted files
2265 .Copy []string List of files in the clipboard to be copied
2266 .Cut []string List of files in the clipboard to be moved
2267 .Select []string Selection list
2268 .Visual []string Visual selection
2269 .Index int Index of the cursor
2270 .Total int Number of visible files in the current working directory
2271 .Hidden int Number of hidden files in the current working directory
2272 .All int Number of all files in the current working directory
2273 .LinePercentage string Line percentage (analogous to `%p` for the `statusline` option in Vim)
2274 .ScrollPercentage string Scroll percentage (analogous to `%P` for the `statusline` option in Vim)
2275 .Filter []string Filter currently being applied
2276 .Mode string Current mode ("NORMAL" for Normal mode, and "VISUAL" for Visual mode)
2277 .Options map[string]string The value of options (e.g. `{{.Options.hidden}}`)
2278 .UserOptions map[string]string The value of user-defined options (e.g. `{{.UserOptions.foo}}`)
2279 .Stat.Path string Path of the current file
2280 .Stat.Name string Name of the current file
2281 .Stat.Extension string Extension of the current file
2282 .Stat.Size int64 Size of the current file
2283 .Stat.DirSize int64 Total size of the current directory if calculated via `calcdirsize` (`-1` if not calculated)
2284 .Stat.DirCount int Number of items in the current directory if the `dircounts` option is enabled (`-1` if the directory cannot be read)
2285 .Stat.Permissions string Permissions of the current file
2286 .Stat.ModTime string Last modified time of the current file (formatted based on the `timefmt` option)
2287 .Stat.AccessTime string Last access time of the current file (formatted based on the `timefmt` option)
2288 .Stat.BirthTime string Birth time of the current file (formatted based on the `timefmt` option)
2289 .Stat.ChangeTime string Last status (inode) change time of the current file (formatted based on the `timefmt` option)
2290 .Stat.LinkCount string Number of hard links for the current file
2291 .Stat.User string User of the current file
2292 .Stat.Group string Group of the current file
2293 .Stat.Target string Target if the current file is a symbolic link, otherwise a blank string
2294 .Stat.CustomInfo string Custom property if defined via `addcustominfo`, otherwise a blank string
2295
2296 The following functions are exported:
2297
2298 df func() string Get an indicator representing the amount of free disk space available
2299 env func(string) string Get the value of an environment variable
2300 humanize func(int64) string Express a file size in a human-readable format
2301 join func([]string, string) string Join a string array by a separator
2302 lower func(string) string Convert a string to lowercase
2303 substr func(string, int, int) string Get a substring based on starting index and length
2304 upper func(string) string Convert a string to uppercase
2305
2306 The special identifier `{{.SPACER}}` can be used to divide the ruler into sections that are spaced evenly from each other.
2307
2308 The default ruler file can be found at
2309 https://github.com/gokcehan/lf/blob/master/etc/ruler.default