Step 4 of 7

Go to definition

Go to definition

Lesson 15 listed gd among the goto-mode commands with a note that it needed a language server. Now there is one:

  • gd — jump to the definition of the symbol under the cursor
  • gr — list every reference to it in a picker
  • gy — jump to its type definition

All three ask the server, and a real one answers across files and across dependencies; gd on a call from a library takes you into that library’s source. The stand-in here only knows this buffer, so it finds the fn line that defines the name.

Every one of these jumps records where you were, so Ctrl-o brings you back and Ctrl-i takes you forward again — the jumplist from lesson 15 works the same way for jumps a server made.

Below, go from each call in main to the function it calls.

  1. Put the cursor on the greet call in line 8 8gg — the server looks at the next word on the line.
  2. Jump to its definition with gd The cursor lands on fn greet, line 1.
  3. Come back with Ctrl-o A definition jump is a jumplist entry like any other.
  4. Now jump to the definition of farewell from its call in line 9 Move down a line, then gd again.
Put the cursor on the greet call in line 8 8gg — the server looks at the next word on the line.

Next: Jump to its definition with gd

Loading editor…