Vim Tips Wiki
Tags: Visual edit apiedit
m (Reverted edits by 61.3.171.181 (talk | block) to last version by JohnBot)
Line 80: Line 80:
   
 
Result: The abbreviation is expanded with no extra characters, and you are still in insert mode and can continue typing.
 
Result: The abbreviation is expanded with no extra characters, and you are still in insert mode and can continue typing.
 
---
 
 
To speed up writing English one can learn several speedword systems like [http://jonaquino.blogspot.in/2007/06/yublin-shorthand-for-speed-writing.html Yublin] or [http://www.thetechnicalgeekery.com/2014/01/dutton-speedwords-shorthand/ Dutton Speedwords]
 
   
 
----
 
----

Revision as of 07:55, 9 September 2015

Tip 610 Printable Monobook Previous Next

created 2003 · complexity intermediate · version 6.0


You can use Vim's autocomplete feature in insert mode. Just edit the vimrc file and add lines:

iab <key> <expansion>
<key> is the letter which should be expanded to <expansion>

Example (add your own words):

iab #i #include (typing "#i" and space will be expanded to "#include")
iab #d #define (typing "#d" and space will be expanded to "#define")
iab s struct (typing "s" and space will be expanded to "struct")
iab t typedef ( typing "t" and space will be expanded to "typedef")

In some cases Vim expands a letter automatically that you don't want. You have to watch out for that.

Comments

Similarly, in insert mode you can hit Ctrl+P or Ctrl+N to autocomplete. Ctrl+P searches upward in your text for what your trying to complete to, Ctrl+N searches forward in your text. After exhausting the current buffer, both of these commands will begin searching other open buffers. I'm not sure, but I believe that there is also a search path you can specify in the .vimrc if you wish.


Use a dictionary file:

set complete+=k
set dictionary+=/your/dict/file

Ctrl+N, Ctr+P will now search for completions from that dict file.


You can put your common typos as abbreviations, for auto correction:

iab teh the
iab seperate separate

> How cut the space from the resulted substitution?

From :help abbreviations: 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"

Use getchar() to eat up that space, for example:

iab <t <target name="%"></target><Esc>F%s<c-o>:call getchar()<CR>

Regarding how to eat the last typed character (when it is a space): Use :Iabbr and :Inoreabbr from script#50.


See the SuperTab plugin. It does almost all of this without the need for programming.


To eat the last space, for example, with:

iab did <div id="

In insert mode, type did then press Ctrl-]

Result: The abbreviation is expanded with no extra characters, and you are still in insert mode and can continue typing.