169

Why doesn't Visual Studio have any way of showing line numbers in a source file? Is there any way to enable it, or a plugin for it? I know that the number of lines of code in a program doesn't matter, but sometimes it is nice to know how long a program is or the number of a particular line for reference.

Though I tried, I can't seem to find a way to enable line numbering and I find that surprising.

This is Visual Studio 2010 Ultimate. (If you have read my older questions, I've been using 2008 Express until now.)

0

15 Answers 15

250

Visual Studio has line numbering:

Tools -> Options -> Text Editor -> All Languages -> check the "Line numbers" checkbox.

5
  • 4
    You should check "Show All Settings" check box at the bottom of options window to see "line number" check box Commented May 21, 2014 at 16:28
  • Still hidden for SCSS files?! Commented Nov 25, 2014 at 15:22
  • 6
    If the "Line numbers" check box is checked and you still don't see the lines, uncheck the check box, click OK, the go back to Tools -> Options -> Text Editor -> All Languages, now check the "Line numbers" check box again and the lines should appear.
    – TH Todorov
    Commented Jan 28, 2015 at 15:28
  • 2
    in VS 2017 my line numbers disappeared at some point, even though the tools/options check showed them selected. As @TH Todorov stated, I had to go back, uncheck, then recheck them and save for them to reappear. Commented Oct 4, 2017 at 18:49
  • In VS 2017 settings the square filled checkbox indicates partial application of a setting. It wasn't until I toggled the line numbers setting off and back on that it showed a normal checkmark and line numbers actually engaged for all languages. Commented Jan 24, 2022 at 17:06
46

As of Visual Studio 2015, you can find the option under:

Tools-> Options -> Text Editor -> All Languages-> General -> Line Numbers

Visual Studio 2013 Line Numbers Option Menu


Or simply go to tools -> options and type on the search bar: "Numbers".

1
  • I don't have a search bar in tools -> options menu. How can I make it appear? Commented Mar 31, 2017 at 11:25
25

Tools -> Options -> Show All Settings -> Text Editor -> All Languages -> Line Numbers

19

In Visual Studio 2013 & 2015 :

Tools -> Options -> Text Editor -> All Languages -> check Line Numbers enter image description here

0
8

It's not enabled by default but you can enable it by going to:

  1. Click Tools
  2. Options
  3. Text Editor (expand)
  4. All Languages
  5. Line Numbers (Checkbox)
  6. Click Ok

settings

7

Options -> Text Editor -> All Languages -> Line Number checkbox enter image description here

1
  • For my VS 2013, "Options..." was listed at the bottom of the "TOOLS" pull-down.
    – JohnH
    Commented Oct 21, 2021 at 12:22
5

In VS 2010:

Tools > Settings > Expert Settings

Then:

Tools > Options > Show all settings > Text editor > C# > General > Check Line Numbers (checkbox)

3

Visual studio 2015 enterprice

Tools -> Options -> Text Editor -> All Languages -> check Line Numbers

https://msdn.microsoft.com/en-us/library/ms165340.aspxenter image description here

1

Line numbers are not on by default. To turn on line numbers just go to Tools -> Options -> Text Editor -> All Languages -> General -> Display and check Line numbers:

http://blogs.msdn.com/blogfiles/zainnab/WindowsLiveWriter/TurnonLineNumbers_A5E7/image_thumb.png

1

For me, line numbers wouldn't appear in the editor until I added the option under both the "all languages" pane, and the language I was working under (C# etc)... screen capture showing editor options

1

Type 'line numbers' into the Quick Launch textbox (top right VS 2015), and it'll take you right where you need to be (tick Line Numbers checkbox).

0

For MS Visual Studio 2015 type "Text" in Quick Launch (Ctrl+Q) of top right corner. 1) quicklaunch

2) In the list select Text Editor->All Languages->General select_allLanguages

3) Now check on "Line Numbers" and click OK to get the line numbers.

Finally we get the line number in text editor.

1
  • You can also just type 'Line Numbers' in the quick launch to go directly to the right screen
    – asidis
    Commented Jan 2, 2019 at 15:31
0

In Visual Studio 2010 Express, there is an option called "Show all Settings". Located at "Tools > Options", window.

enter image description here

If this option is not checked, the line number option will not be available. Make sure this option is checked like shown below. This will make lot of additional settings visible in the tree view to the left.

enter image description here

Now this will make the option "Tools > Options > Text Editor > C# > General > Line Editor" available. Check the "Line Number" option to make line numbers visible on Visual Studio 2010 Express.

enter image description here

0

You should edit "settings.json". In that add, "editor.lineNumbers":"on", . You can check comments for various options you have.

In Visual Studio Code - 2017, you can also directly go to a given line number. There are following three ways to do that.

  1. Directly use keyboard shortcut - Ctrl + G.
  2. Under menu Go, use Go to Line - Go > Go to Line
  3. Search for Go to Line in Command Pallete (Cmd + Shift + P).
0

As other answers have already explained in length, you can enable line numbers by going into Tools -> Options ... clickety clickety click ... arriving at some page with an insanely large number of irrelevant options, scanning through them, finding a "Line Numbers" checkbox, and checking it. If you want to disable line numbers, it is clickety clickety click all over again.

Still as of 2024, Visual Studio does not offer a toolbar button or keyboard shortcut for toggling line numbers on or off.

This is particularly problematic since line numbers take up a non-negligible amount of screen real estate, which does not justify their (extremely limited) usefulness, so it is best to keep them hidden most of the time. Unfortunately, sometimes you need them, and then it is a pain to toggle them on and off.

The good news: you do not actually need line numbers.

Most people who have line numbers visible at all times do it due to one of the following reasons:

  • They are insecure without them. They almost never look at the actual numbers, but are used to them always being there, so if they are not there, they feel something is missing. (Same syndrome as editor tabs: they are useless, they waste screen real estate, and they require valuable time to keep curating them, but people feel they need them.)

  • They are using lame tooling which does not support double-click-to-go-to-source-line. For example, aspx web sites that show diagnostic stack traces in html. (Instead of logging the stack trace in the output window, using the same format as the compiler uses for error messages, so you can just double-click the log line in the output window and have visual studio show you the source code.)

How to live your life without line numbers:

  • Make sure that absolutely all of your logging goes to the output window of visual studio, and that it is in the exact same format as the compiler uses for error messages, so that each line in the output window can be double-clicked to take you to the right source file and line number. You should never be in a situation where you have to read a source filename and line number from the screen and manually find that source file and that line number.

  • In the exceedingly rare event that you do, nonetheless, have to find a particular source line by number, use the "Go to line" command. By default, this command is bound to Ctrl+G.

  • If you want to know which line you are at, either look at the information shown to the right of the horizontal scrollbar at the bottom of the text editor window, or press Ctrl+G again: the "Go to line" dialog has the current line already filled in.

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.