10

I'm currently using Visual Studio 2010 (and also have a copy of Visual Studio 2005 which I'm also happy to use if the functionality is available in it but not '10)

What I'm wondering is if there is any way to highlight pieces of code?

For instance, I'm currently working on an assignment to take a piece of code, and change the stack implementation. It would be really useful if I could highlight the stack implementation specific pieces of code so that it's easy for me to just glance at the screen and know which pieces need my attention rather than having to visually wade through it.

(I am using comments to highlight the stack implementation specific code - but they get a little lost amidst other comments - and this seems like a better idea.)

Eilidh
  • 1,354
  • 5
  • 21
  • 43

2 Answers2

8

You might consider using bookmarks at the start of a section you are interested in, or on a specific line. While this does not highlight the lines of code, it does provide a visual indicator in the left margin.

If you use the AllMargins extension, it also appears there. This is a handy way to quickly see if there any bookmarks in the current document, and also helps since the bookmark icon on the left will not appear in collapsed regions.

alt text

By using bookmarks, you can also use the bookmarks window to quickly navigate to the code you are interested in:

alt text

Jeff Ogata
  • 56,645
  • 19
  • 114
  • 127
  • 2
    It does strike me as very odd that you can't colour-highlight code though... – Eilidh Nov 20 '10 at 15:45
  • 3
    @ShimmerGeek, appreciate the checkmark, but I think it would be fair to give it to @Dean Taylor.... he did mention bookmarks in his answer before I posted mine. – Jeff Ogata Nov 20 '10 at 15:47
7

Consider using #region and #endregion blocks.

From MSDN:

#region lets you specify a block of code that you can expand or collapse when using the outlining feature of the Visual Studio Code Editor. In longer code files, it is convenient to be able to collapse or hide one or more regions so that you can focus on the part of the file that you are currently working on. The following example shows how to define a region:

#region MyClass definition
public class MyClass 
{
    static void Main() 
    {
    }
}
#endregion

For smaller sections / individual lines of code a quick way to jump between or keep track of them is to use Bookmarks. These can be added by using Ctrl+K, Ctrl+K and you can press Ctrl+K, Ctrl+N to move to the next bookmark, or Ctrl+K, CTRL+P for the previous bookmark. The Navigating Bookmarks article is a good quick reference.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Dean Taylor
  • 40,514
  • 3
  • 31
  • 50
  • 3
    No way to physically highlight it though? i.e. Make a line or two turn pink? – Eilidh Nov 20 '10 at 15:13
  • Any part big enough to be worth defining as a region is probably easier to find, it's when there's just a line or so or a tiny, tiny snippet that it's more of an issue. – Eilidh Nov 20 '10 at 15:14
  • 1
    You could always use bookmarks for those smaller sections, I have updated my answer to include this. – Dean Taylor Nov 20 '10 at 15:27
  • +1 for bookmarks :). You edited your answer while I was entering mine and I was going to delete it, but figured the bit about AllMargins was still useful. – Jeff Ogata Nov 20 '10 at 15:42
  • also I think it is time for someone to challenge the idea of the code editor - colors, "clouding", mind mapping - a bit more like working on a white board should be closer to how we need to work. – zzzuperfly Dec 11 '13 at 09:49