Command-line and alike modes

From Vifm Wiki
Jump to: navigation, search

Command-line editing[edit]

Emacs-like navigation and editing as in a shell[edit]

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).
Emacs-like keys
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[edit]

Available completion kinds[edit]

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</code) and <code>: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.

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[edit]

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.

Completion control keys
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.

'wildmenu'[edit]

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:

Wildmenu.png

Treating / (forward slash) specially[edit]

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[edit]

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 in abc candidate);
  • case sensitive (ab doesn't match Ab, aB or AB).

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 (like cd pattern in abcDe candidate).

Recalling previous input[edit]

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.

History related keys
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[edit]

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:

  1. For elements of the active pane.
  2. For elements of the inactive pane (has one more Ctrl-X prefix).
  3. For filters.
Ctrl-X mappings
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[edit]

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.

External command-line editing keys
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[edit]

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.