Difference between revisions of "Saving one keystroke on entering command-line command"

From Vifm Wiki
Jump to: navigation, search
(Add a couple more examples)
(When it works: Describe when it works)
 
Line 25: Line 25:
 
==== When it works ====
 
==== When it works ====
  
'''TODO:'''
+
For any command when no ambiguity is created.  Here is an example where it
 +
''does not'' work:
 +
 
 +
<source lang="vim">
 +
:commandname :echo $USER
 +
</source>
 +
 
 +
Here <code>command</code> is immediately followed by <code>name</code> leaving
 +
no changes for Vifm to figure out whether it's <code>:commandname</code> command
 +
or <code>:command</code> followed by its first argument <code>name</code>.  It's
 +
not a technical problem to guess command names, but it would lead to semantic
 +
changes in the presense of <code>:commandname</code> command, which is
 +
undesireable.

Latest revision as of 11:37, 4 October 2014

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.