Is there any way to 'highlight' code? [duplicate]
Asked Answered
S

2

11

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.)

Scarron answered 20/11, 2010 at 14:59 Comment(0)
V
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.

Vicechancellor answered 20/11, 2010 at 15:7 Comment(5)
No way to physically highlight it though? i.e. Make a line or two turn pink?Scarron
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.Scarron
You could always use bookmarks for those smaller sections, I have updated my answer to include this.Vicechancellor
+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.Markusmarl
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.Genius
M
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

Markusmarl answered 20/11, 2010 at 15:34 Comment(2)
It does strike me as very odd that you can't colour-highlight code though...Scarron
@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.Markusmarl
V
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.

Vicechancellor answered 20/11, 2010 at 15:7 Comment(5)
No way to physically highlight it though? i.e. Make a line or two turn pink?Scarron
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.Scarron
You could always use bookmarks for those smaller sections, I have updated my answer to include this.Vicechancellor
+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.Markusmarl
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.Genius

© 2022 - 2024 — McMap. All rights reserved.