*usr_29.txt*	 Vim version 6.2.   : 2002 Aug 14

		  VIM -  

			   


 Vim -- .  ,   Vim   ,
    :      
   ͣ,       , 
 ,       .

|29.1|	 
|29.2|	  
|29.3|	   
|29.4|	  ͣ
|29.5|	  ͣ

  : |usr_30.txt|   
 : |usr_28.txt|	
      : |usr_toc.txt|

==============================================================================
*29.1*	 

  ?    ,   . ,
      C  C++.    
     Vim  ,    
 , .. ,   ,   .
              
: >

	ctags *.c

"ctags"   .       
Unix-.      ,     Exuberant
ctags :

	http://ctags.sf.net ~

   Vim         
    : >

	:tag startlist

  ģ  "startlist",       .
    CTRL-]   ,  ,   
  .         C.
,     "write_block"  ,   
 "write_line".      "write_line"?  
   "write_line"   CTRL-],    
  .
    "write_line",   ,   "write_char". 
  ,    .  !  
    "write_char"   CTRL-].   
  "write_char".

	+-------------------------------------+
	|void write_block(char **s; int cnt)  |
	|{				      |
	|   int i;			      |
	|   for (i = 0; i < cnt; ++i)	      |
	|      write_line(s[i);		      |
	|}	    |			      |
	+-----------|-------------------------+
		    |
	     CTRL-] |
		    |	 +----------------------------+
		    +--> |void write_line(char *s)    |
			 |{			      |
			 |   while (*s != 0)	      |
			 |	write_char(*s++);     |
			 |}	  |		      |
			 +--------|-------------------+
				  |
			   CTRL-] |
				  |    +------------------------------------+
				  +--> |void write_char(char c)		    |
				       |{				    |
				       |    putchar((int)(unsigned char)c); |
				       |}				    |
				       +------------------------------------+

 ":tags"   ,    :

	:tags
	  #             .      ~
	  1  1 write_line	   8  write_block.c ~
	  2  1 write_char	   7  write_line.c ~
	> ~
>
 Σ .  CTRL-T    .  
  Σ   "write_line",    "write_char".
       -,   
   .      
"ң".   >

	:tag

    .     
  ,    ң, 
 . , ":3tag".   ,    
 CTRL-T.
    ,         
 CTRL-],     CTRL-T.  ":tags"  ,
     .


 

 ":tag"  ,      , , 
  .  ,       
 ,    , ,       ?
       ":split"   
 ":tag".  Vim       : >

	:stag _

 ,        ,  
,   >

	CTRL-W ]

      -,   
     .


  

      ,     
    . Vim       
.
    Vim       ,  
'tags' ,  Vim     . : >

	:set tags=./tags,./../tags,./*/tags

        ,   
,    ,         
.
        ,  Vim     
   . ,     
"~/proj/src",        "~/proj/sub/tags",  
 : >

	:set tags=~/proj/**/tags


  

   Vim      ,  
         . 
      Exuberant ctags.    
   : >

	cd ~/proj
	ctags -R .

  Exuberant ctags   ,   
   .     
  ctags.
         ,    
: >
    
	:set tags=~/proj/tags


 

     (  ̣  
),   ":tag"     .   
   ,   ģ    .
      ,      ,
   >

	:tnext

       .  
  ,     >

	:tselect _

   Vim     :

	  #                  ~
	  1 F	f    mch_init	       os_amiga.c ~
		       mch_init() ~
	  2 F	f    mch_init	       os_mac.c ~
		       mch_init() ~
	  3 F	f    mch_init	       os_msdos.c ~
		       mch_init(void) ~
	  4 F	f    mch_init	       os_riscos.c ~
		       mch_init() ~
	    ( <CR>  ):  ~

     (   ) ,   
  .       
  ,    .

         
:

	:tfirst			   
	:[]tprevious	  []  
	:[]tnext		  []  
	:tlast			   

 []  ,  ,    1.


  

     ,   
  .      
  <Tab>: >

	:tag write_<Tab>

     .      
,   ,     <Tab>  
 ,  .
         .     
 ,  ͣ  .     
 Vim      .
   , ,      ,   
 "block".     >

	:tag /block

    :  <Tab>. Vim  ģ
 ,   "block"    .
   "/"     ,     
 ,    .     
. ,     ,    
"write_": >

	:tselect /^write_

"^"    .        
 ,   "write"    . , "$"
    ,     
.


 

 CTRL-]     ,   ,
     ͣ    . ģ
.
    ,   ͣ (  Exuberant ctags): >

	ctags --c-types=f -f functions *.c

  Vim        
   ̣ : >

	vim
	:vsplit functions

     ,    
,    .    ,
  ":set ts=99".
        : >

	:nmap <buffer> <CR> 0ye<C-W>w:tag <C-R>"<CR>

    ,       
<Enter>. Vim       .


 

        ,  
'ignorecase'.

 'tagbsearch'  ,    
  ,   .   , 
 ,       ,
   ,     ,    
.

 'taglength'    ,   
  .

    SNiFF+,   Vim    
, . |sniff|. SNiFF+   .

Cscope   ,      ,
     ,    ,   . .
|cscope|.

==============================================================================
*29.2*	  

       ,  
 .  ,    ,
    .    
   .  ,     
   .       
 . 
          
"write_char": >

	:ptag write_char

Vim       "write_char".  ,  
Σ          
     CTRL-W.
        ,   ţ   
   : >

	CTRL-W }

 ,     , 
     . . |CursorHold-|

   ,  : >

	:pclose

        , 
 ":pedit".        
, : >

	:pedit defs.h

 ,     ":psearch"    
     ޣ ,     
.       ,
         .  : >

	:psearch popen

       "stdio.h"   
popen():

	FILE	*popen __P((const char *, const char *)); ~

        .  
   'previewheight'.

==============================================================================
*29.3*	   

     ,  Vim 
   .     
   .
      C     :

	#ifdef USE_POPEN ~
	    fd = popen("ls", "r") ~
	#else ~
	    fd = fopen("tmp", "w") ~
	#endif ~

      ;  , 
      .    "#ifdef" 
 %. Vim ģ    "#else".    % 
  "#endif".    %     
"#ifdef".
          ,  Vim ģ
 .       
"#if".
      -  "#if" - "#endif",     
      >

	[#

     -  "#if"  "#ifdef",  Vim
  .     "#else"  "#endif"
 >

	]#

       "#if" - "#endif". :
Example:

	#if defined(HAS_INC_H) ~
	    a = a + inc(); ~
	# ifdef USE_THEME ~
	    a += 3; ~
	# endif ~
	    set_width(a); ~

       ,  "[#" 
   .  "#ifdef" - "#endif"    
.


    

  C     .    
  .       
 "[[".  "]]"    .   ,
 "{"  "}"    .
    "[{"      .  
  {},    . "]}"   
 .
    ,      :

			function(int a)
	   +->		{
	   |		    if (a)
	   |	   +->	    {
	[[ |	   |		for (;;)	       --+
	   |	   |	  +->	{			 |
	   |	[{ |	  |	    foo(32);		 |     --+
	   |	   |   [{ |	    if (bar(a))  --+	 | ]}	 |
	   +--	   |	  +--		break;	   | ]}  |	 |
		   |		}		 <-+	 |	 | ]]
		   +--		foobar(a)		 |	 |
			    }			       <-+	 |
			}				       <-+

    C++  Java,   {}  .
   {}   .     
      "[m",   "]m"
   .

 , "[]"      ,  "][" 
 ң   .     "}",
   .

				int func1(void)
				{
					return 1;
		  +---------->  }
		  |
	      []  |		int func2(void)
		  |	   +->	{
		  |    [[  |		if (flag)
	start	  +--	   +--			return flag;
		  |    ][  |		return 2;
		  |	   +->	}
	      ]]  |
		  |		int func3(void)
		  +---------->	{
					return 3;
				}

 ,        "%"  
   (), {}  [].     ,
         .


    

 "[("  "])"   ,   "[{"  "]}",   , 
       ()   {}.
>
				  [(
<		    <--------------------------------
			      <-------
		if (a == b && (c == d || (e > f)) && x > y) ~
				  -------------->
			  --------------------------------> >
				       ])

  

        "[/". 
 ң      "]/".  
     /* - */.

	  +->	  +-> /*
	  |    [/ |    *               --+
       [/ |	  +--  *  . 	     | ]/
	  |	       */		           <-+
	  |
	  +--	       foo = bar * 3;	           --+
						     | ]/
		       /*   */  <-+

==============================================================================
*29.4*	  ͣ

,      C    
    . "int"  "unsigned"?  
  --   "[I".
   ,     "column". : >

	[I

Vim      ,   , ޣ   
 ,    ,      (   ,
   ޣ ,  ..).   
:

	structs.h ~
	 1:   29     unsigned     column;    /* column number */ ~

        
   ,    ģ  ޣ . 
     ,      
    .  ,     
,      ,    
    ޣ . 
   ,    ,    
 .  ,  'include'  ,  
 .       C  C++. 
 , , ģ    .


   ?

   Vim   ޣ   ,    'path'.
         ,   ޣ
    .   ,   , 
  >

	:checkpath

    ޣ ,   , 
,     .   :

	--- ޣ      --- ~
	<io.h> ~
	vim.h --> ~
	  <functions.h> ~
	  <clib/exec_protos.h> ~

 "io.h" ޣ   ,   . "vim.h" , 
 ":checkpath"  , ޣ   ,  , 
    "functions.h"  "clib/exec_protos.h".

	:
	Vim   .    "#ifdef"   ޣ
	,     "#include",   ,
	       "#if NEVER".

 ,   ,     
'path'.   ϣ Makefile,      
 ,       "-I", 
"-I/usr/local/X11".    ,  : >

	:set path+=/usr/local/X11

  ,      "*". : >

	:set path+=/usr/*/include

      "/usr/local/include",   
"/usr/X11/include".

   ,       
,    "**".      
. : >

	:set path+=/projects/invent/**/include

      , :

	/projects/invent/include ~
	/projects/invent/main/include ~
	/projects/invent/main/os/include ~
	 ..

     .  
     'path'.
      ,     ,  
: >

	:checkpath!

   ޣ , , ,  . 
  , Vim   ,    
 "(   )".


    

"[I"  ,     . 
     ,      
>
	[<Tab>

     "[ CTRL-I",  CTRL-I  <Tab> 
   .

,    "[I",  ,    
 .      ,    
  ,       : >

	3[<Tab>

       .  ,  
     CTRL-O.


 

	[i		   
	]I		  ,   
			     
	]i		      


  #define

 "[I"   .      "#define",
  >

	[D

       ޣ .  
     'define',   
     C/C++.
   ,   "[D":

	[d		   
	]D		  ,   
			     
	]d		      

==============================================================================
*29.5*	  ͣ

 "[I"    ޣ .     
      ,    ,
  ,  : >

	gD

     ("Goto Definition").    
    ,   C -- "".
ģ  (    "counter"):

	   +->   static int counter = 0;
	   |
	   |     int get_counter(void)
	gD |     {
	   |	     ++counter;
	   +--	     return counter;
		 }

         
,   : >

	gd

           
     .   ,  
         "{"  
,        . ģ  (
 "idx"):

		int find_entry(char *name)
		{
	   +->	    int idx;
	   |
	gd |	    for (idx = 0; idx < table_len; ++idx)
	   |		if (strcmp(table[idx].name, name) == 0)
	   +--		    return idx;
		}

==============================================================================

 : |usr_30.txt|   
 : . |___|  

vim:tw=78:ts=8:ft=help:norl:
