matches.
A special option for completion is 'infercase'. This is useful to find
matches while ignoring case ('ignorecase' must be set) but still using the
case of the word typed so far. Thus if you type "For" and Vim finds a match
"fortunately", it will result in "Fortunately".
COMPLETING SPECIFIC ITEMS
If you know what you are looking for, you can use these commands to complete
with a certain type of item:
CTRL-X CTRL-F file names
CTRL-X CTRL-L whole lines
CTRL-X CTRL-D macro definitions (also in included files)
CTRL-X CTRL-I current and included files
CTRL-X CTRL-K words from a dictionary
CTRL-X CTRL-R contents from registers
CTRL-X CTRL-T words from a thesaurus
CTRL-X CTRL-] tags
CTRL-X CTRL-V Vim command line
After each of them CTRL-N can be used to find the next match, CTRL-P to find
the previous match.
More information for each of these commands here: |ins-completion|.
COMPLETING FILE NAMES
Let's take CTRL-X CTRL-F as an example. This will find file names. It scans
the current directory for files and displays each one that matches the word in
front of the cursor.
Suppose, for example, that you have the following files in the current
directory:
main.c sub_count.c sub_done.c sub_exit.c
Now enter Insert mode and start typing:
The exit code is in the file sub ~
At this point, you enter the command CTRL-X CTRL-F. Vim now completes the
current word "sub" by looking at the files in the current directory. The
first match is sub_count.c. This is not the one you want, so you match the
next file by typing CTRL-N. This match is sub_done.c. Typing CTRL-N again
takes you to sub_exit.c. The results:
The exit code is in the file sub_exit.c ~
If the file name starts with / (Unix) or C:\ (MS-Windows) you can find all
files in the file system. For example, type "/u" and CTRL-X CTRL-F. This
will match "/usr" (this is on Unix):
the file is found in /usr/ ~
If you now press CTRL-N you go back to "/u". Instead, to accept the "/usr/"
and go one directory level deeper, use CTRL-X CTRL-F again:
the file is found in /usr/X11R6/ ~
The results depend on what is found in your file system, of course. The
matches are sorted alphabetically.
COMPLETING IN SOURCE CODE
Source code files are well structured. That makes it possible to do
completion in an intelligent way. In Vim this is called Omni completion. In
some other editors it's called intellisense, but that is a trademark.
The key to Omni completion is CTRL-X CTRL-O. Obviously the O stands for Omni
here, so that you can remember it easier. Let's use an example for editing C
source: >
{
struct foo *p;
p->
The cursor is after "p->". Now type CTRL-X CTRL-O. Vim will offer you a list
of alternatives, which are the items that "struct foo" contains. That is
quite different from using CTRL-P, which would complete any word, while only
members of "struct foo" are valid here.
For Omni completion to work you may need to do some setup. At least make sure
filetype plugins are enabled. Your vimrc file should contain a line like
this: >
filetype plugin on
Or: >
filetype plugin indent on
For C code you need to create a tags file and set the 'tags' option. That is
explained |ft-c-omni|. For other filetypes you may need to do something
similar, look below |compl-omni-filetypes|. It only works for specific
filetypes. Check the value of the 'omnifunc' option to find out if it would
work.
==============================================================================
*24.4* Repeating an insert
If you press CTRL-A, the editor inserts the text you typed the last time you
were in Insert mode.
Assume, for example, that you have a file that begins with the following: >
"file.h" ~
/* Main program begins */ ~
You edit this file by inserting "#include " at the beginning of the first
line: >
#include "file.h" ~
/* Main program begins */ ~
You go down to the beginning of the next line using the commands "j^". You
now start