lf-wiki
Most of the following tips assume that ifs
option is set to "\n"
and shell
option is set to a posix compatible shell. You may need to adjust these to your setup accordingly.
Enable Borders
If you want to have borders around the columns:
Dual pane single column mode
If you are used to file managers with single column directory views (e.g. midnight commander or far manager), there are a few settings you can use to get a similar feeling:
If you also want to have dual panes, you need to utilize a terminal multiplexer or your window manager. For tmux
you may consider using a shell alias to automatically create dual panes:
Dynamically set number of columns
You can check the terminal width on startup and set number of columns accordingly:
You can also define this as a named command (e.g. cmd recol &{{ .. }}
) and then call it once on startup (e.g. recol
) so it will also be available as a command.
Copy or move files on client instead of server
By default lf
saves the names of files to be copied or moved on the server first so that you can for instance copy files in one client and paste them in another. If you don't need such use cases then you may consider remapping existing keys to work with selected files on the client instead of saving them on the server in advance:
Make backups when copying or moving
Unfortunately POSIX cp
and mv
commands do not define an option to backup existing files, but if you have the GNU implementation, you can define a custom paste
command to use --backup
option with these commands:
See man cp
or man mv
for more information.
Copy and move files asynchronously
You can define an asynchronous paste command to do file copying and moving asynchronously:
You can also define this command with a different name (e.g. cmd paste-async &{{ .. }}
) and then bind it to a different key (e.g. map P paste-async
) to use it selectively.
Show progress for file copying
You can use an alternative file copying program that provides progress information such as rsync
and feed this information to lf
to display progress while coping files:
Information is shown at the bottom of the screen every second but it is overwritten for each action that also use this part of the screen.
Use copy-on-write when possible
This snippet:
Tries to use CoW (reflinks) on btrfs, zfs and xfs
Falls back to lf's native paste (keeps progress %) if it can't
Handles matching names in destination with
.~1~
like lfForwards cp errors to status line, if any
Tested and works with set shell bash
with set shellopts '-eu'
(and GNU coreutils).
(Read before using)
Command/Mapping to create new directories
You can use the underlying mkdir
command to create new directories. It is possible to define a push mapping for such commands for easier typing as follows:
You can also create a custom command for this purpose
This command creates a directory for each argument passed by lf. For example, :mkdir foo 'bar baz'
creates two directories named foo
and bar baz
.
You can also join arguments with space characters to avoid the need to quote arguments as such:
This command creates a single directory with the given name. For example, :mkdir foo bar
creates a single directory named foo bar
.
You can also consider passing -p
option to mkdir
command to be able to create nested directories (e.g. mkdir -p foo/bar
to create a directory named foo
and then a directory named bar
inside foo
).
If you want to select the new directory afterwards, you can call a remote select
command as such:
Use enviromental variable in command or mapping
You can't use environmental (shell) variables directly in mappings and internal commands. You have to send variable to lf from shell scope using remote call. For example - when you want to map g G
to cd $GOPATH
you can use:
Split words by default in zsh
zsh
zsh
does not split words by default as described here, which makes it difficult to work with $fs
and $fx
variables, but a compatibility option named shwordsplit
(-y
or --sh-word-split
) is provided for this purpose. You can set this option for all commands as such:
Bulk rename multiple files
You can define a command to rename multiple files at the same time using your text editor to change the names.
This command either works on selected files or non-hidden files in the current directory if you don't have any selection.
Another very compact possibility which renames the selected items only with vidir
is:
Or, if you want more features, such as support for cyclic renames (A -> B, B -> A,...), for creating missing folders, git mv
, and with safeguards against deleting / overwriting files, and without annoying numbers before filenames - consider using dmulholl/vimv.
(same name as another vimv, but this one is more feature rich and written in rust, don't forget to read its --help
).
Rename commands similar to those of ranger
Recent versions of Lf provide a builtin rename
command. It is mapped by default to r
. You can use the default mapping and command as is, or you can extend it so it'll feel a little bit more like in ranger.
The following was tested with the following shell related Lf settings:
See https://github.com/gokcehan/lf/issues/279 for more implementations.
Create symlinks (soft / hard)
Here's a config snippet that adds a soft / hard symlinking command and mapping:
P
is used for both soft and hard linking. The "cut" mode of files donates a hard link is requested, while a "copy" mode donates a soft link is requested.
Put lf into background
You might be missing the possibility to put the lf
job into the background with the default ctrl
and z
keys.
Use gio trash
if available
gio trash
if availableOn systems that use GIO (Gnome Input/Output), such as Ubuntu, this will use the gio trash
command to move the currently selected items (files and dirs) to the trashcan. If GIO is not available, it falls back to mv
.
Basic use of mv
to implement a trashcan located in the user's home dir, as in the fallback option here, has some noteable disadvantages:
If the items being moved to trash are not on the same filesystem as the user's home dir, they are moved between filesystems with potentially lengthy copy+delete operations.
Items in trash take up storage in the filesystem holding the user's home dir instead of the filesystem they were initially in.
Since items with the same name will overwrite each other if they're moved to the same dir, items with common names easily become overwritten and unrecoverable.
The OS does not know that files moved to trash are probably less important to the user than the user's other files, so will not suggest them for deleting when running low on disk space and may included them in automated backups, etc.
The OS does not provide any functionality that helps finding and restoring accidentally deleted files to their original locations.
gio trash
, however, implements a trashcan without any of the disadvantages listed above. Instead of moving items across filesystems, it creates trash dirs as required on the filesystems where the items alread are. Items are stored with metadata containing original names and locations, preventing overwrites. The OS suggests deleting items from the trash when running low on space. Functionality for finding files that were moved to trash and restoring them to their original locations is available.
New folder with selected item(s)
A function similar to macOS Finder.app
If you use zsh
, make sure you set shellopts '-euy'
as described above for proper $fx
split.
Add to cut/copied files
Like rangers da
and dr
. Implementing this for copying files is mostly the same, simply rename move
to copy
where applicable.
NOTE this can also be used to switch a file selection from move to copy or vice versa.
WARN $'\n'
is not POSIX compliant.
Yank paths into your clipboard
the following commands each use xclip to copy files onto your clipboard. This depends on xclip so it probably won't work on windows. I suggest anyone who wants to use it cross platform create a script to automate platform dependent clipboard tools and then replace xclip
below with that script. These commands strip the trailing line break.
Here's an alternative implementation of yank-basename-without-extension
Here's another implementation which treats any character after the first "." as part of the extension.
Ranger's open_with
Run a command with spaces escaped
Share any file 256MiB limit
returned url wil be appended to clipboard (linux) edit to pbcopy for osx
Toggle preview with the i
key (with the less
pager)
i
key (with the less
pager)In lf
the i
key is the default for previewing files. It is convenient to let i
also quit the less
pager. Hence you uses the same key to open preview and to close it, and here is how to do:
In the lf
config activate the preview and set the preview script for less to use this cusom key binding.
select all files or directories in the current directory
Show current directory in window title
This is useful if you e.g. want to use rofi to search for specific instance of lf.
In shell you could change the title of your terminal to current directory with
However, it's not a standard, so it doesn't work in some terminals. I found it working in alacritty, st, kitty and rxvt-unicode, but not in e.g. KDE's konsole (haven't tested others).
We could utilize this escape sequence in lf via special on-cd
command, which runs when directory is changed.
If you want to show ~
instead of /home/username
, change printf line to
It might also be useful to show a program name.
Warn about nested instances
Add the following to your lfrc
to show a warning on startup if lf
is running as a nested instance:
Show nesting level in powerlevel10k zsh prompt
To show the current nesting level ($LF_LEVEL
) in your prompt when using p10k, add the following to your p10k.zsh
config file:
Add the following function anywhere in the config file. Replace "📂" with whichever icon you want to use and is supported by your terminal/font.
Add
lf
to your prompt (POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
orPOWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
at the top of the file)
This prompt segment will only be shown when the shell is "nested" in an lf instance.
Searchable bookmarks
First, set an environment variable called LF_BOOKMARK_PATH
to an empty folder which will contain your bookmarks, then add the following to your lfrc
.
Last updated