lf: edit files and enter directories with enter
• 195 words • 1 min
Problem statement: in lf, how can
<Enter> edit files without trying to edit directories?
e already opens the selected file in $EDITOR. My first keybinding mapping
attempt copied its default command:
diff
# Edit file: 'e' (mapped out-of-the-box)
+map <enter> $$EDITOR "$f"
This worked for files, but it also sent directories to the editor, which is unwelcome.
Next up: lf’s built-in open command already has the split behavior I wanted
for directories:
text
% lf -doc | sed -n '533,540p'
Change the current working directory to the parent directory.
open (default l and <right>)
If the current file is a directory, then change the current directory to
it, otherwise, execute the open command. A default open command is
provided to call the default system opener asynchronously with the
current file as the argument. A custom open command can be defined toSo I kept the file branch in $EDITOR and sent the directory branch back to
lf’s open command:
text
cmd edit-or-open ${{
if [ -d "$f" ]; then
"$lf" -remote "send $id open"
else
$EDITOR "$f"
fi
}}
map <enter> edit-or-openThis works exactly as intended!
The complete lf configuration lives in my dotfiles. ∎
🤖 This post was drafted with an AI agent through
/bloggify,
then reviewed and edited by me.
More agent-assisted posts.
Connections
Shared tags