Navigating code using PyDev

PyDev is an open source plugin which turns Eclipse into a resourceful Python IDE. It's a mature plugin and has been in active development for more than 12 years already!

It has features that are to be expected from most Eclipse language plugins, such as:

  • Code completion
  • Code analysis
  • Go to definition
  • Find References
  • Refactoring
  • Debugger
  • Tokens browser
  • Unittest integration

And a number of advanced features, which aren't so common, such as:

  • Interactive console
  • Type hinting
  • Remote debugger
  • Find Referrers in Debugger
  • Code coverage
  • Django integration

And more... (see the PyDev homepage for more details).

It's also one of the most used and downloaded plugins in the Eclipse Marketplace and is kept going through community contributions, crowdfunding campaigns and licenses from it's commercial counterpart (LiClipse, which is a PyDev standalone, plus other niceties).

Now, this article will focus in a single point on PyDev/Eclipse, which is navigating through a codebase, which is one of the main advantages of using an IDE. Below is an explanation on the best ways to get to the code you're interested in when coding in PyDev/Eclipse.

1. Any file in your workspace

The simplest way is searching for any resource for any project you have available (this is actually provided by Eclipse itself). So, if you know the file name (or at least part of it), use Ctrl+Shift+R and filter using the Open Resource dialog:

Find Resource

2. Any Python Token

Another way of getting to what you want is using the PyDev Globals Browser (using Ctrl+Shift+T).

This is probably one of the main ways to navigate the code as a single place can be used to filter for package names, classes, methods and attributes inside your own projects or any other package in Python itself. It also allows for advanced filtering, so you can search for tokens only inside a package (i.e.: dj.tz filters for any 'tz' token inside django in the example below).

Global Browser

3. Quick Outline (current editor)

Ctrl+O will show a Quick Outline which shows the structure of your current file. And pressing Ctrl+O one more time in this dialog will also show the structure of superclasses in the hierarchy (you can see that in the example below __setitem__ appears twice, once for the method in this class and another one for the superclass).

Quick Outline

4. Selection History

Go back and forth in your selection: Alt+Left goes to the place you were before and Alt+Right to the place you just came from... this allows you to easily navigate through the places you've recently visited.

History

5. Open files

To filter through the open files you can use Ctrl+E: a dropdown will appear and from there you can filter through its name. You can even close existing editors from this dropdown using Del.

Current

6. Go to previous next token (class or method)

Ctrl+Shift+Up and Ctrl+Shift+Down allows you to quickly navigate from your current position to the previous or next method (selecting the full method/class name).

Prev Next Method

7. Navigate through occurrences and errors in the file

Ctrl+Dot allows navigation through occurrences and errors found in the file. In the case below, we navigate through the occurrences of 'func'.

Occurences and Errors

8. Go to some view/menu/action/preference

This is an Eclipse standard mechanism: using Ctrl+3 allows you to navigate to any part of the IDE.

Preferences

9. References

Ctrl+Shift+G will create a search showing all the references to the token under the cursor (and the search view where results are shown can be navigated with Ctrl+Dot).

References

10. Go to definition

Just press F3 or Ctrl+Click an available token and go directly to the selected place.

11. Hierarchy View

Using F4 shows a hierarchy view. There you can see the structure of your classes.

Hierachy View

12. Show In

Alt+Shift+W allows you to see the current file in a given place (such as the PyDev Package Explorer or the System Explorer from your OS) or your current class/method in the Outline View.

Show In

Other Shortcuts

The shorcuts below are available in standard Eclipse, so you should also definitely get to know them :)

  • Ctrl+L allows you to navigate to a given line in your current editor.
  • Ctrl+Q goes to the place where the last edition was made.
  • Ctrl+F6 navigates through the opened editors. In LiClipse Ctrl+Tab is also bound to it by default-- and I suggest you also add this binding if you aren't using LiClipse :)
  • Ctrl+F7 navigates through opened views (i.e.: Package Explorer, Outline, etc.)
  • Ctrl+F8 navigates through opened perspectives (i.e.: PyDev perspective, Debug perspective, etc).
  • Ctrl+F10 opens the menu for the current view (so you can select filters in the Package Explorer, etc.)
  • F12 focuses the editor (so, you can go from any view to the editor)
  • Ctrl+H Opens the search dialog so you can do text searches
  • Ctrl+Shift+L twice goes to the keybindings preferences

Now you can enjoy going really fast to any place you wish inside PyDev!

About the Authors

Fabio Zadrozny

Fabio Zadrozny
Brainwy Software