Difference between revisions of "Command-line and alike modes"
(→Editing command-line externally: Add table of external editing keys) |
m (→Available completion kinds: Fix broken <code> tag) |
||
(8 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | + | == Command-line editing == | |
− | + | === Emacs-like navigation and editing as in a shell === | |
Assuming that most of users know at least some of Emacs-like shortcuts usually | Assuming that most of users know at least some of Emacs-like shortcuts usually | ||
Line 12: | Line 12: | ||
They can be divided into several categories: | They can be divided into several categories: | ||
+ | * controlling; | ||
* navigation; | * navigation; | ||
* editing; | * editing; | ||
Line 17: | Line 18: | ||
* pasting various information into current cursor position (see section that covers <kbd>Ctrl-X</kbd> shortcuts). | * pasting various information into current cursor position (see section that covers <kbd>Ctrl-X</kbd> shortcuts). | ||
− | < | + | {| class="wikitable" |
− | + | |+Emacs-like keys | |
− | < | + | ! width="200px" | Key |
+ | ! width="525px" | Description | ||
+ | |- | ||
+ | ! colspan="2" align="center" font="bold" | Controlling | ||
+ | |- | ||
+ | | <kbd>Esc/Ctrl-C</kbd> || Leave command line mode, cancels input. | ||
+ | |- | ||
+ | | <kbd>Ctrl-M/Enter</kbd> || Execute command and leave command line mode. | ||
+ | |- | ||
+ | ! colspan="2" align="center" font="bold" | Navigation | ||
+ | |- | ||
+ | | <kbd>Ctrl-B/Left</kbd> || Move cursor to the left. | ||
+ | |- | ||
+ | | <kbd>Ctrl-F/Right</kbd> || Move cursor to the right. | ||
+ | |- | ||
+ | | <kbd>Ctrl-A/Home</kbd> || Go to line beginning. | ||
+ | |- | ||
+ | | <kbd>Ctrl-E/End</kbd> || Go to line end | ||
+ | |- | ||
+ | | <kbd>Alt-B</kbd> || Go to the beginning of previous word. | ||
+ | |- | ||
+ | | <kbd>Alt-F</kbd> || Go to the end of next word. | ||
+ | |- | ||
+ | ! colspan="2" align="center" font="bold" | Editing | ||
+ | |- | ||
+ | | <kbd>Ctrl-K</kbd> || Remove characters from cursor position till the end of line. | ||
+ | |- | ||
+ | | <kbd>Ctrl-U</kbd> || Remove characters from cursor position till the beginning of line. | ||
+ | |- | ||
+ | | <kbd>Ctrl-H/Backspace</kbd> || Remove character before the cursor. | ||
+ | |- | ||
+ | | <kbd>Ctrl-D/Delete</kbd> || Remove character under the cursor. | ||
+ | |- | ||
+ | | <kbd>Ctrl-W</kbd> || Remove characters from cursor position till the beginning of previous word. | ||
+ | |- | ||
+ | | <kbd>Alt-D</kbd> || Remove characters from cursor position till the beginning of next word. | ||
+ | |- | ||
+ | | <kbd>Ctrl-T</kbd> || Swap the order of current and previous or two last characters in the line. | ||
+ | |- | ||
+ | ! colspan="2" align="center" font="bold" | [[ #Recalling_previous_input | History related ]] | ||
+ | |- | ||
+ | | <kbd>Ctrl-P/N</kbd> || Recall previous/next command. | ||
+ | |- | ||
+ | | <kbd>Up/Down</kbd> || Recall previous/next command that starts with current input. | ||
+ | |- | ||
+ | ! colspan="2" align="center" font="bold" | [[ #Recalling_previous_input | Recalling ending of previous commands ]] | ||
+ | |- | ||
+ | | <kbd>Alt-.</kbd> || Recall last part of previous commands. | ||
+ | |- | ||
+ | ! colspan="2" align="center" font="bold" | [[ #Pasting_runtime_context_into_command-line | Insertion of context items ]] | ||
+ | |- | ||
+ | | <kbd>Ctrl-X c/d/e/r/t</kbd> || Name/path/extension/name root/last path component in active pane. | ||
+ | |- | ||
+ | | <kbd>Ctrl-X Ctrl-X c/d/e/r/t</kbd> || Name/path/extension/name root/last path component in inactive pane. | ||
+ | |- | ||
+ | | <kbd>Ctrl-X a/m/=</kbd> || Value of automatic/manual/local filter. | ||
+ | |} | ||
− | + | == Completion == | |
− | + | === Available completion kinds === | |
− | < | + | Generally, it won't harm pressing <code>Tab</code> to initiate completion whenever one would like. |
− | + | So no need to remember where completion is actually available. | |
+ | Still it makes sense to outline what can be completed. | ||
− | + | * Names of command line commands. | |
+ | ** Commands at the beginning of the line. | ||
+ | ** Prefixed by something like <code>windo</code>. | ||
+ | ** Not the first command (e.g. that go after bar symbol, <code>|</code>). | ||
+ | * Arguments. | ||
+ | ** File names/paths of commands that accept paths (<code>:cd</code>, <code>:pushd</code>, <code>source</code>, <code>cp</code>, etc.). | ||
+ | ** Options of <code>:set</code> command. | ||
+ | ** Values of <code>:set</code> command options. | ||
+ | ** Names of options in expressions (<code>&optname</code>). | ||
+ | ** Environment variable names in expressions (<code>$ENVVAR</code>) and <code>:let</code>/<code>:unlet</code> commands. | ||
+ | ** Help tags for <code>:help</code> when <code>'vimhelp'</code> option is set. | ||
+ | ** User/group names for <code>:chown</code> command. | ||
+ | ** Commands for <code>:file</code> command. | ||
+ | ** Highlight groups, attributes and their values for <code>:highlight</code> command. | ||
+ | ** External commands for <code>:!</code>. | ||
+ | ** Argument of <code>:winrun</code>. | ||
+ | ** Color scheme names for <code>colorscheme</code>. | ||
− | + | Depending on the context completion matches are escaped appropriately (e.g. inside single or double quotes, which doesn't prevent path from being completed). | |
− | + | === Activating, controlling and finishing completion === | |
− | |||
− | |||
Starting completion just takes one press of the <kbd>Tab</kbd> (or | Starting completion just takes one press of the <kbd>Tab</kbd> (or | ||
Line 69: | Line 141: | ||
|} | |} | ||
− | + | === <code>'wildmenu'</code> === | |
One of good developments of completion is displaying of matches so that user | One of good developments of completion is displaying of matches so that user | ||
Line 90: | Line 162: | ||
[[File:wildmenu.png]] | [[File:wildmenu.png]] | ||
− | + | === Treating <code>/</code> (forward slash) specially === | |
Sometimes matches on completing directory names end with a | Sometimes matches on completing directory names end with a | ||
Line 104: | Line 176: | ||
<code>/name</code> because both will yield same results. | <code>/name</code> because both will yield same results. | ||
− | + | === Comparison of input and completion candidates === | |
Generally to perform completion Vifm matches candidates with pattern (part of | Generally to perform completion Vifm matches candidates with pattern (part of | ||
Line 118: | Line 190: | ||
* completion of <code>:help</code> command argument when <code>'vimhelp'</code> option is set, where pattern is matched anywhere in the string and always in case insensitive way (like <code>cd</code> pattern in <code>ab<u>cD</u>e</code> candidate). | * completion of <code>:help</code> command argument when <code>'vimhelp'</code> option is set, where pattern is matched anywhere in the string and always in case insensitive way (like <code>cd</code> pattern in <code>ab<u>cD</u>e</code> candidate). | ||
− | + | == Recalling previous input == | |
There are several kinds of operations that work with history. The first one | There are several kinds of operations that work with history. The first one | ||
Line 148: | Line 220: | ||
|} | |} | ||
− | + | == Pasting runtime context into command-line == | |
− | < | + | Inserting parts of paths and names into command line is quite command operation, |
+ | designated shortcuts for them can save quite a lot of keystrokes. | ||
+ | |||
+ | There are three groups of such shortcuts, all are prefixed with <kbd>Ctrl-X</kbd>: | ||
+ | # For elements of the active pane. | ||
+ | # For elements of the inactive pane (has one more <kbd>Ctrl-X</kbd> prefix). | ||
+ | # For filters. | ||
+ | |||
+ | {| class="wikitable" | ||
+ | |+<kbd>Ctrl-X</kbd> mappings | ||
+ | ! width="125px" | Key | ||
+ | ! width="500px" | Description | ||
+ | |- | ||
+ | ! colspan="2" align="center" font="bold" | For active pane | ||
+ | |- | ||
+ | | <kbd>Ctrl-X c</kbd> || Name of the current file of the active pane. | ||
+ | |- | ||
+ | | <kbd>Ctrl-X d</kbd> || Path to the current directory of the active pane. | ||
+ | |- | ||
+ | | <kbd>Ctrl-X e</kbd> || Extension of the current file of the active pane. | ||
+ | |- | ||
+ | | <kbd>Ctrl-X r</kbd> || Name root of current file of the active pane. | ||
+ | |- | ||
+ | | <kbd>Ctrl-X t</kbd> || The last component of path to the current directory of the active pane. | ||
+ | |- | ||
+ | ! colspan="2" align="center" font="bold" | For inactive pane | ||
+ | |- | ||
+ | | <kbd>Ctrl-X Ctrl-X c</kbd> || Name of the current file of the inactive pane. | ||
+ | |- | ||
+ | | <kbd>Ctrl-X Ctrl-X d</kbd> || Path to the current directory of the inactive pane. | ||
+ | |- | ||
+ | | <kbd>Ctrl-X Ctrl-X e</kbd> || Extension of the current file of the inactive pane. | ||
+ | |- | ||
+ | | <kbd>Ctrl-X Ctrl-X r</kbd> || Name root of current file of the inactive pane. | ||
+ | |- | ||
+ | | <kbd>Ctrl-X Ctrl-X t</kbd> || The last component of path to the current directory of the inactive pane. | ||
+ | |- | ||
+ | ! colspan="2" align="center" font="bold" | For filters | ||
+ | |- | ||
+ | | <kbd>Ctrl-X a</kbd> || Value of automatic filter of the active pane. | ||
+ | |- | ||
+ | | <kbd>Ctrl-X m</kbd> || Value of manual filter of the active pane. | ||
+ | |- | ||
+ | | <kbd>Ctrl-X =</kbd> || Value of local filter of the active pane. | ||
+ | |} | ||
− | + | == Editing command-line externally == | |
Similar features in other software: | Similar features in other software: | ||
Line 182: | Line 298: | ||
|} | |} | ||
− | + | === Vim and Vim-plugin additions === | |
Vim can execute commands passed to it in command-line arguments. Vifm uses this | Vim can execute commands passed to it in command-line arguments. Vifm uses this | ||
Line 196: | Line 312: | ||
* automatic ''Insert'' mode entering; | * automatic ''Insert'' mode entering; | ||
* accepting input or picked history element on <kbd>Enter</kbd> in both ''Insert'' and ''Normal'' modes. | * accepting input or picked history element on <kbd>Enter</kbd> in both ''Insert'' and ''Normal'' modes. | ||
+ | |||
+ | [[Category:Manual]] |
Revision as of 09:57, 10 July 2019
Command-line editing
Assuming that most of users know at least some of Emacs-like shortcuts usually available on command-line prompt. And also considering them to be quite convenient (and familiar due to the first statement) for single line editing. As well as listening to common sense claims that Vim-like editing of the command-line of Vim-like file manager would be overkill caused adding of shell shortcuts to Vifm's command-line mode.
They can be divided into several categories:
- controlling;
- navigation;
- editing;
- recalling parts of previous commands (see section on history below);
- pasting various information into current cursor position (see section that covers Ctrl-X shortcuts).
Key | Description |
---|---|
Controlling | |
Esc/Ctrl-C | Leave command line mode, cancels input. |
Ctrl-M/Enter | Execute command and leave command line mode. |
Navigation | |
Ctrl-B/Left | Move cursor to the left. |
Ctrl-F/Right | Move cursor to the right. |
Ctrl-A/Home | Go to line beginning. |
Ctrl-E/End | Go to line end |
Alt-B | Go to the beginning of previous word. |
Alt-F | Go to the end of next word. |
Editing | |
Ctrl-K | Remove characters from cursor position till the end of line. |
Ctrl-U | Remove characters from cursor position till the beginning of line. |
Ctrl-H/Backspace | Remove character before the cursor. |
Ctrl-D/Delete | Remove character under the cursor. |
Ctrl-W | Remove characters from cursor position till the beginning of previous word. |
Alt-D | Remove characters from cursor position till the beginning of next word. |
Ctrl-T | Swap the order of current and previous or two last characters in the line. |
History related | |
Ctrl-P/N | Recall previous/next command. |
Up/Down | Recall previous/next command that starts with current input. |
Recalling ending of previous commands | |
Alt-. | Recall last part of previous commands. |
Insertion of context items | |
Ctrl-X c/d/e/r/t | Name/path/extension/name root/last path component in active pane. |
Ctrl-X Ctrl-X c/d/e/r/t | Name/path/extension/name root/last path component in inactive pane. |
Ctrl-X a/m/= | Value of automatic/manual/local filter. |
Completion
Available completion kinds
Generally, it won't harm pressing Tab
to initiate completion whenever one would like.
So no need to remember where completion is actually available.
Still it makes sense to outline what can be completed.
- Names of command line commands.
- Commands at the beginning of the line.
- Prefixed by something like
windo
. - Not the first command (e.g. that go after bar symbol,
|
).
- Arguments.
- File names/paths of commands that accept paths (
:cd
,:pushd
,source
,cp
, etc.). - Options of
:set
command. - Values of
:set
command options. - Names of options in expressions (
&optname
). - Environment variable names in expressions (
$ENVVAR
) and:let
/:unlet
commands. - Help tags for
:help
when'vimhelp'
option is set. - User/group names for
:chown
command. - Commands for
:file
command. - Highlight groups, attributes and their values for
:highlight
command. - External commands for
:!
. - Argument of
:winrun
. - Color scheme names for
colorscheme
.
- File names/paths of commands that accept paths (
Depending on the context completion matches are escaped appropriately (e.g. inside single or double quotes, which doesn't prevent path from being completed).
Activating, controlling and finishing completion
Starting completion just takes one press of the Tab (or Ctrl-I, which is the same in terminal) or Shift-Tab key. The first one starts completion in forward direction (e.g. in ascending order) while the second one is basically the same but in backward direction.
If nothing happens on hitting one of completion start keys, it might be because:
- there is no matches for the input;
- there is only one match and it's identical to the input.
Same keys are used to go through the list of matches in both directions. One more key is Ctrl-_ (entered as Ctrl-Shift--), which stops completion and restores original input.
Once any other key is pressed match is considered to be picked and completion is finished.
Key | Starts completion | Stops completion | Description |
---|---|---|---|
Tab Ctrl-I |
Yes | No | Complete in forward direction. |
Shift-Tab | Yes | No | Complete in backward direction. |
Ctrl-_ | No | Yes | Restore initial input. |
Any other key | No | Yes | Accept current match. |
One of good developments of completion is displaying of matches so that user
doesn't need to remember the most recent ones and could see what's comming next
at the same time. It's also useful to see that you're actually completting
something rather then just editing command line. Vifm supports one of possible
ways of such matches preview called "wild menu" (same can be found in Vim).
It's disabled by default and is controlled by 'wildmenu'
boolean
option. So it can be enabled like this:
:set wildmenu
There is also related highlight group that can be customized in color schemes
called WildMenu
.
And here is an example of how it looks like:
Treating /
(forward slash) specially
Sometimes matches on completing directory names end with a
slash (/
). At this point one often wants to:
- pick current match and end completion;
- or pick current match and continue by typing file name after already filled in directory name.
To allow doing both of this conveniently and without leaving strange looking
double slash Vifm skips slash character in completion mode if there is
already a slash at cursor position and stops completion at the same time. So
it actually doesn't matter how file name is written as name
or
/name
because both will yield same results.
Comparison of input and completion candidates
Generally to perform completion Vifm matches candidates with pattern (part of input before cursor position when completion starts) like this:
- at the start of the candidate string (like
ab
pattern inabc
candidate); - case sensitive (
ab
doesn't matchAb
,aB
orAB
).
That said, sometimes completion is done differently. Namely, in the following cases:
- when command-line argument being completed is case insensitive (e.g. first argument of the
:highlight
command, which is case insensitive name of highlight group); - when completing paths on Windows, where paths are not case sensitive (well, theoretically they can be, but it's hard to find Windows systems configured in that way);
- completion of
:help
command argument when'vimhelp'
option is set, where pattern is matched anywhere in the string and always in case insensitive way (likecd
pattern inabcDe
candidate).
Recalling previous input
There are several kinds of operations that work with history. The first one walks through the history backward (Ctrl-P) and forward (Ctrl-N) and doesn't depend on current input.
Second type (Up/Down) filters out only those history items that have current input as their prefix.
The third one (Alt-.) works only in command-line mode (not various prompt) and inserts the last component of previous command, repeat it to get further back in the history.
Key | Command-line mode only |
Description |
---|---|---|
Ctrl-P | No | Recall previous command. |
Ctrl-N | No | Recall next command. |
Up | No | Recall previous command that starts with current input. |
Down | No | Recall next command that starts with current input. |
Alt-. | Yes | Recall last argument of the previous command. |
Pasting runtime context into command-line
Inserting parts of paths and names into command line is quite command operation, designated shortcuts for them can save quite a lot of keystrokes.
There are three groups of such shortcuts, all are prefixed with Ctrl-X:
- For elements of the active pane.
- For elements of the inactive pane (has one more Ctrl-X prefix).
- For filters.
Key | Description |
---|---|
For active pane | |
Ctrl-X c | Name of the current file of the active pane. |
Ctrl-X d | Path to the current directory of the active pane. |
Ctrl-X e | Extension of the current file of the active pane. |
Ctrl-X r | Name root of current file of the active pane. |
Ctrl-X t | The last component of path to the current directory of the active pane. |
For inactive pane | |
Ctrl-X Ctrl-X c | Name of the current file of the inactive pane. |
Ctrl-X Ctrl-X d | Path to the current directory of the inactive pane. |
Ctrl-X Ctrl-X e | Extension of the current file of the inactive pane. |
Ctrl-X Ctrl-X r | Name root of current file of the inactive pane. |
Ctrl-X Ctrl-X t | The last component of path to the current directory of the inactive pane. |
For filters | |
Ctrl-X a | Value of automatic filter of the active pane. |
Ctrl-X m | Value of manual filter of the active pane. |
Ctrl-X = | Value of local filter of the active pane. |
Editing command-line externally
Similar features in other software:
- Vim has a nice feature which allows user to edit command-line in a regular text buffer;
- shells and some other applications allow to edit input in external applications.
Approach implemented in Vifm is more Vim-like in that temporary buffer also includes full history, which is something that's missing when editing shell command-line in Vim. Of course, mappings are also Vim-like, although command-line mode mapping is chosen differently to fix conflict with Emacs-like shortcuts for editing.
Key | Mode | Description |
---|---|---|
q: | Normal | Edit/pick command-line command then run it. |
q/ | Normal | Edit/pick pattern then search for it in forward direction. |
q? | Normal | Edit/pick pattern then search for it in backward direction. |
q= | Normal | Edit/pick pattern then use it as new value filter. |
Ctrl-G | Command-line | Edit current input in Vim then run it (action depends on kind of prompt). |
Vim and Vim-plugin additions
Vim can execute commands passed to it in command-line arguments. Vifm uses this to set cursor line and column for external editing of input.
Additionally, if vifm.vim is installed in your Vim configuration, special type of buffer for external command-line editing modes will be set automatically to make editing more convenient. Note, that it requires modeline processing in Vim to be enabled (it's the default for non-root users). The plugin provides:
- syntax highlighting;
- automatic Insert mode entering;
- accepting input or picked history element on Enter in both Insert and Normal modes.