Loading ...
Sorry, an error occurred while loading the content.

Re: Finding prototypes in header files

Expand Messages
  • Aaron Griffin
    ... That s what ctags was made for. Take a look at exuberant-ctags and :help tags
    Message 1 of 7 , Feb 1, 2006
    View Source
    • 0 Attachment
      On 2/1/06, Ernest Obusek <eobusek@...> wrote:
      > Is there a direct way to go from a function in a file to its
      > prototype in a header file? The header file is in the vim path.

      That's what ctags was made for. Take a look at exuberant-ctags and :help tags
    • Justin Randall
      Try using Exuberant Ctags http://ctags.sourceforge.net/ to make a tags file that you can follow inside of VIM. You need to make sure that the vim path has the
      Message 2 of 7 , Feb 1, 2006
      View Source
      • 0 Attachment
        Try using Exuberant Ctags http://ctags.sourceforge.net/ to make a tags file that you can
        follow inside of VIM. You need to make sure that the vim path has the tags file in it.

        To make a tags file with ctags, type the following command in a terminal from the
        top-level directory where your project source is.

        find . \( -name '*.h' -o -name '*.cpp' \) | ctags -L -

        This should find all of the .cpp and .h files that are in your source and construct the
        tags file from them. After that is done, you should be able to open up any C++ file with
        VIM and navigate through the code (go from a function to it's prototype, and more) simply
        by pressing Ctrl-] (Control and the close bracket key) while your cursor is on the
        function name. You could also navigate through the codebase in a number of ways. In the
        the discussion below the code you wish to jump to will be denoted as "THE_TAG".

        1. while the cursor is on the THE_TAG: "g ctrl ]"
        2. ":ts THE_TAG" or ":tselect THE_TAG"
        3. ":sts THE_TAG"
        4. while the cursor is on the THE_TAG: "ctrl ]"
        5. ":ta THE_TAG" or ":tag THE_TAG"
        6. ":sta THE_TAG"
        7. "ctrl t" takes you back to the point before your last jump.


        Numbers 1,2,3 all prompt you to choose among multiple tag matches.
        Numbers 4,5,6 all jump to the first of the possibly multiple tag matches.
        Numbers 1 and 4 are used in "vim normal mode". Numbers 2 and 5 have the prefix ":" which
        switches to command mode in vim. Numbers 3 and 6 are the same as 2 and 5 except a new
        window will be split off containing the code you just jumped to.

        You will want to make a few changes to your .vimrc or .gvimrc so that that things work
        seamlessly.

        * set tags=./tags, OTHER_TAG_FILES
        * set autosave

        Good luck,
        Justin

        --- Ernest Obusek <eobusek@...> wrote:

        > Is there a direct way to go from a function in a file to its
        > prototype in a header file? The header file is in the vim path.
        >
        > Thanks,
        >
        > Ernest
        >
        >


        __________________________________________________
        Do You Yahoo!?
        Tired of spam? Yahoo! Mail has the best spam protection around
        http://mail.yahoo.com
      • Justin Randall
        You re right Russell, ctags -R works just as well. I should RTFM. Thanks. ... __________________________________________________ Do You Yahoo!? Tired of spam?
        Message 3 of 7 , Feb 1, 2006
        View Source
        • 0 Attachment
          You're right Russell, ctags -R works just as well. I should RTFM. Thanks.

          --- Russell Bateman <russ@...> wrote:

          > I have a slightly different take on this and so, my two cents...
          >
          > More easily than Justin's command is, unless I'm mistaken or lacking the
          > whole picture, ...
          >
          > ctags -R
          >
          > from the root of your source tree will do the trick. Now, you need to
          > make certain you don't have any old tag files haunting your
          > subdirectories too, so delete them. You end up with one mother tag file.
          > In .vimrc (or _vimrc if under Windows), ensure the line
          >
          > set tags=tags;
          >
          > This will make it so that Vim, not finding any local tags file, will
          > look back up the directory tree until it finds the one dominating
          > it--your new tags file.
          >
          > I'd appreciate hearing if something I'm doing leaves me in a lurch
          > somewhere. It's worked okay for me, but maybe there's some benefit to
          > Jason's method that I'm missing out on and not realizing.
          >
          > Regards,
          >
          > Russ Bateman
          >
          > Justin Randall wrote:
          > > Try using Exuberant Ctags http://ctags.sourceforge.net/ to make a tags file that you
          > can
          > > follow inside of VIM. You need to make sure that the vim path has the tags file in
          > it.
          > >
          > > To make a tags file with ctags, type the following command in a terminal from the
          > > top-level directory where your project source is.
          > >
          > > find . \( -name '*.h' -o -name '*.cpp' \) | ctags -L -
          > >
          > > This should find all of the .cpp and .h files that are in your source and construct
          > the
          > > tags file from them. After that is done, you should be able to open up any C++ file
          > with
          > > VIM and navigate through the code (go from a function to it's prototype, and more)
          > simply
          > > by pressing Ctrl-] (Control and the close bracket key) while your cursor is on the
          > > function name. You could also navigate through the codebase in a number of ways. In
          > the
          > > the discussion below the code you wish to jump to will be denoted as "THE_TAG".
          > >
          > > 1. while the cursor is on the THE_TAG: "g ctrl ]"
          > > 2. ":ts THE_TAG" or ":tselect THE_TAG"
          > > 3. ":sts THE_TAG"
          > > 4. while the cursor is on the THE_TAG: "ctrl ]"
          > > 5. ":ta THE_TAG" or ":tag THE_TAG"
          > > 6. ":sta THE_TAG"
          > > 7. "ctrl t" takes you back to the point before your last jump.
          > >
          > >
          > > Numbers 1,2,3 all prompt you to choose among multiple tag matches.
          > > Numbers 4,5,6 all jump to the first of the possibly multiple tag matches.
          > > Numbers 1 and 4 are used in "vim normal mode". Numbers 2 and 5 have the prefix ":"
          > which
          > > switches to command mode in vim. Numbers 3 and 6 are the same as 2 and 5 except a new
          > > window will be split off containing the code you just jumped to.
          > >
          > > You will want to make a few changes to your .vimrc or .gvimrc so that that things
          > work
          > > seamlessly.
          > >
          > > * set tags=./tags, OTHER_TAG_FILES
          > > * set autosave
          > >
          > > Good luck,
          > > Justin
          > >
          > > --- Ernest Obusek <eobusek@...> wrote:
          > >
          > >
          > >> Is there a direct way to go from a function in a file to its
          > >> prototype in a header file? The header file is in the vim path.
          > >>
          > >> Thanks,
          > >>
          > >> Ernest
          > >>
          > >>
          > >>
          > >
          > >
          > > __________________________________________________
          > > Do You Yahoo!?
          > > Tired of spam? Yahoo! Mail has the best spam protection around
          > > http://mail.yahoo.com
          > >
          > >
          > >
          >


          __________________________________________________
          Do You Yahoo!?
          Tired of spam? Yahoo! Mail has the best spam protection around
          http://mail.yahoo.com
        • Ernest Obusek
          Thank you all for your help. I have already been using ctags, but you gave me some ideas on how to use it better. However I still can t figure out how to get
          Message 4 of 7 , Feb 1, 2006
          View Source
          • 0 Attachment
            Thank you all for your help. I have already been using ctags, but
            you gave me some ideas on how to use it better. However I still
            can't figure out how to get to a prototype in a header file. When I
            used ctrl-] on a function name in a cpp file, it takes me to the
            implementation of the function, which is great. But I also want to
            have a way to jump to the prototype in the header file. If I do :ts
            after this it doesn't show any additional matches.

            Thanks,

            Ernest
          • Yegappan Lakshmanan
            Hi, ... If all your prototypes are in header files or placed at the beginning of the source file, then you can use [ command (which is same as [ )
            Message 5 of 7 , Feb 1, 2006
            View Source
            • 0 Attachment
              Hi,

              On 2/1/06, Ernest Obusek <eobusek@...> wrote:
              > Thank you all for your help. I have already been using ctags, but
              > you gave me some ideas on how to use it better. However I still
              > can't figure out how to get to a prototype in a header file. When I
              > used ctrl-] on a function name in a cpp file, it takes me to the
              > implementation of the function, which is great. But I also want to
              > have a way to jump to the prototype in the header file. If I do :ts
              > after this it doesn't show any additional matches.
              >

              If all your prototypes are in header files or placed at the beginning
              of the source file, then you can use [<CTRL-I> command (which is
              same as [<Tab>) to jump to the prototype. Note that this may not
              work in all the cases.

              :help [_CTRL-I

              - Yegappan
            • Yegappan Lakshmanan
              Hi Russell, ... You can use the CTRL-O key to jump back to the previous file position. ... - Yegappan
              Message 6 of 7 , Feb 1, 2006
              View Source
              • 0 Attachment
                Hi Russell,

                On 2/1/06, Russell Bateman <russ@...> wrote:
                > Yegappan,
                >
                > Of course, ^T (ctrl-t) doesn't take you back to whence you came. I do a
                > :e#. Is there an alternative? How do personally you get back to where you
                > started?
                >

                You can use the CTRL-O key to jump back to the previous file position.

                :help jumplist

                - Yegappan

                > Russ
                >
                >
                > Yegappan Lakshmanan wrote:
                > Hi,
                >
                > On 2/1/06, Ernest Obusek <eobusek@...> wrote:
                >
                >
                > Thank you all for your help. I have already been using ctags, but
                > you gave me some ideas on how to use it better. However I still
                > can't figure out how to get to a prototype in a header file. When I
                > used ctrl-] on a function name in a cpp file, it takes me to the
                > implementation of the function, which is great. But I also want to
                > have a way to jump to the prototype in the header file. If I do :ts
                > after this it doesn't show any additional matches.
                >
                >
                > If all your prototypes are in header files or placed at the beginning
                > of the source file, then you can use [<CTRL-I> command (which is
                > same as [<Tab>) to jump to the prototype. Note that this may not
                > work in all the cases.
                >
                > :help [_CTRL-I
                >
                > - Yegappan
                >
                >
                >
                >
              Your message has been successfully submitted and would be delivered to recipients shortly.