Vi7.0 comes with the automatic completion function omni-completion.
So how does Vim find matching words? By default, VIM performs the following steps when searching for a word:
1. Search the current file.
2. Search in other windows
3. Search for other mounted buffers.
4. Search for files without a buffer.
5. Search in the current tag list
6. Search for all the files contained in the # include file of the current file.
Of course, we can also customize our search order.
The command CTRL-P we use when auto-completion is to look backward for matching words, and a command CTRL-N is to look forward for matching words. they have the same functions and functions, but they differ in the search direction.
Vim also provides many commands that allow us to customize some of our search features. for example, we can use the following command to tell Vim to ignore the case Difference during automatic search:
: Set ignorecase
In this way, if we enter INS, VIM will think it is insert, inside, or instep. Of course, the premise is that these words are included in the text we edited, or we will find them.
In order to be able to perform exact search automatically, we do not want the above situation to occur. We can set some options to tell Vim case-sensitive situations. At this time, we need to use the following command:
: Set infercase
In this way, if we enter the INS again, the list that matches it becomes instep, inside, insert. We can do it by CTRL-P or CTRL-N.
In most cases, Vim's default settings can work well, but sometimes we need to define some of our complete options, then we need to use the complete option. the format of this option is as follows:
: Set complete = key, key, key
This command may contain the following key values:
. Current File
B has been installed with a buffer, but there are no files in the window
D. Define and include the files in the current file by # include
I consists of # include files.
K files defined by the dictionary Option
Kfile: {file}
T tag (TAGS) File
U does not load the buffer.
W files in other windows
We can use the path option to tell Vim how to find the files we include in the current file. We can also specify a dictionary. The format of this option is as follows:
: Set dictionary = file, file ,....
This option defines the file to be searched for when the command CTRL-P and CTRL-N match the lookup. in Linux, this definition file is in/usr/dict/words, so if we want to add this file for search, we need to use the following command:
: Set dictionary =/usr/dict/words
If we want to use a file of our own, we can set it like this.
: Set dictionary =/home/oualline/words,/usr/doc/words
We can also specify a dictionary file and K options for combination:
: Set dictionary = K/usr/oualline/words
We can also use the K tag option multiple times:
: Set dictionary = K/usr/dict/words, K/usr/share/words
In the above mentioned CTRL-P and CTRL-N to find matching when the range of the wider range of fan, of course we can also use the command for some more rigorous search. at this point we can use the command CTRL-X. when we enter the CTRL-X we enter a sub-pattern of the CTRL-X. in this case, we can use the following command for search:
CTRL-D macro definition
CTRL-F file name
A CTRL-K dictionary
CTRL-I current file and file contained by # include
CTRL-L entire line
CTRL-] tags)
CTRL-P lookforward, same as when there is no CTRL-X command
CTRL-N lookup backward, same as when there is no CTRL-X command
CTRL-X
The CTRL-D command looks up the macro definition. He will also look up the # include file. When we're done with this command, we can use the CTRL-P, The CTRL-N for matching lookup.
For example, you can edit the following test file:
Content in the include. h file
# Define max (x, y) (x) <(y )? (Y) :( X ))
# Define min (x, y) (x) <(y )? (X) :( y ))
Int sum (INT I1, int I2)
{Return (I1 + I2 );}
Content in the main. c file:
# Include "include. H"
# Define more "/usr/UCB/more"
In this case, edit main. c file, if we press the CTRL-X we will enter the sub-mode of the CTRL-X. if we were looking for a macro definition, we could press the CTRL-D, and then we would simply display the matching options at the bottom of the screen. so we can use CTRL-P and CTRL-N to automatically complete the function. while the command CTRL-X
CTRL-] is to find the next tag, which is the definition of a C function. we can use the ctags command to generate a list of C function definitions. we can use this command like this:
$ Ctags *. C *. h
So that we can use the CTRL-X in insert mode.
CTRL-] command to find and match the tag.
By default, the vim editor simply displays the tag name. You can run the following command to display the entire Tag:
: Set showfulltag
We can use CTRL-X
CTRL-F command to match the file name. he looks up the file in the current directory and displays the Matching content, then you can use the CTRL-P and CTRL-N commands to choose the matching option you want.
So far we have been talking about just operating on words, and we can use the command CTRL-X
The CTRL-L matches a row, and we can also match options with CTRL-N and CTRL-P. we can also scroll down the text with a CTRL-X after entering the CTRL-Y command, and scroll up the text with a CTRL-E.
Previous/next article 11:16:31/personal classification: Linux
View (31)/comment (0)/score (0/0)
When we use Vim to process files, we can use the automatic completion function of VIM to greatly accelerate our working speed. The so-called automatic completion means that when we enter a part of a word, press Ctrl
-P, VIM will automatically complete the rest. we used the abbreviate command in the previous learning process to remember a word to achieve the goal of Automatic completion. Here we will
It is a more powerful Automatic completion function. Vim can be very simple and flexible to decide which word to use for Automatic completion.
While using Vim's powerful Automatic completion function, we can also customize our Automatic completion features and use different types of Automatic completion features. [@ more @] When we use Vim to process files, we can use the automatic completion function of VIM to greatly speed up our work. the so-called automatic completion means that when we enter a part of a word, press the CTRL-P, VIM will automatically complete the remaining part. in the previous learning process, we used the abbreviate command to remember a word to achieve automatic completion. Here we will see a more powerful Automatic completion function. vim can be very simple and flexible to decide which word to use for Automatic completion.
While using Vim's powerful Automatic completion function, we can also customize our Automatic completion features and use different types of Automatic completion features.
If we are writing C programs, and we get the following sentence:
Total = ch_array [0] + ch_array [1] + ch_array [2]
Then we enter total = ch_array [0] + CH _, and then press the CTRL-P, VIM will automatically complete the rest for us, then we will get
Total = ch_array [0] + ch_array
We can see that this method can greatly speed up processing files.
So how does Vim find matching words? By default, VIM performs the following steps when searching for a word:
1. Search the current file.
2. Search in other windows
3. Search for other mounted buffers.
4. Search for files without a buffer.
5. Search in the current tag list
6. Search for all the files contained in the # include file of the current file.
Of course, we can also customize our search order.
The command CTRL-P we use when auto-completion is to look backward for matching words, and a command CTRL-N is to look forward for matching words. they have the same functions and functions, but they differ in the search direction.
Vim also provides many commands that allow us to customize some of our search features. for example, we can use the following command to tell Vim to ignore the case Difference during automatic search:
: Set ignorecase
In this way, if we enter INS, VIM will think it is insert, inside, or instep. Of course, the premise is that these words are included in the text we edited, or we will find them.
In order to be able to perform exact search automatically, we do not want the above situation to occur. We can set some options to tell Vim case-sensitive situations. At this time, we need to use the following command:
: Set infercase
In this way, if we enter the INS again, the list that matches it becomes instep, inside, insert. We can do it by CTRL-P or CTRL-N.
In most cases, Vim's default settings can work well, but sometimes we need to define some of our complete options, then we need to use the complete option. the format of this option is as follows:
: Set complete = key, key, key
This command may contain the following key values:
. Current File
B has been installed with a buffer, but there are no files in the window
D. Define and include the files in the current file by # include
I consists of # include files.
K files defined by the dictionary Option
Kfile: {file}
T tag (TAGS) File
U does not load the buffer.
W files in other windows
We can use the path option to tell Vim how to find the files we include in the current file. We can also specify a dictionary. The format of this option is as follows:
: Set dictionary = file, file ,....
This option defines the file to be searched for when the command CTRL-P and CTRL-N match the lookup. in Linux, this definition file is in/usr/dict/words, so if we want to add this file for search, we need to use the following command:
: Set dictionary =/usr/dict/words
If we want to use a file of our own, we can set it like this.
: Set dictionary =/home/oualline/words,/usr/doc/words
We can also specify a dictionary file and K options for combination:
: Set dictionary = K/usr/oualline/words
We can also use the K tag option multiple times:
: Set dictionary = K/usr/dict/words, K/usr/share/words
In the above mentioned CTRL-P and CTRL-N to find matching when the range of the wider range of fan, of course we can also use the command for some more rigorous search. at this point we can use the command CTRL-X. when we enter the CTRL-X we enter a sub-pattern of the CTRL-X. in this case, we can use the following command for search:
CTRL-D macro definition
CTRL-F file name
A CTRL-K dictionary
CTRL-I current file and file contained by # include
CTRL-L entire line
CTRL-] tags)
CTRL-P lookforward, same as when there is no CTRL-X command
CTRL-N lookup backward, same as when there is no CTRL-X command
CTRL-X
The CTRL-D command looks up the macro definition. He will also look up the # include file. When we're done with this command, we can use the CTRL-P, The CTRL-N for matching lookup.
For example, you can edit the following test file:
Content in the include. h file
# Define max (x, y) (x) <(y )? (Y) :( X ))
# Define min (x, y) (x) <(y )? (X) :( y ))
Int sum (INT I1, int I2)
{Return (I1 + I2 );}
Content in the main. c file:
# Include "include. H"
# Define more "/usr/UCB/more"
In this case, edit main. c file, if we press the CTRL-X we will enter the sub-mode of the CTRL-X. if we were looking for a macro definition, we could press the CTRL-D, and then we would simply display the matching options at the bottom of the screen. so we can use CTRL-P and CTRL-N to automatically complete the function. while the command CTRL-X
CTRL-] is to find the next tag, which is the definition of a C function. we can use the ctags command to generate a list of C function definitions. we can use this command like this:
$ Ctags *. C *. h
So that we can use the CTRL-X in insert mode.
CTRL-] command to find and match the tag.
By default, the vim editor simply displays the tag name. You can run the following command to display the entire Tag:
: Set showfulltag
We can use CTRL-X
CTRL-F command to match the file name. he looks up the file in the current directory and displays the Matching content, then you can use the CTRL-P and CTRL-N commands to choose the matching option you want.
So far we have been talking about just operating on words, and we can use the command CTRL-X
The CTRL-L matches a row, and we can also match options with CTRL-N and CTRL-P. we can also scroll down the text with a CTRL-X after entering the CTRL-Y command, and scroll up the text with a CTRL-E.