Teach you to convert vim into an IDE programming environment (GRAPHIC) Wu Yin _ Related skills

Source: Internet
Author: User
Tags function definition logical operators parent directory tag name egrep

By: Wu Yin

Copyright: The article is copyrighted by Wu Yin and his lovely wife, Little bun. may be transmitted and reproduced at will without any commercial purpose. Any act of this article shall be subject to the consent of the author for commercial purposes.
Contact Way: lazy.fox.wu#gmail.com

1 written in front

Linux programming has been criticized for the point is: There is no good IDE, but I heard that the Linux cattle, hackers and other things do not use the IDE. But for me and other coder from the Windows platform, a useful IDE is how important ah, it is estimated that a lot of people are stuck on this threshold, "工欲善其事, its prerequisite" Well, I think if there is a very good IDE, those who are Linux cattle will welcome. These are the good wishes of the laboring people, today, I teach you to convert Gvim into a simple IDE, said it is "simple" is the interface looks "simple", but the function is definitely not better than a good IDE poor, the features are there, there should not be some features, you have nothing to steal Joy Bar, Now I'm going to start by introducing today's work.

This article will teach you:

1. Installation of Chinese help manual
2. Vim Programming Common commands
3. Syntax highlighting
4. Jump in the program: use of Ctags
5. Teach you to efficiently browse the source--plugin: taglist
6. File Browser and window Manager--plugin: Winmanager
7. Use of Cscope
8. QuickFix window
9. Quick browse and Operation Buffer--plugin: Minibufexplorer
Switch between c/h files--plugins: A
11. Find in Engineering--plugins: Grep
12. Highlighted Bookmark--plugin: Visualmark
13. Auto-complement
14. Accelerate your completion--plugin: Supertab

This article will not teach you:

1. How to use Vim. This article will not start from zero to teach you how to use VIM, if you are first contact with VIM,
It is recommended that you take a look at other vim introductory tutorials, or enter a command under the shell: Vimtutor,
This is a simple introductory tutorial.
2. Programming skills.
3. The writing of Vim script.

My working environment is: Fedora Core 5

Gvim is 7.0 of its own compilation, if you have not yet installed Gvim, please see my article < compile and configure Gvim 7.0> in Redhat Linux 9
Because I have been engaged in C language work, so the following examples are in the C language Program demo, other languages have not tried, if there are friends in other languages have problems, you can discuss some with me, I will try to help you.

This article uses the demonstration source code is the vim7.1 source code, may download to the source code package in www.vim.org: vim-7.1.tar.bz2, you also may not need to download, uses your own program the source code, the relation is not big. I unzipped the source code in my home directory: ~/vim71

The following is a definition of some of the names in the article:

1. Some of the symbols used in the article, such as <c-t>, <c-s-a>, and so on, you can use the following command to see the explanation:

: Help Keycodes

2. Some of the paths mentioned in this article, such as:
If you don't have it, create it yourself.
3. VIMRC documents refer to the ~/.VIMRC

First to show you a picture, I am the vim of the interface, solution Jiejie first ^_^

(---figure 1---)
I will teach you the following features in this article, in contrast to the icons above:

Simple and straightforward buffer browsing and operation
File browser
Tag Browser
Highlighted bookmarks
Richer syntax highlighting
Drop-down for member variables, auto-complement

2 Chinese Help manual Installation

Vim's own Help manual is in English, in peacetime programming people do not have much difficulty reading, not to mention there are "star translation King", but there are a group of people to translate it into Chinese, but I can not resist the temptation to install it, alas ... Another good chance to learn English, not a precedent.
Let's take a look at my Chinese help interface:

(---Figure 2---)
Installation method:
Download the Chinese help package at the following Web site:
Http://vimcdoc.sf.net (中文版)
Http://vcd.gro.clinux.org (Chinese)

The downloaded package should be similar to this: vimcdoc-1.5.0.tar.gz
After decompression, there is a Doc folder, the contents of which are copied to ~/.vim/doc, or vim installation directory under the Doc directory, at this time vim help information is already in Chinese.
A. If you cannot display Chinese, add the following sentence to the ~/.VIMRC:
B. The text of the Help file is utf-8 encoded, and if you want to use VIM to view it directly, you need to set it in ~/.VIMRC:
Set Encoding=utf-8

3, VIM programming commonly used commands

Suggest to look at the following chapters in the Help manual, where you can skip the tags file, in the later chapters will say, then you come back to see, it is very simple:

: Help usr_29
: Help usr_30

Here are some of the commands I used to put in here for my memo:

% Jump to paired parentheses to
[[ Jumps to the beginning of the code block (but requires that ' {' must have a separate line in the code block)
Gd Jump to the definition of a local variable
'' Jump to where the cursor was last docked, two ', not one '
Mx Set bookmark, x can only be a A-Z 26 letters
' X Jump to Bookmark ("'" is the key to the left of 1)
> Increase indentation, "x>" means to increase the indentation of the following X lines
< Reduce indentation, "x<" means to reduce the indentation of the following X lines

4. Syntax highlighting

How painful it would be to write a program without syntax highlighting, thanks to Vim's author is a programmer (if not, that can be NB Large), provides syntax highlighting, in the above picture you can also see those comments, keywords, strings, etc., are displayed in different colors, to do so, First, add the following words to your ~/.VIMRC file:

Copy Code code as follows:

Syntax enable
Syntax on

And then restart Vim, and open a C program file, is not to feel the sudden color of the suddenly colorful up ...
If you don't like the color scheme you can choose a color scheme that you want in the Edit-> color scheme (GVIM) and add the following sentence to the ~/.VIMRC file:

Copy Code code as follows:

ColorScheme Desert

Desert is my favorite color scheme, you can change it to yours. If you are not satisfied with the color scheme in the menu (you too spend it), it doesn't matter, there are a lot of people like you on the vim.org, they do a variety of color themes, you can download one of the tests, and you can see more of your vertigo. If you are not satisfied with this (you are really xxxx), it doesn't matter, Vim's author early thought that there will be you, you can create your own color theme, the following document to learn a little better:

Copy Code code as follows:

: Help Syntax.txt

The brighter syntax Highlights:
You may find that many things are not highlighted, such as operational symbols, parentheses, function names, custom types, and so on, but looking at the picture above, my operational symbols and function names highlight ^_^, want to know why? Wow haha .... Let me teach you ...

The main idea is to create a new grammar file, define what you want to highlight in the file, highlight what you want to highlight, and use VIM to be so confident. The so-called grammar file is vim used to highlight a variety of source files of a script, vim by this script description of the file in different text display different colors, For example, the C language syntax file is placed in a path similar to this:
The syntax file for other languages can also be found in this path, and yours may not be in this path, whatever it is, Create a new grammar file in your own home, create a new blank file:
to add

"========================================================" Highlight all Function "=============================== ========================= syn Match cfunction "/&lt;[a-za-z_][a-za-z_0-9]*/&gt;[^ ()]*) (" Me=e-2 syn match cFunction "/ &lt;[a-za-z_][a-za-z_0-9]*/&gt;/s* ("me=e-1 hi cfunction gui=none guifg= #B5A1FF" =================================== ===================== "Highlight all Math Operator" ======================================================== "C Math Operators syn match cmathoperator display "[-+/*/%=]" "C pointer operators syn match cpointeroperator display"-&gt;/|
/." "C logical operators-boolean Results syn match clogicaloperator display" [!&lt;&gt;]=/= "syn match Clogicaloperator D Isplay "= =" "C bit Operators syn match cbinaryoperator display"/(&amp;/| | /|/^/|&lt;&lt;/|&gt;&gt;/) =/= "syn match cbinaryoperator display"/~ "SYN match cbinaryoperatorerror display"/~= "" Mor E C logical operators-highlight in preference to binary SYN match Clogicaloperator Display "&amp;&amp;/| | |" SYN match CLOGICALOPERATORERROR display "/(&amp;&amp;/| | | /) = "" Math Operator hi cmathoperator guifg= #3EFFE2 hi cpointeroperator guifg= #3EFFE2 hi clogicaloperator guifg= #3E FFE2 hi cbinaryoperator guifg= #3EFFE2 hi cbinaryoperatorerror guifg= #3EFFE2 hi clogicaloperator guifg= #3EFFE2 hi CLog Icaloperatorerror guifg= #3EFFE2

And then open your C file to see if it's a lot brighter. There is also a pressure at the bottom of the box to tell you, if you add a type or structure, and so on, how to make it also like "int", "void" to highlight it? Then add the following dongdong to the file ~/.vim/syntax/c.vim above:

" my Own DataType
============================ ============================
syn keyword cType  my_type_1 my_type_2 my_type_3

So your own type my_type_1, my_type_2, My_type_3 can also be the same as "int" highlighted, the disadvantage is that each additional type, it will be manually added here, if someone knows the easier way please be sure to tell me, with the following address:

: lazy.fox.wu#gmail.com
Homepage : Http://blog.csdn.net/wooin

5, jump to jump in the program: the use of Ctags

Wow, this can be powerful, tag file (tag file) but the programmer's housekeeping treasure, you can not use it, but you can't not know it, because the Linux kernel source code has provided "make tags" this option. Here we will introduce the tag file.

Tags file is generated by the Ctags program an index file, Ctags program is called "Exuberant Ctags", is the UNIX above Ctags program alternatives, and more powerful than it is the most Linux distributions on the default Ctags program. So tags file is what to do with it? If you read a function call while reading the program, or a variable, or a macro, and so on, what do you want to know about their definition? With grep? That would have found a lot of irrelevant places. Now popular with the <c-]>, who used to know Ah, when the cursor on a function or variable, press "CTRL +]", the cursor will automatically jump to its definition, strong enough, you do not have to envy the Visual Studio programmers, began to envy me ~_~.

You should not rush to press <C-]> now; you press the useless, what do you want me to do, you have to do is to check your computer has ctags this program, if there is, what version, if it is ctags 5.5.4, like me, you'd better to install a ctags 5.6, which It will be used in the following automatic completion chapters. On this site: http://ctags.sourceforge.net, download a file like ctags-5.6.tar.gz down (now it seems like the 5.7 version is coming out, but I haven't used it yet):

Unzip the installation with the following command:

Copy Code code as follows:

$ TAR-XZVF ctags-5.6.tar.gz
$ CD ctags-5.6
$ make
# make Install//requires root permission

Then go to your source directory, if your source is a multi-level directory, go to the top of the directory, in the directory to run the command: ctags-r
I'm now presenting it as a vim71 source directory.

Copy Code code as follows:

$ cd/home/wooin/vim71
$ ctags-r

At this time in the/HOME/WOOIN/VIM71 directory will generate a tags file, now with vim open/home/wooin/vim71/src/main.c

Copy Code code as follows:

$ vim/home/wooin/vim71/src/main.c

Then run the command in VIM:

Copy Code code as follows:

: Set Tags=/home/wooin/vim71/tags

This command will add tags file to vim, you can also put this sentence into the ~/.VIMRC, if you often in this project programming.
Let's start with the real knife, the following figure, put the cursor on the Setmouse () function

(---Figure 3---)

When you press <C-]>, the cursor automatically jumps to the definition of the Setmouse () function, as shown in the following figure:

(---Figure 4---)

If you still want to jump back to the position, you can also press <C-T>, and then jump back to the place where the Setmouse () function is called, variables, structure, macros, etc., all right, try it quickly ...

Now I'm going to go back and learn the VIM manual in section 3rd.

: Help usr_29

But there is a small flaw, you modify the program, such as the addition of function definition, delete the variable definition, tags file can not automatically rebuild, you have to manually run the command:

$ ctags-r

Make tags file updates, but people are gratified that vim does not need to restart, the program is being written also do not have to quit, immediately can be correctly used <C-]> and <C-T>. If anyone knows a simpler way, please do tell me.

6, teach you to efficiently browse the source--plugin: taglist

Download Address http://www.vim.org/scripts/script.php?script_id=273
Version 4.4
Installation Unzip the taglist_xx.zip in the ~/.vim directory
Manual : Help Taglist.txt

On the Windows platform with the source insight to see the program people must be familiar with the code window to the symbol window to the left, which lists all the current file macros, global variables, function names, etc., in view of the code with this window to the overall situation, switching location is quite convenient, Today tells you a Vim plug-in: TagList, you can also implement this function.

The previous section has already told you the use of Ctags, Ctags's basic principle is that some of the key words in the program (such as: function name, variable name, etc.), such as the name, location and other information through a window to tell you, if you have installed a good taglist, You can use the following command to see the TagList Help file:

: Help Taglist.txt

The following is my translation of the first paragraph of "Overview" for everyone to understand the taglist, translation is not good, please advise:

"Tab List" is a VIM used to browse the source code, this plugin allows you to efficiently browse the various languages written in the source code, "Tag list" has the following features:

* Display the tags (functions, classes, structs, definitions) in a file in a vertical or horizontal split window of vim.

variables, etc.)

* In the GUI vim, you can choose to display tags in the Drop-down menu and pop-up menu

* When you switch between multiple source files/buffers, the TagList window is automatically updated accordingly.

When you open a new file, tags that are defined in the new file are added to the list of existing files.

and tags that are defined in all files are grouped by file name.

* When you select a tag name in the TagList window, the cursor in the source file automatically jumps to the tag's set

Righteousness Office

* Automatically highlight the current tag name

* Group each tag by type and display each group in a collapsible tree structure

* Can display the original type and scope of tag

* In the TagList window you can choose to display the tag's original type instead of the tag name

* Tag list can be sorted by tag name, or time

* Source files that support the following languages: Assembly, ASP, Awk, Beta, C,

C + +, C #, Cobol, Eiffel, Erlang, Fortran, HTML, Java, Javascript, Lisp,

Lua, make, Pascal, Perl, PHP, Python, Rexx, Ruby, Scheme, Shell, slang,

SML, SQL, TCL, Verilog, Vim and YACC.

* Can be easily extended to support the new language. The modifications to the new language support are also simple.

* Provides functions that can be used to display the current tag name in the status bar of Vim or in the title bar of a window

* The list of files and tags in the taglist can be stored and loaded between VIM sessions

* Provides commands for obtaining the tag name and original type

* Can be used in console vim and GUI vim

* Can be used with the Winmanager plugin. The Winmanager plugin allows you to use a file browser at the same time

Buffer browser and TagList Plug-ins, just like an IDE.

* Can be used in UNIX and ms-windows systems

First, add the following sentences to your ~/.VIMRC file:

Copy Code code as follows:

Let tlist_show_one_file=1
Let Tlist_exit_onlywindow=1

At this time with vim open a C source file try:

Copy Code code as follows:

$ vim ~/VIM/SRC/MAIN.C

When you enter Vim, open the TagList window with the following command, as shown in Figure 5:

: tlist

(---Figure 5---)
The window on the left is the TagList window, which lists the tags in the main.c file and classifies them according to "typedef", "variable", "function", and so on. Move the cursor over the vimmain, like the red box on the left of the picture, and when you press ENTER, the source program automatically jumps to the definition of the vimmain, as in the red box on the right of the figure. This is the most basic and most commonly used operation of TagList. To teach you a common operation, when you browse the TagList window, if you do not want to let the source code jump, but want to see tag in the source code complete expression, you can move the cursor to see the tag, such as the top yellow box, and then press the space bar, in the following command line, such as the yellow box below the picture, will show the tag in the source code complete writing, and will not jump to the source code department.

TagList plugin I introduced here, in fact it has a lot of usage and settings, I can not one by one to teach you, fortunately TagList has a detailed help manual, with the following command to open the manual, to learn it:

: Help Taglist.txt

7. File Browser and window Manager--plugin: Winmanager

Download Address Http://www.vim.org/scripts/script.php?script_id=95
Version 2.x
Installation Unzip the winmanager.zip in the ~/.vim directory
Manual : Help Winmanager

In Figure 1 you can see that the icon 2 identifies a file browser, it lists the files in the current directory, you can use this browser to browse the project source files, is not more and more like the common IDE, when the cursor stops in a file or folder, press ENTER, you can open the file or folder .
How does this stuff come out? In fact, this is also implemented by Plug-ins, this plug-in is Netrw.vim, but you do not download and install, this plug-in is already a standard vim plug-in, has been installed with VIM into your system, now first a simple demonstration, into the "~/vim71" folder after running Vim, Then run the command in VIM:

: E ~/vim71
You will see an interface in Vim as shown in the following figure:

(---Figure 6---)
in this interface you can use some of the following commands for common directory and file operations:

<F1> Show Help
<cr> If the cursor is a directory, enter the directory; If the file is under the cursor, open the file
Return to Parent Directory
Toggle Vim The current working directory is browsing the directory
Create a table of contents
Delete a directory or file
Toggle display Mode
File or directory rename
Select a Sort method
Customize the browsing style and open the file using the program you specify

I'm not here to teach you how to use the Netrw.vim plugin, but to teach you to integrate taglist windows and NETRW windows with the Winmanager plugin, as shown in Figure 1, icons 2 and 3.
Now add the next two sentences to your ~/.VIMRC.

Copy Code code as follows:

Let g:winmanagerwindowlayout= ' fileexplorer| TagList '
Nmap wm:wmtoggle<cr>

Then restart Vim, open ~/vim71/src/main.c, and enter the "WM" in the normal state, and you will see Figure 7:

(---Figure 7---)
The top left is the netrw window, and the bottom left is the TagList window, and the two windows are closed when you re-enter the WM command.

Winmanager's main function is that I introduced these, but it has some other advanced features, but also can support a few other plug-ins, if you think I am not enough to introduce you to use, I suggest you to the Help manual for a good study, use the following command to bring up the help manual:

: Help Winmanager

8, the use of Cscope

This is even more powerful, with Cscope's own words-"You can think of it as a ctags of more than frequency", its function and strength can be seen, I will not elaborate on its introduction, if you have installed the previous Chinese help manual, use the following command to see the introduction bar:

: Help If_cscop.txt

I am here to simply excerpt a little, for those who are still hesitating to see:
Cscope is an interactive screen tool used to help you:
* There is no need to flip through the thick list of programs to understand how a C program works.
* No need to familiarize yourself with the entire program to know the location of the code to be modified for the bug.
* Examine the effect that a proposed change, such as adding an enumeration value, might have.
* Verify that all source files have been modified as needed, such as adding an argument to an existing function.
* Rename a global variable in all relevant source files.
* Change a constant to a preprocessing symbol in all relevant locations.

It is designed to answer the following questions:
* Where did you use this symbol?
* Where is this defined?
* Where is this variable assigned?
* Where is the definition of the global symbol?
* Where is this function in the source file?
* Which functions have called this function?
* What functions is called by this function?
* Where does the information "out of space" come from?
* Where is this source file located in the entire directory structure?
* Which files contain this header file?

Install Cscope:
If you have a cscope command in your system, you can skip this segment, and if not, then install one with me first.
On Cscope's homepage: http://cscope.sourceforge.net Download a source pack, unzip and compile the installation:

Copy Code code as follows:

# make
# make Install//requires root permission

First, add a sentence to the ~/VIMRC:

: Set cscopequickfix=s-,c-,d-,i-,t-,e-

This is the setting of whether to use the Quickfix window to display the Cscope results, as will be said later.

Like Ctags, to use its functionality, you must first generate a Cscope database for your code, running the following command at the root of the project:

$ cd/home/wooin/vim71/
# Three files will be generated thereafter
$ ll cscope.*
-rw-rw-r--1 wooin wooin 1.1M 2007-09-30 10:56 cscope.in.out
-rw-rw-r--1 wooin wooin 6.7M 2007-09-30 10:56 cscope.out
-rw-rw-r--1 wooin wooin 5.1M 2007-09-30 10:56 cscope.po.out
# Open the file and start coding
$ cd src
$ VI main.c

The first thing to get into Vim is to import the Cscope file that you just generated into VIM, using the following command:

: CS add/home/wooin/vim71/cscope.out/home/wooin/vim71

The above command is important, must be written in full, not only the first half of the sentence:

: CS Add/home/wooin/vim71/cscope.out

Because the source code is a multi-level directory, if this write, cscope can not be in the subdirectory of the source code work, of course, if your source code in the same level of the directory will not matter. If you want to use cscope often, add the above sentence to the ~/.VIMRC.

Let's drill down to find the definition of function vim_strsave (), using the command:

: CS Find G Vim_strsave
The following figure:

(---figure 8---)
When you press ENTER, you will automatically jump to the definition of Vim_strsave (). At this point you will certainly say Ctags can also do this ah, so the following said this ctags can not do, I would like to find Vim_strsave () in those places have been called, with the command:

: CS Find C Vim_strsave
When you press ENTER, Vim automatically jumps to the first match, and displays in the command bar the number of results that match the requirements, as shown in the figure:

(---Figure 9---)

If you are not satisfied with the position of the automatic jump, and want to see other results, you can open the Quickfix window with the following command:

: CW
As shown in figure:


Then you can pick the ^_^.

The main function of Cscope is realized by the same subcommand "find".
The use of "Cscope find":
CS Find C|d|e|f|g|i|s|t Name

0 or S Find this C symbol (you can skip annotations)
1 or G Find this definition
2 or D Find the function called by this function
3 or C Find functions that call this function
4 or T Find this string
6 or E Find this egrep mode
7 or F Find this file
8 or I Find files that contain this file

It's annoying to have to enter a long list of commands every time you look up, Cscope's help manual recommends the use of shortcuts, and here's one, which I use, add the following to ~/.VIMRC, and restart Vim:

Copy Code code as follows:

Nmap <c-_>s:cs Find S <c-r>=expand ("<cword>") <CR><CR>
Nmap <c-_>g:cs Find G <c-r>=expand ("<cword>") <CR><CR>
Nmap <c-_>c:cs Find C <c-r>=expand ("<cword>") <CR><CR>
Nmap <c-_>t:cs Find T <c-r>=expand ("<cword>") <CR><CR>
Nmap <c-_>e:cs Find e <c-r>=expand ("<cword>") <CR><CR>
Nmap <c-_>f:cs find F <c-r>=expand ("<cfile>") <CR><CR>
Nmap <c-_>i:cs Find I ^<c-r>=expand ("<cfile>") <CR>$<CR>
Nmap <c-_>d:cs Find D <c-r>=expand ("<cword>") <CR><CR>

When the cursor is over a word you are looking for, press <c-_>g to find the definition of the object.
Press this key combination has a bit of skill, press the <C-_> to immediately press a key, otherwise the screen flash back to Nomal state
The <c-_>g is to press "ctrl+shift+-" first and then press "G" again soon.

It is strange that this sentence:
Nmap <c-_>i:cs Find I ^<c-r>=expand ("<cfile>") <CR>$<CR>
I can't work in my vim, but I change it to:
Nmap <c-_>i:cs Find I <c-r>=expand ("<cfile>") <CR><CR>
Can work properly, do not know what is the reason? Any friend who knows, please tell me.

Other features of cscope you can learn by yourself through the Help manual

Reset: Reinitialize all connections.
Usage: CS Reset

9. QuickFix window

In Figure 10 in the previous section, you can see that there is a window below the window that displays the results of the query. This window lists query results for query commands, and users can select each result to view from this window, which is called the "QuickFix" window, which used to be a vim plugin, It's just a standard plug-in for VIM, you do not have to install, the main function of the Quickfix window is to see the function: Output some alternative results, can be many command calls, more detailed introduction and use of the following command to open the Quickfix manual to learn it:

: Help Quickfix
Here I have a common example to introduce a Quickfix window to use the method. This example is to imitate the usual when we are programming, when the compiler error, Quickfix will be the error of the information listed, for us to view and modify. First or use Vim to open ~/VIM71/SRC/MAIN.C, preferably first compiled vim71, or a bit slow to compile, or you can write a small have the wrong program to follow me to do the following steps, see the figure below:

We modified the MAIN.C, artificially causing several errors, adding a BAOBAO_WU without any defined string in line 1019th, deleting the last bracket in line 1020th, and compiling with the following command:

: Make
Obviously compiled will report a lot of errors, when the compile finished and exit to the source interface, just the compiler reported errors have not been seen, but we can use the Quickfix window to find out the error information, with the following command to pull out the Quickfix window:

: CW
You can now look at the Quickfix window as shown in the following figure:

In the Quickfix window below we can find every compilation error, also you can click each record with the mouse, the code will automatically jump to the error immediately, you can also use the following command to jump:

: CN//Switch to next result
: CP//Switch to previous result

If you use these two commands frequently, you can also set shortcuts to them, such as adding to the ~/.VIMRC:

Copy Code code as follows:

Nmap <F6>:cn<cr>
Nmap <F7>:cp<cr>

There are other commands/Plug-ins that will also use the Quickfix window, but the usage is basically similar, the Quickfix window will be used later in this article, then look down.

10. Fast browsing and operation Buffer--plugin: Minibufexplorer

Download Address http://www.vim.org/scripts/script.php?script_id=159
Version 6.3.2
Installation Drop the downloaded Minibufexpl.vim file into the ~/.vim/plugin folder
In the head of the Minibufexpl.vim file

In the programming can not always only edit a file, you will certainly open a lot of source files for editing, if each file open a vim to edit the words that operation will be much trouble ah, so vim has buffer (buffer) concept, can see the help of Vim:
: Help Buffer
Vim's own buffer management tools only: LS,: bnext,: bdelete, such as the command, not easy to use, but not intuitive. Now a grand recommendation to you a Vim plug-in (plugin): Minibufexplorer

How to use:
Restart Vim, when you only edit a buffer when minibufexplorer not useful, when you open the second buffer, the Minibufexplorer window automatically bounced out, see the following figure:

The long, narrow window above is the Minibufexplorer window, which lists all the currently open buffer, and when you place the cursor in the window, there are several shortcut keys available:

<Tab> Loop forward to each buffer name
<S-Tab> Loop backwards to each buffer name
<Enter> In the buffer at which the cursor is opened
D Delete the buffer where the cursor is located

The following two features need to be added to the ~/.VIMRC:

Let G:minibufexplmapctabswitchbufs = 1

<C-Tab> Loop forward to switch to each buffer, and open in the front window
<C-S-Tab> Loop backwards to each buffer and open in the front window

If you set the following sentence in ~/.VIMRC:

Let G:minibufexplmapwindownavvim = 1
You can use <C-h,j,k,l> to switch to the top and bottom window, like this:
C-w,h J K L to "left, down, up, right" toggle window.
Set in ~/.VIMRC:

Let G:minibufexplmapwindownavarrows = 1
is to use the <c-arrow keys > Switch to the top and bottom window.

11, c/h files to switch between--plug-in: A

Download Address Http://www.vim.org/scripts/script.php?script_id=31

Put A.vim in the ~/.vim/plugin folder

The following describes its usage:
As a C programmer, daily coding in the source file and the first file between the switch is a common thing, and directly with VIM open its source/header file is not really a problem, but only a key to switch over, this is how intimate function ah ....
After installing the A.vim, there are several commands you can use:

: A Switch to c/h file in new buffer
: As Split the window horizontally and open the c/h file
: AV Split the window vertically and open the c/h file
: at Create a new tab and open the c/h file

There are some other commands, you can see on its web page, I have not used, in fact, are similar to find their most comfortable on the line.

I added a phrase to the ~/.VIMRC:

Nnoremap <silent> <F12>:a<cr>

The meaning is to press F12 in a new buffer to open the c/h file, so that when the program can be written without hesitation in c/h file between the switch, reducing the number of keystrokes, the idea is more fluent, Amitabha ....

12. Find in Engineering--plugin: Grep

Download Address http://www.vim.org/scripts/script.php?script_id=311
Version 1.8
Installation Just drop the Grep.vim file in the ~/.vim/plugin folder.
In Grep.vim file head

The following describes its usage:
VIM has its own search function, but with the shell in the grep than there are some gaps, sometimes coding is too hectic, really want to press F3, the cursor is the word to a project-wide grep, do not knock on those cumbersome orders, now the gospel comes, and I am also lazy people a few , you can find some documentation in the front of the Grep.vim script:

: Grep Finds in the specified file according to the specified rules
: Rgrep Ditto, but it's recursive grep.
: Grepbuffer Find in all open buffers
: Bgrep Ditto
: Grepargs Find in Vim's argument filenames (: args)
: Fgrep Run Fgrep
: Rfgrep Run recursion Fgrep
: Egrep Run Egrep
: RegRep Run recursion Egrep
: Agrep Run Agrep
: Ragrep Run recursion Agrep

The command above is called like this:

: Grep [<grep_options>] [<search_pattern> [<file_name (s)]]
: Rgrep [<grep_options>] [<search_pattern> [<file_name (s)]]
: Fgrep [<grep_options>] [<search_pattern> [<file_name (s)]]
: Rfgrep [<grep_options>] [<search_pattern> [<file_name (s)]]
: Egrep [<grep_options>] [<search_pattern> [<file_name (s)]]
: RegRep [<grep_options>] [<search_pattern> [<file_name (s)]]
: Agrep [<grep_options>] [<search_pattern> [<file_name (s)]]
: Ragrep [<grep_options>] [<search_pattern> [<file_name (s)]]
: Grepbuffer [<grep_options>] [<search_pattern>]
: Bgrep [<grep_options>] [<search_pattern>]
: Grepargs [<grep_options>] [<search_pattern>]

But I never had to knock on the ^_^ of those commands, because I added the following sentence to the ~/.VIMRC:

Nnoremap <silent> <F3>:grep<cr>

For example, if you want to find "Feat_quickfix" in/HOME/WOOIN/VIM71/SRC/MAIN.C, move the cursor over "Feat_quickfix" and press the F3 key, as shown in the following figure:

Displayed at the bottom of the command line:

Search for Pattern:feat_quickfix
At this point you can also edit the line, grep supports regular expressions, you want to match the whole Word can be changed to:

Search for pattern:/<feat_quickfix/>
Then press ENTER:

Displayed at the bottom of the command line:

Search for Pattern:feat_quickfix
At this point you can also edit the line, grep supports regular expressions, you want to match the whole Word can be changed to:

Search for pattern:/<feat_quickfix/>
then press ENTER:

Displayed at the bottom of the command line:

Search in Files: *

is to ask you to search the scope, the default is the directory of all the files, at this time you can edit the line, such as you just want to search source files:

Search in Files: *.c *.h

Then, when you press ENTER, you will find all eligible search results in the pop-up Quickfix window, where you can look for the results you want, as shown in the following figure:


In fact, there are some other features and settings, but I have not used, these features plus regular expression, has been enough for me to use, the other you can look at the Web page of its documents, if there is anything amazing to remember with my exchange, common progress oh ....

13, highlighting the bookmark--plugin: Visualmark

Download Address http://www.vim.org/scripts/script.php?script_id=1026

Installation Just drop the Visualmark.vim file in the ~/.vim/plugin folder.

The following describes its usage:
Vim, like other editors, has a "bookmark" concept, called "Mark" in Vim, which can be viewed in the following order:

: Help Mark
The "bookmark" has a very big disadvantage: it is not visible.
The visual Mark plug-in I want to introduce below has nothing to do with the "Mark" in vim, not to make it visible, but to be "visible bookmarks" in itself, and then look down and see, in the author's words, "bookmarks like UltraEdit".
In addition, there is also the web to make vim in the mark visible plug-ins, but I tried, as if no visual mark useful, I will not introduce.

In accordance with the above method of installation of visual mark, you do not have to set up, if it is gvim, directly in the code pressed CTRL+F2, if it is vim, with "MM", how to find the cursor on the line to highlight the bar, see the following figure:

If you set up more than one bookmark, you can use the F2 key to toggle forward during the period, with SHIFT+F2 reverse during the period.
Okay, I'm done with visual mark, easy enough, ^_^.

If you think the color of the bookmark is not good-looking, you can also define it by yourself, but modify the source code of the plugin script, find and open the Visualmark.vim in the directory ~/.vim/plugin/, find the following section:

Copy Code code as follows:

if &bg = = "Dark"//depending on your background color style to set different bookmark colors
Highlight Signcolor ctermfg=white ctermbg=blue guifg=wheat Guibg=peru
else//main is to modify the value of the GUIBG to set the color of the bookmark
Highlight Signcolor ctermbg=white ctermfg=blue Guibg=grey guifg=royalblue3

I still have a few unsatisfactory places:
1 This bookmark can not be automatically saved, off Vim is gone.
2 Switch between different files when switching bookmarks, only in the same file

If any friend can solve these two problems, please tell me

14. Auto-complement

Friends who have used Microsoft Visual Studio must know the code completion function, enter an object name, and then type "." or "->", then its member names can be listed, so that coding fluent many, realize a lot of lazy dream, now I want to tell you, this is no longer a Microsoft Visual Studio patent, VIM can do! I will teach you the following, the function to tags file support, and is Ctags 5.6 version, you can look at the previous article tags file chapters.

The function I want to introduce here is called "new-omni-completion (full complement)", you can use the following command to look at the introduction:

Copy Code code as follows:

: Help New-omni-completion

You will also need to add the following two sentences to the ~/.VIMRC file:

Copy Code code as follows:

FileType plugin indent on

Open file type detection, add this sentence can be used to complete the intelligent

Copy Code code as follows:

Set Completeopt=longest,menu

Turn off the preview window when the smart fill is complete

Please make sure your ctags 5.6 has been installed, and the generated tags file can be used, then we have to copy the guy Open.
Open source file with vim

Copy Code code as follows:

$ vi/home/wooin/vim71/src/main.c

Set tags file

Copy Code code as follows:

: Set Tags=/home/wooin/vim71/tags

Find a random object with a member variable, such as "PARMP", enter insert mode, and place the cursor after "-&gt;",

Then press "Ctrl+x Ctrl+o", which will pop up with the following menu, showing all the matching labels, as shown below:

There are some shortcut keys available at this time:

Ctrl+p Toggle Members Forward
CTRL + N Toggle member Back
Ctrl+e Sign out of the dropdown window and return to the original input text
Ctrl+y Indicates exiting the Drop-down window and accepting the current option

If you add a few member variables, full complement can not immediately add new members, you need to regenerate tags file, but you do not need to restart Vim, just to regenerate the tags file on the line, then the full complement can be automatic completion, and really enough "almighty" bar.

Other complementary methods in Vim include:

Ctrl+x ctrl+l
Full line full complement
Ctrl+x CTRL + N Keyword completion based on current file
Ctrl+x ctrl+k Complete according to the dictionary
Ctrl+x ctrl+t Complement the thesaurus with a synonym dictionary
Ctrl+x Ctrl+i Keyword completion based on header file
Ctrl+x Ctrl +] Complete by label
Ctrl+x ctrl+f Complement full file name
Ctrl+x Ctrl+d Complement macro definition
Ctrl+x Ctrl + V Fill out the full vim command
Ctrl+x Ctrl+u User-defined complement method
Ctrl+x Ctrl+s Spelling suggestions

15, accelerate your completion--plugin: Supertab

Download Address http://www.vim.org/scripts/script.php?script_id=1643
Version 0.43
Installation Just drop the Supertab.vim file in the ~/.vim/plugin folder.
Supertab.vim file header, and command ": Supertabhelp"

In the above section you should learn the function of automatic complement code, press the "Ctrl+x Ctrl+o" is done, if you are lazy enough to say "so troublesome ah, actually to press four keys", do not have to blame, because Gergely Kontra and Eric Van dewoestine Also similar to you, but others developed the Supertab.vim this plug-in, can forever lazy down, I will teach you to lazy.

Add these two sentences to your ~/.VIMRC file:

Copy Code code as follows:

Let g:supertabretaincompletiontype=2
Let g:supertabdefaultcompletiontype= "<C-X><C-O>"

In the future when you are ready to press "Ctrl+x Ctrl+o" when the direct press &lt;Tab&gt;, good enough ....

Let me briefly introduce the above two sentences configuration information:

Copy Code code as follows:

Let g:supertabdefaultcompletiontype= "<C-X><C-O>"
"Set the default completion mode by pressing <Tab>, default is <c-p>
"Now change to <c-x><c-o>. About the complete method of <C-P>,
"There are other complementary ways in which you can look at some of the following help:
": Help Ins-completion
": Help Compl-omni

Copy Code code as follows:

Let g:supertabretaincompletiontype=2
"0-Do not record the last complement method
"1-remember the last complement until you change it with the other full command
"2-remember the last completion mode until you press ESC to exit insert mode

But now my <Tab> key is not good, I used to love the use of <Tab> for indentation, if the previous character pressed the <Tab> key will be completed, rather than I want the indentation function, I don't know if there is a shortcut key to temporarily turn off and activate the Supertab key function. If any friend knows, please be sure to tell me ah ....

Help poor children in uganda!

"To help poor Ugandan children."
Vim's author developed such a powerful, Easy-to-use editor, and is completely open source, completely free, do not know Burguez will not think this person is really unreasonable. The author's only expectation for user users is to help children in Uganda, who can use the command: Hlep KCC to view the details,

1. Donate to a primary school child: 17 euros per month (or more).
2. Donate to a secondary school child: 25 euros per month (or more).
3, Donation clinics: Monthly or quarterly, the amount is unlimited.
4, one-time donation.

Conditional on the funding for a while, no conditions like me to help publicize it, this is also regarded as open source spirit ...

Thank you brothers to join in, the picture on the Web page has been done, may have been free of time to the article will be upgraded, mainly to add some new plug-ins to use the introduction, if you have useful plug-ins can also recommend to me.
Do not know where there is room to upload the text for everyone to download, so as to avoid mail trouble.

Reply to everyone:

Deathmual@gmail.com published in 2007-10-31 11:55:36 ip:192.168.3.*
Collect a copy first, thank you, here can not see the picture, may be the company's network problem.
Sorry, my article problem, I have changed, you can see the picture

Duyanning published in 2007-10-31 12:02:19 ip:202.117.10.*
Can I debug a program in VIM?
This article describes the temporary not good, but there are some plug-ins can support GDB, I tried not to use,
I will keep my eye on it.

Dlwxn published in 2007-11-01 10:33:48 ip:211.143.246.*
and the hyperlink in front of you is wrong.
This article will teach you:
1. Installation of Chinese help manual
2. Vim Programming Common commands
file:///C:/Documents%20and%20Settings/Administrator/Desktop/programming_with_gvim_05.tar/programming_with_gvim_05/ Programming_with_gvim.html#2
Yes, I'll make time to change it later, I didn't expect the problem so much ... Everyone will see it first, sorry ^_^

Original: http://blog.csdn.net/wooin/article/details/1858917

Related Article

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.