vi Compiler Learning and use

Source: Internet
Author: User

Transfer from http://mylxiaoyi.iteye.com/blog/313975

When we use VIM to process files, we can use Vim's auto-completion function to greatly speed up our work. So-called auto-completion means that when we enter a part of a word, pressing CTRL-P,VIM will automatically complete the rest. We used the previous learning process: abbreviate command to précis-writers a word to achieve the purpose of auto-completion, and here we will see is a more powerful auto-complete function. Vim can be very simple and flexible to decide which word to use for automatic completion. While we are using Vim as a powerful AutoComplete feature, we can also customize our auto-complete features, and we can also use different types of AutoComplete.
If we are writing a C program, and we are called to get the following sentence:
TOTAL=CH_ARRAY[0]+CH_ARRAY[1]+CH_ARRAY[2]
Then we enter the Total=ch_array[0]+ch_, and then press Ctrl-p,vim will automatically do the rest for us, then we get will be
Total=ch_array[0]+ch_array
From this we can see that we are working on the file in such a way can greatly speed up our processing speed.
So how does vim find a matching word? In the default case, Vim looks for a word in the following steps:
1 finding in the current file
2 Finding in other Windows
3 finding in other mounted buffers
4 finding in files that do not have a buffer loaded
5 list in the current tag (tag) is to be searched
6 Find in all files included in the current file's # include
Of course, we can also customize our search order.
When we use the Auto-completion command, CTRL-P is looking backwards for matching words, and a command ctrl-n is looking forward for matching words. They have the same function and function, and the difference is only in finding the direction of the difference.
Vim also provides a number of commands that allow us to customize some of our search features. For example, we can use the following command to tell vim the difference in ignoring the case during the AutoComplete lookup:
: Set ignorecase
This way, if we enter Ins,vim, we will think of it as Insert,inside or instep. Of course, the premise is to include these words in the text we're editing, or we'll find them.
In order to be able to do the exact search automatically, we do not want the above situation to occur, we can set some options to tell vim case-sensitive situation. Then we need to use the following command:
: Set Infercase
Then if we enter INS again, the matching list becomes instep,inside,insert. We can do this by pressing CTRL-P or CTRL-N.
In most cases, Vim's default settings are good for the job, but sometimes we need to define some of our completed options, and we'll use the complete option. This option is in the following format:
: Set Complete=key,key,key
The key values that may appear in this command are as follows:
. Current file
B has been loaded buffer, but there is no file inside the window
d files defined in the current file and included by # include
I consist of files included in # include
k files defined by the dictionary option
Kfile file with name {file}
T tags (tags) file
U does not have a loaded buffer
W Files in other windows
We can use the path option to tell vim how to find the files that we include in the current file. We can also specify a dictionary, which has the following format:
: Set Dictionary=file,file,....
This option defines the files to find when matching lookups by command ctrl-p and Ctrl-n. In Linux, this definition file is in/usr/dict/words, so if we want to add this file to find it, we need to use the following command:
: Set Dictionary=/usr/dict/words
If we want to use a file of our own can also be set
: Set Dictionary=/home/oualline/words,/usr/doc/words
We can also specify a dictionary file with the K option combination:
: Set Dictionary=k/usr/oualline/words
We can also use the k tag option several times:
: Set Dictionary=k/usr/dict/words,k/usr/share/words
In the above mentioned Ctrl-p and ctrl-n to find matching when looking for a wide range of comparisons, We can, of course, use the command to do some more rigorous lookups. We can then use the command ctrl-x. When we enter Ctrl-x we enter a sub-pattern of ctrl-x. Then we can use the following command to find:
CTRL-D macro Definition
Ctrl-f file name
Ctrl-k Dictionary
Ctrl-i current file and files included by # include
Ctrl-l Entire Line
CTRL] Tag (tags)
Ctrl-p forward lookup, same as no ctrl-x command
Ctrl-n backward Lookup, same as no ctrl-x command
Ctrl-x
The ctrl-d command looks up the macro definition. He will also look up the # include file. Once we have executed this command, we can use ctrl-p,ctrl-n for matching lookups.
For example, we can edit the following test file:
Content in the Include.h file
#define MAX (x, y) < (y)? ( Y):(x))
#define MIN (x, y) (() < (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"
At this point we begin to edit the Main.c file, and if we press Ctrl-x we will enter Ctrl-x's sub-mode. If we are looking for a macro definition, we can press ctrl-d, This will simply show how many matching options are available at the bottom of the screen. So we can use Ctrl-p and ctrl-n to do the auto-complete function. The command Ctrl-x Ctrl] is to find the next tag (tag), A token is a definition of a C function. We can use the command ctags command to generate a list of C function definitions. We can do this with this command:
$ctags *.c *.h
We can then use the Ctrl-x Ctrl] command to find and match the tags in insert mode.
By default, the Vim editor simply displays the name of the tag, and we can execute the following command so that the entire tag can be displayed later:
: Set Showfulltag
We can use the Ctrl-x ctrl-f command to match the file name. He will find the files in the current directory and will display the matching content, then you can use the Ctrl-p and Ctrl-n commands to select the matching options you want.
So far we've just been talking about words, we can match the line with the command Ctrl-x ctrl-l, and we can also use Ctrl-n and ctrl-p to match the options. We can also scroll down the text with Ctrl-x after entering the ctrl-y command , and scroll up the text with CTRL-E.

vi Compiler Learning and use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.