Write a CC ++ program with Vim

xiaoxiao2021-03-06  78

Write a C / C program with Vim

VI is the most common text editor under UNIX. Vim (VI Improved) is its enhancement. Some people often take VIM and Emacs, VIM, although there are so many features like Emacs, but more convenient than Emacs. People who have used Emacs will definitely feel annoyed for some shortcuts of Emacs, sometimes I want to have eight hands. Vim's learning curve is not as long as Emacs, just look at VIM's own vitutor, approximately 20 minutes to master VIM usage. For the C / C programmers under UNIX, I recommend you to write programs using the combination of Vim CTags. Among them, I listened to me slowly. (The introduction of VIM below is mainly for version 5.6) VIM supports language guidance and automatic indentation

Vim automatically sets the syntax highlighting by the suffix name, such as: *. C, *. CPP, *. CC, etc.. Some reserves in C / C , such as: if, for, incrude, etc., there will be different colors, which will reduce the possibility of programmers to make mistakes. It is relatively easy to read the program. Use the following command to view help from VIM: ": h syntax", ": h syn-qstart", ": h syntax-printing".

Vim also supports automatic indentation according to the GNU, so that the code written by the programmer is more readily read, and it is also conducive to the cultivation of programming style. Use the following command to view the help of automatic indentation in VIM: ": h cindent", ": h cinoptions", ": h cinoptions-value", ": h cinkeys", ": h cinwords". Use CTAGS

CTAGS has been taken in Vim. Although CTAGS can also support other editors, it officially supports only VIM. CTags can help programmers easily browse source code. Use the following command to create a "tags" file in the root directory of the source code:

[/ home / brimmer / src] $ ctags -r

"-R" means recursion creation, which includes the source program in all subdirectory in the source code root directory. A list of these objects in the "tags" file:

l The macro defined with #define

l Value of enumerated variables

l function definition, prototype and statement

l Namespace (Namespace)

l Type Definition (TypeDefs)

l Variables (including definitions and declarations)

L - class, structure, enumeration type (Enum) and Union (UNION)

L-class, structural and union member variables or functions

Vim uses this "tags" file to locate the above-mentioned objects, let's introduce the method of positioning these objects:

1) Use the command line. Plus "-t" parameters when running VIM, for example:

[/ home / brimmer / src] $ VIM -T FOO_BAR

This command will open the file defined "foo_bar" (variable or function or other), and position the cursor to this line.

2) Use the ": ta" command in the VIM editor, for example:

: TA foo_bar

3) The most convenient way is to move the cursor on the variable name or function name, then press "Ctrl-]. Return the original place with "Ctrl-O". Note: When running VIM, you must run in the directory where the "tags" file is located. Otherwise, use the ": set tags =" command to set the ": set tags =" command when running the VIM, so that VIM can find the "Tags" file. Quick correction error

With ": make" in the VIM editor, you can compile the program. Of course, the premise is that there is a Makefile file in the current directory. After running ": make", if there is an error in the program, it will be displayed. At this time, the cursor will automatically point to the first place, and you can also see the wrong prompt. Then, you can correct the mistake without manually finding the wrong line. Remember the following useful commands:

l ": CL" lists the error

l ": cn" allows the cursor points to the next error

l ": cp" Let the cursor point to an error

l ": cnew" starts from the beginning

You can even let VIM identify other compilers instead of erroneous tips for GCC. This is useful for programmers for developing embedded systems because they are likely to use not GCC but other compilers. By setting the value of "ErrorMMAT", you can identify the error prompt of the compiler. Because different compilers' error prompts are different, if it is not used to be GCC, it is necessary to reset.

The value of "errorformat" is a string, its format and the SCANF of the C language acquaintance.

The value of GCC's "ErrorMMAT" is:% F:% L: /% M. Where "% f" indicates that the file name, "% L" represents the line number, "% m" indicates an error message.

Use ": h errormat" to view detailed help information.

Use ": H Quickfix", ": h make", ": h makeprg", ": h errorfile" to view other information. Useful shortcut

The following shortcuts are very helpful to programmers: move cursors in the function

[[Go to the previous "{"

]] Go to the next "{" in the first column.

{Go to the previous blank line

} Go to the next blank line

GD goes to the definition of local variables referred to in the current cursor

* Go to the next appearance of the words referred to as the current cursor

# 转到 到到 上 上 上 上 上 上 上 上

% Is used to match parentheses, brackets and braces. It depends on what the current cursor points to what symbols. other

Vim's profile is ".vimrc", you can configure Vim with this file. Vim's graphical interface is called GVIM. Vim also has a version used for Windows platforms. VIM resources

Vim's Homepage: http://www.vim.org/. Copyright statement

The copyright of this article belongs to the author brimmer (brimmer@linuxaid.com.cn) and www.linuxaid.com.cn. If you want to reprint, please add the copyright prompt.

Brimmer's Homepage: www.linuxaid.com.cn/ENGINEER/brimmer. The Document in the HTML format and Word format can be found on the home page.

转载请注明原文地址:https://www.9cbs.com/read-105354.html

New Post(0)