the universal "get out" key. Unfortunately, in the good old
Vi pressing <Esc> in a command line executed the command! Since that
might be considered to be a bug, Vim uses <Esc> to cancel the command.
But with the 'cpoptions' option it can be made Vi compatible. And
when using a mapping (which might be written for Vi) <Esc> also works
Vi compatible. Therefore, using CTRL-C is a method that always works.
If you are at the start of the command line, pressing <BS> will cancel the
command. It's like deleting the ":" or "/" that the line starts with.
==============================================================================
*20.2* Command line abbreviations
Some of the ":" commands are really long. We already mentioned that
":substitute" can be abbreviated to ":s". This is a generic mechanism, all
":" commands can be abbreviated.
How short can a command get? There are 26 letters, and many more commands.
For example, ":set" also starts with ":s", but ":s" doesn't start a ":set"
command. Instead ":set" can be abbreviated to ":se".
When the shorter form of a command could be used for two commands, it
stands for only one of them. There is no logic behind which one, you have to
learn them. In the help files the shortest form that works is mentioned. For
example: >
:s[ubstitute]
This means that the shortest form of ":substitute" is ":s". The following
characters are optional. Thus ":su" and ":sub" also work.
In the user manual we will either use the full name of command, or a short
version that is still readable. For example, ":function" can be abbreviated
to ":fu". But since most people don't understand what that stands for, we
will use ":fun". (Vim doesn't have a ":funny" command, otherwise ":fun" would
be confusing too.)
It is recommended that in Vim scripts you write the full command name. That
makes it easier to read back when you make later changes. Except for some
often used commands like ":w" (":write") and ":r" (":read").
A particularly confusing one is ":end", which could stand for ":endif",
":endwhile" or ":endfunction". Therefore, always use the full name.
SHORT OPTION NAMES
In the user manual the long version of the option names is used. Many options
also have a short name. Unlike ":" commands, there is only one short name
that works. For example, the short name of 'autoindent' is 'ai'. Thus these
two commands do the same thing: >
:set autoindent
:set ai
You can find the full list of long and short names here: |option-list|.
==============================================================================
*20.3* Command line completion
This is one of those Vim features that, by itself, is a reason to switch from
Vi to Vim. Once you have used this, you can't do without.
Suppose you have a directory that contains these files:
info.txt
intro.txt
bodyofthepaper.txt
To edit the last one, you use the command: >
:edit bodyofthepaper.txt
It's easy to type this wrong. A much quicker way is: >
:edit b<Tab>
Which will result in the same command. What happened? The <Tab> key does
completion of the word before the cursor. In this case "b". Vim looks in the
directory and finds only one file that starts with a "b". That must be the
one you are looking for, thus Vim completes the file name for you.
Now type: >
:edit i<Tab>
Vim will beep, and give you: >
:edit info.txt
The beep means that Vim has found more than one match. It then uses the first
match it found (alphabetically). If you press <Tab> again, you get: >
:edit intro.txt
Thus, if the first <Tab> doesn't give you the file you were looking for, press
it again. If there are more matches, you will see them all, one at a time.
If you press <Tab> on the last matching entry, you will go back to what you
first typed: >
:edit i
Then it starts all over again. Thus Vim cycles through the list of matches.
Use CTRL-P to go through the list in the other direction:
<------------------- <Tab> -------------------------+