Look, someone must have said, what's the function? Vase?
Tell you, you say the vase is wrong, our tribe can all be real deal person, lie not, how can fool a person.
Let me tell you what this is all about:
1. File indexing function, that is, you can know what functions, variables, macro definitions, structures, classes and so on in this file
2. File directory, you can open the file you want to open through the directory window
3. Basic editing functions Needless to say,
4. Automatic completion of the file function, especially when the include, according to the path auto-completion, select the file you want
5. Auto-Complete class members, functions, namespaces, etc.
6. Syntax highlighting, providing type keywords, functions and other highlighting, of course, I do not feel necessary, so not set
7.c/h files are free to switch, when you are in coding, you definitely need to go back and forth between. H/hpp and. C/cpp, no problem, yes.
8.quickfix function, compile error, you would like to find the file corresponding to the error in the correct place, no problem, you can.
Below we say how to integrate these functions, some vim comes with, some need plug-in.
Two. Preparatory work
1. Verify that the file/path exists, some of the paths described in this article, such as:
~/.vim/plugin ~/.vim/doc ~/.vim/syntax
If not, please create a new.
2. The. vimrc file referred to in the text refers to the ~/.VIMRC
Three. Go to the Dungeon
1.vim Programming Common Commands
% jump to the pair of parentheses go [[ jump to the beginning of the code block (but require that ' {' In the code block must occupy a single line) GD jumps to the definition of the local variable " jump to the place where the cursor was last docked, is two 'instead of a"mx settings bookmark, x can only be a-Z of 26 letters ' x Jump to the bookmark ("'" is 1 left key)> increment indent,"x> " represents an increase in indent < decrease indentation for the following X lines , and"x<" means reducing the indentation of the following X lines
write a program without syntax highlighting will be a very painful thing ah, a piece of black, like has been running corpse, fortunately, VIM provides syntax highlighting function, in the picture above you can also see those comments, keywords, strings, etc., are displayed in different colors, to do so, first of all in your ~/ Add the following words to the. vimrc file:2. Syntax highlighting
Syntax Enablesyntax on
And then restart Vim, and open a C program file, is not feel the sudden color in front of the colorful up ...
If you do not like this color scheme you can choose a color scheme that you are satisfied with, then add the following ColorScheme xxx in the ~/.VIMRC file, as in this sentence:
ColorScheme Desert
Desert represents a color scheme, on the vim.org with you a lot of people, they do a variety of color themes, you can download a test, you can see your eyes. If you are not satisfied (you are really xxxx), it's okay, the author of Vim thought there would be someone like you, you can create your own color theme, the following this document to learn a little bit:
: Help Syntax.txt
More awesome syntax highlighting:
You may find that many things are not highlighted, such as arithmetic symbols, various parentheses, function names, custom types, and so on.
The main idea is to create a new grammar file, define what you want to highlight in the file, what to highlight what to highlight, with VIM is so confident. The so-called grammar file is a script that Vim uses to highlight various source files, and Vim relies on the script's description to make different text in the file display different colors, such as the C grammar file in a path similar to this one:
/usr/share/vim/vim64/syntax/c.vim
Grammar files in other languages can also be found in this path, and your may not be in this path, regardless of it, create a new grammar file under your own home, create a new empty file:
~/.vim/syntax/c.vim
in which to join
"========================================================"Highlight all Function"========================================================SYN Match Cfunction"/<[a-za-z_][a-za-z_0-9]*/>[^ ()]*) ("me=e-2syn Match cfunction"/<[a-za-z_][a-za-z_0-9]*/>/s* ("me=e-1Hi cfunction GUI=none guifg=#B5A1FF"========================================================"Highlight all Math Operator"========================================================"C Math OperatorsSYN Match Cmathoperator display"[-+/*/%=]""C pointer OperatorsSYN Match Cpointeroperator display"->/|/.""C Logical Operators-boolean resultsSYN Match Clogicaloperator display"[!<>]=/="syn Match clogicaloperator display"==""C bit OperatorsSYN Match Cbinaryoperator display"/(&/| | /|/^/|<</|>>/) =/="syn Match cbinaryoperator display"/~"syn Match cbinaryoperatorerror display"/~=""More C logical operators-highlight in preference to binarySYN Match Clogicaloperator display"&&/| | |"syn Match clogicaloperatorerror display"/(&&/| | | /)=""Math OperatorHi Cmathoperator guifg=#3EFFE2hi cpointeroperator GUIFG=#3EFFE2hi clogicaloperator GUIFG=#3EFFE2hi cbinaryoperator GUIFG=#3EFFE2hi cbinaryoperatorerror GUIFG=#3EFFE2hi clogicaloperator GUIFG=#3EFFE2hi clogicaloperatorerror GUIFG= #3EFFE2
And then open your C file to see if it's a lot brighter. There is a pressure box to tell you, if you add a type or structure, and so on, how to make it like "int", "void" to highlight it? Then add the following in the file ~/.vim/syntax/c.vim above:
This way your own type my_type_1, my_type_2, my_type_3 can also be "int" as highlighted, the disadvantage is that each additional type, it is necessary to manually add a bit here
" ======================================================== " My Own DataType " ========================================================syn keyword cType my_type_1 my_type_2 my_type _3
3.Ctags
Ctags let you jump in the program to jump, is simply a treasure of things, the Linux kernel source code has provided "make tags" this option, let us understand tags this file.
Tags file is an index file produced by the Ctags program, the Ctags program is called "Exuberant Ctags", is a UNIX alternative to the Ctags program, and more powerful than it is the default Ctags program on most Linux distributions. So what is a tags file for? What if you read a function call, or a variable, or a macro, and so on while reading the program, and you want to know where they are defined? With grep? That will search out a lot of irrelevant places. Now the popular use is <c-]> who knows? When the cursor is on a function or variable, press CTRL +], the cursor will automatically jump to its definition, enough, you no longer envy Visual Studio programmer, Cool
You now do not rush to press <C-]>, because the computer default is not Ctags program, you need to install, Ctags site is http://ctags.sourceforge.net, need to manually download the above, and then install, I am under the 5.8 version, then take 5.8 as an example:
$tar -xzvf ctags-5.8. Tar . GZ$CD ctags-5.8$. /configure$make$makeinstall// require root permission
Then go to your source directory, if your source code is a multi-level directory, go to the top-level directory, run the command in this directory: Ctags-r, such as:
$CD/home/styuan/ctags-5.8-R
At this time in the/home/styuan/ctags-5.8 directory will generate a tags file, now with vim open/home/styuan/ctags-5.8/main.c
$ vim/home/styuan/ctags-5.8/main.c
Then run the command in VIM:
: Set tags=/home/styuan/ctags-5.8/tags
This command adds the tags file to vim, and you can also put this phrase into the ~/.VIMRC if you regularly program in this project.
Let's start with the real gun, like, put the cursor on the Createtagsforentry () function
At this point the <C-]> is pressed, and the cursor automatically jumps to the definition of the createtagsforentry () function, as shown here:
If at this point you want to jump back to the position, you can also press <C-T>, and then jump back to the Createtagsforentry () function is called the place, variables, structures, macros, and so on, you can, quickly try it ...
But there is a small flaw, you modify the program, such as adding a function definition, delete the variable definition, tags file can not be automatically rebuild, you must manually run the command:
$ ctags-r
4.TagList, efficient reading code
http://sourceforge.net/projects/vim-taglist/files/vim-taglist/
Decompression Taglist_45.zip, you can see there are two directories doc and plugin, the structure is as follows
taglist_45| | --------doc| \--------taglist.txt|\--------plugin\--------Taglist.vim
Execute the following shell command, which is the installation complete
CP Doc/taglist.txt ~/.vim/doc/cp Plugin/taglist.vim ~/.vim/plugin/
How to use:
In the source directory, execute ctags-r to each directory recursively create tags file
Use VIM to open the source file, execute tlist in command mode, you can enable TagList plug-in,<f1> to view the TagList Help information
Configure taglist in. VIMRC at the same time
"" TagList "let tlist_show_one_file=1 " only show the current file of tagslet tlist_winwidth= " set taglist width let tlist_exit_onlywindow=1 " taglist window is the last window, exit vimlet tlist_use_right_window=1" Display the TagList window on the right side of the Vim window
5.WinManager File Explorer and window Manager
: http://www.vim.org/scripts/script.php?script_id=95
Unzip and get two folders plugin and doc, copy them to the corresponding directory under ~/.vim, such as the installation of TagList
Modify the. vimrc file
" Winmanager Settings " Integrated TagList window ' fileexplorer| TagList'" set shortcut keys, WM outbound Nmap wm:wmtoggle<cr>
Use WM key in Vim to call out the window, the above example is already in use, where the upper left corner is the Winmanager window, the lower left corner is the TagList window.
6.QuickFix window
In the first picture there is a quickfix window, when make, there may be errors, and let the error location to the corresponding file, which requires quickfix appearance, such as deliberately in xxx.c each row with a comma, and then
: Make
Obviously compile will report a lot of errors, when the compile end and exit to the source interface, the compiler reported that the error has not been seen, but we can use the Quickfix window to find out the error message, with the following command to bring up the Quickfix window:
: CW
When the cursor moves to the corresponding position, press ENTER, but also jump to the wrong file corresponding to the place oh, is not very good ~ at the same time can also jump:
: CN // switch to next result :CP // switch to previous result
Switching between 7.c/h files
As a C programmer, the daily coding between the source file and the header file switching is the usual thing, the direct use of vim to open its source/header file is actually not a problem, but only with a button to switch over, this is how thoughtful function ah ....
Plug-in Name: A
: http://www.vim.org/scripts/script.php?script_id=31
Once downloaded, placing A.vim in the ~/.vim/plugin folder is equivalent to installing the
: A Switch to C/h file in new buffer: As split window and open C/H file: AV Portrait Split window and open C/H file: at Create a new tab and open a C/h file
8. Automatic completion of the Autocomplpop
Autocomplpop Automatic popup for support code (normal variable function)
: http://www.vim.org/scripts/script.php?script_id=1879
In accordance with the installation method of other script plugins, copy the extracted files to the corresponding directory under ~/.vim/:
autoload/*-~/.vim/autoload/
doc/*-~/.vim/doc/
plugin/*-~/.vim/plugin/
Re-open vim to use. To add a Help file: Helptags ~/.vim/doc/(Opens the helper file: H (ELP) Autocomplpop) as follows:
Automatic completion of 9.c++ code
Plugins: Omnicppcomplete, supported classes. ,->,:: Automatic completion of operators
: http://www.vim.org/scripts/script.php?script_id=1520
In accordance with the installation method of other script plugins, copy the extracted files to the corresponding directory under ~/.vim/:
autoload/*-~/.vim/autoload/
doc/*-~/.vim/doc/
after/*-~/.vim/after/
Also add the appropriate configuration in the. vimrc
"omnicppcomplete Configurationfiletype plugin indent onset completeopt=Menu,menuone"open the. HintLet omnicpp_maycompletedot=1"Tips for openingLet omnicpp_maycompletearrow=1"Open:: TipsLet omnicpp_maycompletescope=1"Open NamespaceLet Omnicpp_namespacesearch=1"Open Global SearchLet Omnicpp_globalscopesearch=1"the default namespace is STDLet omnicpp_defaultnamespace=["STD"] "turn on function hint functionsLet omnicpp_showprototypeinabbr=1"automatically navigates to the secondLet Omnicpp_selectfirstitem =2 "set the shortcut key to generate STD tag as tagMap tag:!ctags-r--c++-kinds=+p--fields=+ias--extra=+q <CR>
When you hit tag in vim, the corresponding tags will be generated, then set Tags=xxx.tags.
Note: ctags-r--c++-kinds=+p--fields=+ias--extra=+q to generate tags, is a shell command, so when binding the keys to use
Map tag:!ctags-r--c++-kinds=+p--fields=+ias--extra=+q <cr>, which means to press the tag command in Vim, execute the corresponding shell command, and then also set Tags:set tags =xxx.tags, if you feel that each time the setup is inconvenient, and the common directory does not change, can also be written in. vimrc
Medium: Set Tags+=/home/xxx/tags
OK, done, of course, after the integration, the window is more, so attach vim common window operation
Vim Multi-Window usage tips
1. Open multiple Windows
The commands for opening several windows are the following:
Horizontal cutting window
: new+ window name (file name after saving)
: split+ window name, can also be abbreviated as: sp+ window name
Portrait cutting window Name
: vsplit+ window name, can also be abbreviated as: vsp+ window name
2. Close Multiple windows
Can be used: q!, can also be used: Close, the last window cannot be closed with close. Using close only temporarily closes the window, its contents are still in the cache, and only use q!, w!, or X to actually exit.
: TABC Close the current window
: Tabo Close All windows
3. Window switch
: ctrl+w+j/k, through j/k can switch up or down, or: ctrl+w plus up and down keys, you can also double-click the ctrl+w to switch windows in turn.
4, Window size adjustment
Longitudinal adjustment
: Ctrl+w + Vertical expansion (Increased number of rows)
: ctrl+w-Zoom Out (decrease in number of lines)
: res (ize) num For example:: Res 5, display line number adjusted to 5 rows
: Res (ize) +num adds the current window height to num rows
: Res (ize)-num reduce the current window height by num rows
Transverse adjustment
: Vertical res (ize) num Specifies that the current window is num column
: Vertical res (ize) +num add num column to current window
: Vertical res (ize)-num reduces the current window to NUM columns
5. Renaming a window
: F File
6, vi open multi-file
VI a B C
: N jumps to the next file, you can also specify the file to jump directly, such as: N C, you can jump directly to the C file
: e# back to the file you just edited
7. File browsing
: Ex Opens the Directory browser, can browse all the files in the current directory, and can choose
: Sex horizontally splits the current window and opens the Directory browser in a window
: LS Displays the current buffer condition
8, VI and Shell switch
: Shell can switch to shell command line without shutting down VI
: Exit from Shell to VI
VIM Development Environment Configuration