Tip 104Navigate Keyword Definitions with Vim’s Tag Navigation Commands

Vim’s ctags integration turns the keywords in our code into a kind of hyperlink, allowing us to jump rapidly to a definition. We’ll see how to use the Normal mode <C-]> and g<C-]> commands as well as their complementary Ex commands.

Jump to a Keyword Definition

Pressing <C-]> makes our cursor jump from the keyword under the cursor to the definition. Here it is in action:

KeystrokesBuffer Contents

{start}

 require './speaker.rb'
 class Anglophone < Speaker
  def speak
  puts "Hello, my name is #{@name}"
  end
 end
 Anglophone.new('Jack').speak

<C-]>

 require './speaker.rb'
 class Anglophone < Speaker
  def speak
  puts "Hello, my name is #{@name}"
  end
 end
 Anglophone.new('Jack').speak ...

Get Practical Vim, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.