diff --git a/complete.go b/complete.go index 1d45dc8e..af4fba10 100644 --- a/complete.go +++ b/complete.go @@ -113,6 +113,7 @@ var ( "cmd-lowercase-word", "visual", "visual-accept", + "visual-unselect", "visual-discard", "visual-change", } diff --git a/doc.md b/doc.md index 87ac188e..61ddd74e 100644 --- a/doc.md +++ b/doc.md @@ -108,6 +108,7 @@ The following commands are provided by lf: The following Visual mode commands are provided by lf: visual-accept (default 'V') + visual-unselect visual-discard (default '') visual-change (default 'o') @@ -220,6 +221,7 @@ The following environment variables are exported for shell commands: f fs + fv fx id 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. -## visual (default 'V') +## visual (default `V`) Switch to 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. +## visual-unselect + +Remove the visual selection from the selection list, quit Visual mode and return to Normal mode. + ## visual-discard (default ``) 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. @@ -780,7 +786,7 @@ For example, `\033[4m%s\033[0m` has the same effect as `\033[4m`. ## 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) @@ -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). +## fv + +Visually selected file(s) separated with the value of `filesep` option as full path(s). + ## 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 diff --git a/doc.txt b/doc.txt index 8f4cd5b0..43177061 100644 --- a/doc.txt +++ b/doc.txt @@ -98,6 +98,7 @@ The following commands are provided by lf: The following Visual mode commands are provided by lf: visual-accept (default 'V') + visual-unselect visual-discard (default '') visual-change (default 'o') @@ -210,6 +211,7 @@ The following environment variables are exported for shell commands: f fs + fv fx id PWD @@ -411,22 +413,27 @@ toggle 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 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. +visual-unselect + +Remove the visual selection from the selection list, quit Visual mode +and return to Normal mode. + visual-discard (default ) 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. @@ -828,7 +835,7 @@ effect as \033[4m. 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) @@ -1183,10 +1190,15 @@ fs 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 -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 diff --git a/eval.go b/eval.go index 7fcfe56a..5be668bf 100644 --- a/eval.go +++ b/eval.go @@ -2346,6 +2346,19 @@ func (e *callExpr) eval(app *app, args []string) { // allows us to use visual mode inside search, find etc. dir.visualAnchor = -1 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": if !app.nav.init { return diff --git a/lf.1 b/lf.1 index 37b54bbb..03417598 100644 --- a/lf.1 +++ b/lf.1 @@ -1,6 +1,6 @@ .\" Automatically generated by Pandoc 3.7.0.2 .\" -.TH "LF" "1" "2025\-07\-06" "" "DOCUMENTATION" +.TH "LF" "1" "2025\-07\-07" "" "DOCUMENTATION" .SH NAME lf \- terminal file manager .SH SYNOPSIS @@ -109,6 +109,7 @@ The following Visual mode commands are provided by lf: .IP .EX visual\-accept (default \(aqV\(aq) +visual\-unselect visual\-discard (default \(aq\(aq) visual\-change (default \(aqo\(aq) .EE @@ -227,6 +228,7 @@ The following environment variables are exported for shell commands: .EX f fs +fv fx id 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. .SS toggle 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. If already in Visual mode, discard the visual selection and stay in 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 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]\f[R]) Discard the visual selection, quit Visual mode and return to Normal 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. .SS invert (default \f[CR]v\f[R]) 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 \f[CR]\(rs033[4m\f[R]. .SS filesep (string) (default \f[CR]\(rsn\f[R]) -File separator used in environment variables \f[CR]fs\f[R] and -\f[CR]fx\f[R]. +File separator used in environment variables \f[CR]fs\f[R], +\f[CR]fv\f[R] and \f[CR]fx\f[R]. .SS findlen (int) (default 1) Number of characters prompted for the find command. 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 Selected file(s) separated with the value of \f[CR]filesep\f[R] option 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 Selected file(s) (i.e. -\f[CR]fs\f[R]) if there are any selected files, otherwise current file -selection (i.e. +\f[CR]fs\f[R], never \f[CR]fv\f[R]) if there are any selected files, +otherwise current file selection (i.e. \f[CR]f\f[R]). .SS id Id of the running client. diff --git a/nav.go b/nav.go index 3d3686ad..f5b3c8f9 100644 --- a/nav.go +++ b/nav.go @@ -751,8 +751,15 @@ func (nav *nav) exportFiles() { } 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("fs", currSelections) + os.Setenv("fv", currVSelections) os.Setenv("PWD", quoteString(nav.currDir().path)) if len(selections) == 0 {