Saving one keystroke on entering command-line command
Here is a demonstration of one of probably not that well known property of Vim's command parser:
" change directory to root of file system
:cd/
" make selected file(s) executable
:chmod+x
" define 'hi' command probably replacing existing command with the same name
:command!hi :echo 'Hi, '.$USER
Note absence of space between name of the command (:cd
) and its argument (/
).
As one might guess, the same applies to Vifm.
Why it works[edit]
Because of limited number of allowed characters in command names. This makes unambiguous parsing of command name and its arguments possible in most cases as:
- no special symbols are allowed in the middle of command names;
- special symbols after command name (or
!
/?
at the end of user-defined command name) separate the name from arguments; - whitespace characters before/between/after arguments are skipped.
When it works[edit]
For any command when no ambiguity is created. Here is an example where it does not work:
:commandname :echo $USER
Here command
is immediately followed by name
leaving
no changes for Vifm to figure out whether it's :commandname
command
or :command
followed by its first argument name
. It's
not a technical problem to guess command names, but it would lead to semantic
changes in the presense of :commandname
command, which is
undesireable.