Old Liao once published an article in phperArticleIt is called using Vim for PHP development environment. It details the preparations required for using Vim for PHP development, this article introduces the things that Vim needs to do for C/C ++ development based on some materials and some of my own experiences. It is more convenient than php development.
The premise is of course you have downloaded vim, if not, please go to the official website to download the latest version, address is: http://www.vim.org/download.php
Help documentation: http://vimcdoc.sourceforge.net/
First, from the visual aspect:
The first thing to do is indent., Modify your vim configuration file_ Vimrc, Add at the endSet cindentIn this way, the C-style indent is set. The indent size here isShiftwidth.
The second thing to do is to highlight the syntax., This is required, in_ VimrcJoinSyntax enable.
Third, set the font.Setting a comfortable font makes programming much more comfortable. When editplus is used, I use consolas. In vim, I still use this font._ VimrcJoin
If has ("gui_running ")
Set guifont = consolas: H9
Endif
This font is used to run the vim interface.
Fourth, set the color scheme, You can click here to download, and then put it$ Vim "vimfiles" ColorsIn this directory, add the following configuration in
If has ("gui_running ")
Set guifont = consolas: H9
"Set color Schema
ColorschemeColorscheme_name
Endif
Colorscheme_nameThe name of the color scheme you want to set.
Next we are runningProgramUsed in:
First, use CTAG
The ctags program has been included in vim. Although ctags supports other editors, it only officially supports vim. Ctags can help programmers easily browseSource code. Use the following commandCodeCreate a "tags" file in the root directory:
[/Home/Brimmer/src] $ ctags-R
"-R" indicates recursive creation, which includes the source program under all subdirectories under the source code root directory. The "tags" file contains a list of these objects:
L macro defined by # define
L enumerated variable value
L function definition, prototype, and Declaration
L namespace)
L type definition (typedefs)
L variables (including definitions and declarations)
Class, struct, Enum, and Union)
L class, structure, and union member variables or functions
Vim uses this "tags" file to locate the marked objects above. The following describes how to locate these objects:
1) Use the command line. Add the "-T" parameter when running vim, for example:
[/Home/Brimmer/src] $ vim-T foo_BAR
This command will open the file defining "foo_BAR" (variable or function or other), and position the cursor to this line.
2) run the ": Ta" command in the vim Editor, for example:
: Ta foo_BAR
3) the most convenient way is to move the cursor over the variable or function name, and then press "Ctrl-]". Use ctrl-O to return the original location.
Note: When running vim, you must run it in the directory where the "tags" file is located. Otherwise, run the ": Set tags =" command to set the path of the "tags" file before vim can find the "tags" file.
You can also choose to use the taglist plug-in. This plug-in can display a list of functions, variables, and so on the right side.
Second, correct errors in the program
In the vim Editor Environment, You can compile the program by using ": Make" (the use of the make tool has been described in the cloud wind articles I mentioned in yesterday, of course, the premise is that there is a MAKEFILE file in the current directory. After ": Make" is run, if an error occurs in the program, it is displayed. At this time, the cursor will automatically point to the first place where an error occurs, and you can also see the error prompt. Then, you can correct the error, instead of finding the line with the error. Remember the following useful commands:
L ": CL" listing errors
L ": CN" points the cursor to the next error
L ": CP" points the cursor to the previous error
L ": cnew" starts from scratch
You can even let Vim identify other compilers rather than GCC error prompts. This is useful to some programmers who develop embedded systems, because they may not use GCC but other compilers. By settingErrorformatTo let Vim identify the error prompt of the compiler. Because the error messages of different compilers are different, you need to reset them if you are not using gcc.
"ErrorformatThe value is a string in the format of scanf in C language.
GCC's"Errorformat"Value: % F: % L:" % m. "% F" indicates the file name, "% L" indicates the row number, and "% m" indicates the error message.
Use": H errorformat"To view detailed help information.
Use": H quickfix", ": H make", ": H makeprg", ": H errorfile"View other information.
Third, use the shortcut key
The following shortcut keys are helpful to programmers:
Move cursor in Function
[[Go to the previous "{" in the first column
] To the next "{" in the first column
{Go to the previous empty line
} Go to the next empty line
GD refers to the definition of the local variable to be transferred to the current cursor
* Go to the next occurrence of the word indicated by the current cursor
# Go To The last occurrence of the word pointed by the current cursor
Matching of parentheses
% Is used to match parentheses, braces, and braces. It depends on what symbol the cursor points.
Conclusion:
Vim has always been a tool recommended by some cool people and is still rational. It greatly improves our work efficiency. If you want to change it for a long time, it is necessary to spend a week to familiarize yourself with vim!