"#def", "a b", "_$r"
An abbreviation is only recognized when you type a non-keyword character.
This can also be the <Esc> that ends Insert mode or the <CR> that ends a
command. The non-keyword character which ends the abbreviation is inserted
after the expanded abbreviation. An exception to this is the character <C-]>,
which is used to expand an abbreviation without inserting any extra
characters.
Example: >
:ab hh hello
< "hh<Space>" is expanded to "hello<Space>"
"hh<C-]>" is expanded to "hello"
The characters before the cursor must match the abbreviation. Each type has
an additional rule:
full-id In front of the match is a non-keyword character, or this is where
the line or insertion starts. Exception: When the abbreviation is
only one character, it is not recognized if there is a non-keyword
character in front of it, other than a space or a tab. However, for
the command line "'<,'>" (or any other marks) is ignored, as if the
command line starts after it.
end-id In front of the match is a keyword character, or a space or a tab,
or this is where the line or insertion starts.
non-id In front of the match is a space, tab or the start of the line or
the insertion.
Examples: ({CURSOR} is where you type a non-keyword character) >
:ab foo four old otters
< " foo{CURSOR}" is expanded to " four old otters"
" foobar{CURSOR}" is not expanded
"barfoo{CURSOR}" is not expanded
>
:ab #i #include
< "#i{CURSOR}" is expanded to "#include"
">#i{CURSOR}" is not expanded
>
:ab ;; <endofline>
< "test;;" is not expanded
"test ;;" is expanded to "test <endofline>"
To avoid the abbreviation in Insert mode: Type CTRL-V before the character
that would trigger the abbreviation. E.g. CTRL-V <Space>. Or type part of
the abbreviation, exit insert mode with <Esc>, re-enter insert mode with "a"
and type the rest.
To avoid the abbreviation in Command-line mode: Type CTRL-V twice somewhere in
the abbreviation to avoid it to be replaced. A CTRL-V in front of a normal
character is mostly ignored otherwise.
It is possible to move the cursor after an abbreviation: >
:iab if if ()<Left>
You can even do more complicated things. For example, to consume the space
typed after an abbreviation: >
func Eatchar(pat)
let c = nr2char(getchar(0))
return (c =~ a:pat) ? '' : c
endfunc
iabbr <silent> if if ()<Left><C-R>=Eatchar('\s')<CR>
There are no default abbreviations.
Abbreviations are never recursive. You can use ":ab f f-o-o" without any
problem. But abbreviations can be mapped.
*:abbreviate-local* *:abbreviate-<buffer>*
Just like mappings, abbreviations can be local to a buffer. This is mostly
used in a |filetype-plugin| file. Example for a C plugin file: >
:abb <buffer> FF for (i = 0; i < ; ++i)
<
*:ab* *:abbreviate*
:ab[breviate] list all abbreviations. The character in the first
column indicates the mode where the abbreviation is
used: 'i' for insert mode, 'c' for Command-line
mode, '!' for both. These are the same as for
mappings, see |map-listing|.
*:abbreviate-verbose*
When 'verbose' is non-zero, listing an abbreviation will also display where it
was last defined. Example: >
:verbose abbreviate
! teh the
Last set from /home/abcd/vim/abbr.vim
See |:verbose-cmd| for more information.
:ab[breviate] {lhs} list the abbreviations that start with {lhs}
You may need to insert a CTRL-V (type it twice) to
avoid that a typed {lhs} is expanded, since
command-line abbreviations apply here.
:ab[breviate] [<expr>] [<buffer>] {lhs} {rhs}
add abbreviation for {lhs} to {rhs}. If {lhs} already
existed it is replaced with the new {rhs}. {rhs} may
contain spaces.
See |:map-<expr>| for the optional <expr> argument.
See |:map-<buffer>| for the optional <buffer> argument.
*:una* *:unabbreviate*
:una[bbreviate] [<buffer>] {lhs}
Remove abbreviation for {lhs} from the list. If none
is found,