Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Vi, if I am in the middle of a function, how can I navigate back to the function declaration?

share|improve this question

2 Answers 2

At the risk of stating the obvious, this may depend on the language and the coding style.  If the code is in C or C++ and the programmer followed the convention of beginning functions as

int
sum(int num1, int num2)
{

(or even with the return type on the same line as the function name), and then indenting all internal blocks, you could do a ?^{ search.  Alternatively (and this may be the best answer), [[ seems to be a shortcut for ?^{.  (]] seems to be a shortcut for /^{ –– no, not /^}.)

Even if the convention is

int sum(int num1, int num2) {

(consistently) you could search for ?^[a-zA-Z].*{$. For that matter, ?^[a-zA-Z] might be good enough.  Other languages, other coding conventions might require different answers.

share|improve this answer

I'd typically use {, which gets me to the beginning of the paragraph (which is often the beginning of the function too) in one keystroke, or sometimes I might have to use { two or more times, depending on how many blank lines I have in the function.

If I'm using C and ctags, then :tag functionname will get me to the function declaration from anywhere (Vim Book, p.79).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.