vim+ctags use

Vim+ctags uses_tiefanhe's blog-CSDN blog

To install Ctags under Ubuntu, just use apt-get install ctags

To use ctags proficiently, you only need to remember the following seven commands:

 

    1. $ ctags–R * ($ is the Linux system Shell prompt)
      2. $ vi –t tag (please replace tag with the variable or function name you want to find)
      3. :ts (ts mnemonic: tags list, the command starting with “:” is the command line mode command in VI)
      4. :tp (tp mnemonic: tags preview); This command is not commonly used, so you don’t need to remember it.
      5. :tn (tn mnemonic: tags next); This command is not commonly used, so you don’t need to remember it.
      6. Ctrl +]
      7. Ctrl + T

Let’s explain the above commands one by one:

      “$ ctags –R *”:
              “-R” means recursive creation, which includes all subdirectories under the source code root directory (current directory). "*" indicates all files. This
      command will generate a "tags" file in the current directory. When the user runs vi in ​​the current directory, this tags file will be automatically loaded.
              The Tags file contains a list of these objects:                       macro enumeration variables
                      defined with #define definitions of value                       functions, prototypes and declarations                       namespace                       type definitions (typedefs)




                      Variables (including definitions and declarations)
                      , classes, structures, enumerations, and unions.
                      Member variables or functions in classes, structures, and unions.
              VIM uses this "tags" file to locate the above. marked object.

        The remaining commands are ways to locate these objects:

        "$ vi –t tag": Add the "-t" parameter when running vim
                    . For example: [/usr/src]$ vim -t main
                    This command will open the definition " main" (variable or function or other) file and position the cursor on this line.
       
        If this variable or function is defined in multiple places, the ":ts" command in VI command line mode can list a list for the user to select.

        ":tp" marks the file with the previous tag, and ":tn" marks the file with the next tag. Of course, if there is only one variable or function name that the user is looking for in the current tags file, the ":tp,:tn" command is not available.

        The most convenient way is to move the cursor to the variable name or function name, and then press "Ctrl+]", so that you can jump directly to the
source file where the variable or function is defined, and position the cursor on this line. Use "Ctrl+t" to return to the original place. Even if the user uses "Ctrl+]" N times to find N variables, pressing "Ctrl+t" N times can return to the originally opened file, and it will return along the original path.

        Note: When running vim, you must run it in the directory where the "tags" file is located. Otherwise, when running vim, you must use the ":settags=" command to set the path of the "tags" file so that vim can find the "tags" file. When completing the encoding, the tags file can be deleted manually.

        Note: In addition, under Windows, gvim can be used, and ctags can also be used. This ctags can be copied from the directory of other software packages. For example, ultraedit comes with a ctags program. You can copy it directly to the vim directory under the gvim directory.

 

Guess you like

Origin blog.csdn.net/sinat_30603081/article/details/132420771