Additions to visual-mode (#2035)

* Add `visual-unselect` command

* Add `fv` environment variable
This commit is contained in:
CatsDeservePets authored and GitHub committed 2025-07-08 08:46:26 +10:00
1 parent c2049e05c2
commit f40c626c4d
6 files changed
+70 -19

No files matched your search

+1
View File
@@ -113,6 +113,7 @@ var (
"cmd-lowercase-word", "cmd-lowercase-word",
"visual", "visual",
"visual-accept", "visual-accept",
"visual-unselect",
"visual-discard", "visual-discard",
"visual-change", "visual-change",
} }
+15 -5
View File
@@ -108,6 +108,7 @@ The following commands are provided by lf:
The following Visual mode commands are provided by lf: The following Visual mode commands are provided by lf:
visual-accept (default 'V') visual-accept (default 'V')
visual-unselect
visual-discard (default '<esc>') visual-discard (default '<esc>')
visual-change (default 'o') visual-change (default 'o')
@@ -220,6 +221,7 @@ The following environment variables are exported for shell commands:
f f
fs fs
fv
fx fx
id id
PWD PWD
@@ -412,20 +414,24 @@ Move the current file selection to the high/middle/low of the screen.
Toggle the selection of the current file or files given as arguments. Toggle the selection of the current file or files given as arguments.
## visual (default 'V') ## visual (default `V`)
Switch to Visual mode. Switch to Visual mode.
If already in Visual mode, discard the visual selection and stay in Visual mode. If already in Visual mode, discard the visual selection and stay in Visual mode.
## visual-accept (default 'V') ## visual-accept (default `V`)
Add the visual selection to the selection list, quit Visual mode and return to Normal mode. Add the visual selection to the selection list, quit Visual mode and return to Normal mode.
## visual-unselect
Remove the visual selection from the selection list, quit Visual mode and return to Normal mode.
## visual-discard (default `<esc>`) ## visual-discard (default `<esc>`)
Discard the visual selection, quit Visual mode and return to Normal mode. Discard the visual selection, quit Visual mode and return to Normal mode.
## visual-change (default 'o') ## visual-change (default `o`)
Go to the other end of the current Visual mode selection. Go to the other end of the current Visual mode selection.
@@ -780,7 +786,7 @@ For example, `\033[4m%s\033[0m` has the same effect as `\033[4m`.
## filesep (string) (default `\n`) ## filesep (string) (default `\n`)
File separator used in environment variables `fs` and `fx`. File separator used in environment variables `fs`, `fv` and `fx`.
## findlen (int) (default 1) ## findlen (int) (default 1)
@@ -1081,9 +1087,13 @@ Current file selection as a full path.
Selected file(s) separated with the value of `filesep` option as full path(s). Selected file(s) separated with the value of `filesep` option as full path(s).
## fv
Visually selected file(s) separated with the value of `filesep` option as full path(s).
## fx ## fx
Selected file(s) (i.e. `fs`) if there are any selected files, otherwise current file selection (i.e. `f`). Selected file(s) (i.e. `fs`, never `fv`) if there are any selected files, otherwise current file selection (i.e. `f`).
## id ## id
+18 -6
View File
@@ -98,6 +98,7 @@ The following commands are provided by lf:
The following Visual mode commands are provided by lf: The following Visual mode commands are provided by lf:
visual-accept (default 'V') visual-accept (default 'V')
visual-unselect
visual-discard (default '<esc>') visual-discard (default '<esc>')
visual-change (default 'o') visual-change (default 'o')
@@ -210,6 +211,7 @@ The following environment variables are exported for shell commands:
f f
fs fs
fv
fx fx
id id
PWD PWD
@@ -411,22 +413,27 @@ toggle
Toggle the selection of the current file or files given as arguments. Toggle the selection of the current file or files given as arguments.
visual (default 'V') visual (default V)
Switch to Visual mode. If already in Visual mode, discard the visual Switch to Visual mode. If already in Visual mode, discard the visual
selection and stay in Visual mode. selection and stay in Visual mode.
visual-accept (default 'V') visual-accept (default V)
Add the visual selection to the selection list, quit Visual mode and Add the visual selection to the selection list, quit Visual mode and
return to Normal mode. return to Normal mode.
visual-unselect
Remove the visual selection from the selection list, quit Visual mode
and return to Normal mode.
visual-discard (default <esc>) visual-discard (default <esc>)
Discard the visual selection, quit Visual mode and return to Normal Discard the visual selection, quit Visual mode and return to Normal
mode. mode.
visual-change (default 'o') visual-change (default o)
Go to the other end of the current Visual mode selection. Go to the other end of the current Visual mode selection.
@@ -828,7 +835,7 @@ effect as \033[4m.
filesep (string) (default \n) filesep (string) (default \n)
File separator used in environment variables fs and fx. File separator used in environment variables fs, fv and fx.
findlen (int) (default 1) findlen (int) (default 1)
@@ -1183,10 +1190,15 @@ fs
Selected file(s) separated with the value of filesep option as full Selected file(s) separated with the value of filesep option as full
path(s). path(s).
fv
Visually selected file(s) separated with the value of filesep option as
full path(s).
fx fx
Selected file(s) (i.e. fs) if there are any selected files, otherwise Selected file(s) (i.e. fs, never fv) if there are any selected files,
current file selection (i.e. f). otherwise current file selection (i.e. f).
id id
+13
View File
@@ -2346,6 +2346,19 @@ func (e *callExpr) eval(app *app, args []string) {
// allows us to use visual mode inside search, find etc. // allows us to use visual mode inside search, find etc.
dir.visualAnchor = -1 dir.visualAnchor = -1
normal(app) normal(app)
case "visual-unselect":
if !app.nav.init {
return
}
dir := app.nav.currDir()
for _, path := range dir.visualSelections() {
delete(app.nav.selections, path)
}
if len(app.nav.selections) == 0 {
app.nav.selectionInd = 0
}
dir.visualAnchor = -1
normal(app)
case "visual-discard": case "visual-discard":
if !app.nav.init { if !app.nav.init {
return return
+16 -8
View File
@@ -1,6 +1,6 @@
.\" Automatically generated by Pandoc 3.7.0.2 .\" Automatically generated by Pandoc 3.7.0.2
.\" .\"
.TH "LF" "1" "2025\-07\-06" "" "DOCUMENTATION" .TH "LF" "1" "2025\-07\-07" "" "DOCUMENTATION"
.SH NAME .SH NAME
lf \- terminal file manager lf \- terminal file manager
.SH SYNOPSIS .SH SYNOPSIS
@@ -109,6 +109,7 @@ The following Visual mode commands are provided by lf:
.IP .IP
.EX .EX
visual\-accept (default \(aqV\(aq) visual\-accept (default \(aqV\(aq)
visual\-unselect
visual\-discard (default \(aq<esc>\(aq) visual\-discard (default \(aq<esc>\(aq)
visual\-change (default \(aqo\(aq) visual\-change (default \(aqo\(aq)
.EE .EE
@@ -227,6 +228,7 @@ The following environment variables are exported for shell commands:
.EX .EX
f f
fs fs
fv
fx fx
id id
PWD PWD
@@ -434,17 +436,20 @@ A count can be specified to move to a specific line, for example, use
Move the current file selection to the high/middle/low of the screen. Move the current file selection to the high/middle/low of the screen.
.SS toggle .SS toggle
Toggle the selection of the current file or files given as arguments. Toggle the selection of the current file or files given as arguments.
.SS visual (default \(aqV\(aq) .SS visual (default \f[CR]V\f[R])
Switch to Visual mode. Switch to Visual mode.
If already in Visual mode, discard the visual selection and stay in If already in Visual mode, discard the visual selection and stay in
Visual mode. Visual mode.
.SS visual\-accept (default \(aqV\(aq) .SS visual\-accept (default \f[CR]V\f[R])
Add the visual selection to the selection list, quit Visual mode and Add the visual selection to the selection list, quit Visual mode and
return to Normal mode. return to Normal mode.
.SS visual\-unselect
Remove the visual selection from the selection list, quit Visual mode
and return to Normal mode.
.SS visual\-discard (default \f[CR]<esc>\f[R]) .SS visual\-discard (default \f[CR]<esc>\f[R])
Discard the visual selection, quit Visual mode and return to Normal Discard the visual selection, quit Visual mode and return to Normal
mode. mode.
.SS visual\-change (default \(aqo\(aq) .SS visual\-change (default \f[CR]o\f[R])
Go to the other end of the current Visual mode selection. Go to the other end of the current Visual mode selection.
.SS invert (default \f[CR]v\f[R]) .SS invert (default \f[CR]v\f[R])
Reverse the selection of all files in the current directory (i.e. Reverse the selection of all files in the current directory (i.e.
@@ -727,8 +732,8 @@ Such a string should end with the terminal reset sequence.
For example, \f[CR]\(rs033[4m%s\(rs033[0m\f[R] has the same effect as For example, \f[CR]\(rs033[4m%s\(rs033[0m\f[R] has the same effect as
\f[CR]\(rs033[4m\f[R]. \f[CR]\(rs033[4m\f[R].
.SS filesep (string) (default \f[CR]\(rsn\f[R]) .SS filesep (string) (default \f[CR]\(rsn\f[R])
File separator used in environment variables \f[CR]fs\f[R] and File separator used in environment variables \f[CR]fs\f[R],
\f[CR]fx\f[R]. \f[CR]fv\f[R] and \f[CR]fx\f[R].
.SS findlen (int) (default 1) .SS findlen (int) (default 1)
Number of characters prompted for the find command. Number of characters prompted for the find command.
When this value is set to 0, find command prompts until there is only a When this value is set to 0, find command prompts until there is only a
@@ -1025,10 +1030,13 @@ Current file selection as a full path.
.SS fs .SS fs
Selected file(s) separated with the value of \f[CR]filesep\f[R] option Selected file(s) separated with the value of \f[CR]filesep\f[R] option
as full path(s). as full path(s).
.SS fv
Visually selected file(s) separated with the value of \f[CR]filesep\f[R]
option as full path(s).
.SS fx .SS fx
Selected file(s) (i.e. Selected file(s) (i.e.
\f[CR]fs\f[R]) if there are any selected files, otherwise current file \f[CR]fs\f[R], never \f[CR]fv\f[R]) if there are any selected files,
selection (i.e. otherwise current file selection (i.e.
\f[CR]f\f[R]). \f[CR]f\f[R]).
.SS id .SS id
Id of the running client. Id of the running client.
+7
View File
@@ -751,8 +751,15 @@ func (nav *nav) exportFiles() {
} }
currSelections := strings.Join(selections, gOpts.filesep) currSelections := strings.Join(selections, gOpts.filesep)
var vSelections []string
for _, selection := range nav.currDir().visualSelections() {
vSelections = append(vSelections, quoteString(selection))
}
currVSelections := strings.Join(vSelections, gOpts.filesep)
os.Setenv("f", currFile) os.Setenv("f", currFile)
os.Setenv("fs", currSelections) os.Setenv("fs", currSelections)
os.Setenv("fv", currVSelections)
os.Setenv("PWD", quoteString(nav.currDir().path)) os.Setenv("PWD", quoteString(nav.currDir().path))
if len(selections) == 0 { if len(selections) == 0 {