Vim auto-completion howto


vim has a great feature that allows to auto-complete a word while typing it in insert mode. This article shows how it works.


Auto-complete from the current file

If you know that the word appeared earlier in the same text file, you can type the first letters then press CTRL-x CTRL-p. If the word you are typing appears later in the text then press CTRL-x CTRL-n. This will create a menu that shows the different possible matching words that have the same prefix.


Auto-complete from source files

When writing a program and you want to insert a function call, and you just remember how the function starts.
You can type the beginning of the function name then press CTRL-x CTRL-]. This will create a menu with alternative candidates for the symbol you typed. You need to create a tag file using ctags to use the latter feature.


Auto-completing a filename

If the word you are inserting corresponds to a file name, then use CTRL-x CTRL-f


Other auto-completion commands

This is the list of available auto-completion commands in vim.

Completion can be done for:

1. Whole lines                                          |i_CTRL-X_CTRL-L|
2. keywords in the current file                         |i_CTRL-X_CTRL-N|
3. keywords in 'dictionary'                             |i_CTRL-X_CTRL-K|
4. keywords in 'thesaurus', thesaurus-style             |i_CTRL-X_CTRL-T|
5. keywords in the current and included files           |i_CTRL-X_CTRL-I|
6. tags                                                 |i_CTRL-X_CTRL-]|
7. file names                                           |i_CTRL-X_CTRL-F|
8. definitions or macros                                |i_CTRL-X_CTRL-D|
9. Vim command-line                                     |i_CTRL-X_CTRL-V|
10. User defined completion                             |i_CTRL-X_CTRL-U|
11. omni completion                                     |i_CTRL-X_CTRL-O|
12. Spelling suggestions                                |i_CTRL-X_s|
13. keywords in 'complete'                              |i_CTRL-N|

See help completion in vim for more info.



Labels: , , Wireless Internet Security Coding Network Monitoring

Comment

Enter your comment (wiki syntax is allowed):
SCGSK

Wireless Internet Security Performance RADIUS server Wireless Internet Security Performance RADIUS server