Many a times I have to deal with code files which are quite long - about 5 screen pages at the minimum. Almost always there is something towards the top/bottom that I need to refer when I'm at the bottom/top (respectively). It's a mammoth overhead to constantly scroll back-n-forth between the file parts.

It's a cognitive overload to just remember each and everything throughout the file and it's quite necessary to be able to refer to parts of the file.

Yes, the Outline view in some editors like Eclipse/NetBeans helps, but sometimes they will work well only for parts recognizable by that parser. Sometimes outline views don't show up e.g. when coding in CoffeeScript or JavaScript using closures/namespaced functions etc. The fallback is then just manual scroll overhead.

So as programmers what are some of the techniques/practices that can be employed to reduce this ridiculous overhead?

Yes, I can shorten the files, but specifically javascript libraries like Backbone.js etc. are all as one file since you really can't split them into multiple file due to lack of Java-like packages. So under the constraints of inability of splitting a file and the outline views not working, what are some of the techniques I can use to navigate through long source files? I work a lot on Eclipse/Netbeans and Aptana and sometimes Vi (but seldom in production environments). It'd be great to be able to split a window into two and see the same file on one side and code in the other. Not doable with Eclipse/NB/Aptana IMO. Vi, yes but can't use it all the time.

PS: As of now, I split the file among multiple editors e.g. Eclipse and Aptana. It'd be great to have it at one place, but is that the best that we can do? :)

UPDATE - Seems Eclipse has way for doing this and can be found here

  • 4
    Use a better IDE ;)
    – Oded
    Jul 21, 2012 at 20:45
  • I like the ones that are free - surely THIS is not a paid convenience :)
    – PhD
    Jul 21, 2012 at 20:50
  • 2
    You get what you pay for... And Visual Studio has free express editions. (unless you mean free as in Libre).
    – Oded
    Jul 21, 2012 at 20:55
  • 1
    The free versions of visual studio can minimize blocks of code (including functions), and can do splitpane, allowing you two view two sections of the same file at the same time. Jul 22, 2012 at 2:45
  • 1
    In NetBeans you can right-click on a window tab and select Clone. This will create a second window. You can then drag it elsewhere so that you can view different parts of the same file in different windows. Jul 24, 2012 at 23:44

5 Answers 5


So as programmers what are some of the techniques/practices that can be employed to reduce this ridiculous overhead?

under the constraints of inability of splitting a file and the outline views not working, what are some of the techniques I can use to navigate through long source files?

Open the file in several different editor windows (or different editors) - have each section of interest in a different window. If you, like many developers, have two or more monitors, you can put each window on a different monitor for reference.

I don't know about Eclipse/NB/Apatana, but Visual Studio has a split bar - this allows you to see several different portions of a file in one window. Perhaps your editor of choice has this feature as well.

  • 3
    Any IDE / editor without a horizontal split view is not worth using.
    – Matt S
    Jul 21, 2012 at 21:38

The most important thing to reduce this problem is to provide good abstractions for your methods. If you need to look at what Foo does everytime, then that is a good reason to refactor the code, to either rename the method, or break up the method into different ones. (Breaking up is useful when you have a complex control flow based on the input)

If you don't want to refactor, typically in visual studio I use goto definition and the back button on my mouse to navigate around to the various points. You might be able to use similar shortcuts in your IDE to avoid having to manually look around so much.

  • 1
    The OP specifically talks about source code that can't be broken up this way - open source library code, or languages that don't allow this kind of modularization.
    – Oded
    Jul 21, 2012 at 21:15
  • @Oded: I didn't say break up the files, I said break up the methods. Good method names will reduce the need to navigate to figure out what the method does. If your abstractions are good you can rely on them and reduce this kind of rubber necking of your code window.
    – Guvante
    Jul 23, 2012 at 22:30
  • No where did I mention files. And with open source, unless you are in a position to send patches back to the source, this can be very counter productive (you make your updates, then get the latest, overwriting your changes...). I agree that good naming helps, but not when you need to understand the subtleties.
    – Oded
    Jul 24, 2012 at 8:42
  • 1
    Oded: "languages that don't allow this kind of modularization". And my response was on the borderline of useful in this exact case, (since he obviously can't rename files from an OS file) however in general it is useful when dealing with these situations. Specifically, if your developers are complaining about navigating your internal codebase, it is time to refactor, while a neat IDE can help, and sometimes the exact definition is important, it is important to not ignore red flags like this.
    – Guvante
    Jul 24, 2012 at 14:22

Here's the rules which allows keeping files of 10kloc in size with 100 classes in each file in c++ code:

  1. Use emacs + esc-< + C-s for going to beginning of file and then searching a class by search words "class MyClass" and "::mymemberfunction". It requires remembering the name of the class or member function you want to find.
  2. notepad has the same feature in C-f
  3. other ides probably have ability to find text from single file which you have already open; going to beginning of file is more difficult to find...

I develop in Object Pascal/Delphi and once I came up with an idea (I called it Wident) for simplifying navigation in the long files. Basically it's about having a quick two-direction search of the identifiers at caret (I used Ctrl-Alt-[arrows]). You press for example Ctrl-Alt-Down, the tool detects the keyword at the caret pos and goes to the next mentioning of the keyword. Since after the jump your caret is placed at the same word only at different position, the next pressing will jump to the next reference (Ctrl-Alt is held so you just repeat pressing Down key). Although at this point you can be far away from your starting point, you can return to it easily. The caret is still at the name, so Ctrl-Alt-Up pressed twice will do the magic.

And this is just an example. Actually it's like quickly creating new dimensions in navigation while keeping full control of where you are. This works because the names of variables, functions, types and their references is what connects pieces of software semantically.

Although I use the tool developed for Delphi IDE, in other editors similar functionality can be implemented just by assigning new keys to the corresponding functions. For example, in notepad++ they are "Find (Volatile) Next" and "Find (Volatile) Previous".


Personally I rely on my memory. I remember the scroll bar position where I am looking at some important code. Ofcourse, you can only scroll to approximate location, but in most cases a PgUp / PgDown gets you right there. After a while, it becomes a habit.

You can easily remember about 4-5 scroll locations for a file. It would work great for files upto apprx. 2-3kloc. After that, the scroll bar would reach its minimum size and start losing its precision.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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