Command-line and alike modes
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:
- recalling parts of previous commands (see section on history below);
- pasting various information into current cursor position (see section that covers Ctrl-X shortcuts).
|Esc/Ctrl-C||Leave command line mode, cancels input.|
|Ctrl-M/Enter||Execute command and leave command line mode.|
|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.|
|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.|
|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.|
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
- Not the first command (e.g. that go after bar symbol,
- File names/paths of commands that accept paths (
- Options of
- Values of
- Names of options in expressions (
- Environment variable names in expressions (
- Help tags for
'vimhelp'option is set.
- User/group names for
- Commands for
- Highlight groups, attributes and their values for
- External commands for
- Argument of
- Color scheme names for
- 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|
|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
option. So it can be enabled like this:
There is also related highlight group that can be customized in color schemes
And here is an example of how it looks like:
/ (forward slash) specially
Sometimes matches on completing directory names end with a
/). 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 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
- case sensitive (
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
:highlightcommand, 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
:helpcommand argument when
'vimhelp'option is set, where pattern is matched anywhere in the string and always in case insensitive way (like
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.
|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.
|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.|
|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.
|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.