In visual studio it \'s easier to push F12 button to jump to a declaration of a function or variable when editing C/C++ code.
Is there a short-cut key in emacs to do th
There are multiple ways to do this. As darioo mentioned, Ctags is one, but it goes to the definition by default (which might work for you). Looking further, though, you can see that prefixing M-.
(ie, C-u M-.
) will take you to the next tag match (which is often the declaration). There is also a --declarations
option, but Exuberant Ctags doesn't seem to support it.
CEDET is another option, but in my experience, it's still not ready for production. Often times in C++ semantic-ia-fast-jump
will go to forward declarations instead of the definition or the declaration.
As others have said there is no built-in universal solution for this in emacs. That said, after having this functionality in IntelliJ I wanted it in emacs too so I made Dumb Jump.
Right now Dumb Jump has basic support for:
It's available via MELPA and is actively being developed.
Well, it's a bit more involved than that.
By default, Emacs doesn't "know" about function declarations for C or C++ code. First, obtain Exuberant Ctags. Then, use command etags
(ctags for Emacs) on your source code. A file named TAGS
will be generated.
Then, while editing your source code, when you want to jump to a declaration, press M-. (meta and dot, or alt and dot on modern keyboards). At first, Emacs will ask you for location of your tags file. Point it to the one you generated and afterwards navigation will be automatic.
I'd suggest reading Emacswiki article about tags for a better understanding of this functionality.
The newest version of Emacs (23.2) comes with CEDET integrated, which has more advanced features for C and C++ navigation, but it can be a bit difficult to set up right, so read more about it if you're interested.
M-. key will take you to the function definition emacs.