在 Visual Studio 中启用行号显示
为什么 Visual Studio 没有办法显示源文件中的行号?有什么方法可以启用它,或者有插件吗?我知道程序中的代码行数并不重要,但有时了解程序的长度或特定行的行数以供参考是很好的。
尽管我尝试过,但我似乎找不到启用行编号的方法,这让我感到惊讶。
这是 Visual Studio 2010 Ultimate。 (如果您已阅读我之前的问题,那么到目前为止我一直在使用 2008 Express。)
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.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
Visual Studio 有行编号:
工具 ->选项->文本编辑器 ->所有语言 ->选中“行号”复选框。
Visual Studio has line numbering:
Tools -> Options -> Text Editor -> All Languages -> check the "Line numbers" checkbox.
从 Visual Studio 2015 开始,您可以在以下位置找到该选项:
Tools->选项->文本编辑器 ->所有语言->一般->行号
或者直接转到
tools ->;选项
并在搜索栏上输入:“数字”。As of Visual Studio 2015, you can find the option under:
Tools-> Options -> Text Editor -> All Languages-> General -> Line Numbers
Or simply go to
tools -> options
and type on the search bar: "Numbers".工具->选项->显示所有设置 ->文本编辑器 ->所有语言 ->行号
Tools -> Options -> Show All Settings -> Text Editor -> All Languages -> Line Numbers
在 Visual Studio 2013 中2015:
工具->选项->文本编辑器 ->所有语言 ->检查行号

In Visual Studio 2013 & 2015 :
Tools -> Options -> Text Editor -> All Languages -> check Line Numbers

默认情况下未启用它,但您可以通过以下方式启用它:
设置
It's not enabled by default but you can enable it by going to:
settings
选项->文本编辑器 ->所有语言 ->行号复选框

Options -> Text Editor -> All Languages -> Line Number checkbox

在 VS 2010 中:
工具 >设置>专家设置
然后:
工具>选项>显示所有设置>文本编辑器> C#>一般>检查行号(复选框)
In VS 2010:
Tools > Settings > Expert Settings
Then:
Tools > Options > Show all settings > Text editor > C# > General > Check Line Numbers (checkbox)
Visual studio 2015企业
工具->选项->文本编辑器 ->所有语言 ->检查行号
https://msdn.microsoft.com/en-us/library /ms165340.aspx
Visual studio 2015 enterprice
Tools -> Options -> Text Editor -> All Languages -> check Line Numbers
https://msdn.microsoft.com/en-us/library/ms165340.aspx
默认情况下,行号不打开。要打开行号,只需转到“工具”->“选项->文本编辑器 ->所有语言 ->一般->显示和检查行号:
http://blogs.msdn.com/blogfiles /zainnab/WindowsLiveWriter/TurnonLineNumbers_A5E7/image_thumb.png
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
对我来说,行号不会出现在编辑器中,直到我在“所有语言”窗格和我正在使用的语言(C# 等)下添加选项... 显示编辑器选项的屏幕截图
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
在“快速启动”文本框(VS 2015 右上角)中输入“行号”,它将带您到达您需要的位置(勾选“行号”复选框)。
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).
对于 MS Visual Studio 2015,在右上角的快速启动 (Ctrl+Q) 中键入“文本”。
1) 快速启动
2) 在列表中选择文本编辑器->所有语言->常规
select_allLanguages
3) 现在选中“行号”并单击“确定”以获取行号。
最后我们在文本编辑器中得到行号。
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.
在 Visual Studio 2010 Express 中,有一个名为“显示所有设置”的选项。位于“工具 > 选项”窗口。
如果未选中此选项,则行号选项将不可用。确保选中此选项,如下所示。这将使许多附加设置在左侧的树视图中可见。
,“工具 > 选项 > 文本编辑器 > C# > 行编辑器”选项可用。选中“行号”选项以使行号在 Visual Studio 2010 Express 上可见。
In Visual Studio 2010 Express, there is an option called "Show all Settings". Located at "Tools > Options", window.
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.
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.
您应该编辑“settings.json”。在该添加中,
"editor.lineNumbers":"on",
。您可以查看评论以了解您拥有的各种选项。在 Visual Studio Code - 2017 中,您还可以直接转到给定的行号。有以下三种方法可以做到这一点。
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.
正如其他答案已经详细解释的那样,您可以通过进入“工具”->“启用行号”。选项...点击一下...到达某个页面,其中包含大量不相关的选项,扫描它们,找到“行号”复选框,然后选中它。如果您想禁用行号,只需再次点击即可。
截至 2024 年,Visual Studio 仍不提供用于打开或关闭行号的工具栏按钮或键盘快捷键。
这是特别有问题的,因为行号占用了不可忽略的屏幕空间,这并不能证明它们(极其有限)的用处,因此最好在大多数时间将它们隐藏起来。不幸的是,有时您需要它们,但打开和关闭它们却很痛苦。
好消息:您实际上并不需要行号。
大多数始终显示行号的人都是由于以下原因之一而这样做的:
没有行号他们会感到不安全。他们几乎从不看实际的数字,而是习惯了数字总是在那里,所以如果数字不在那里,他们就会觉得少了点什么。 (与编辑器选项卡相同的综合症:它们毫无用处,浪费屏幕空间,并且需要宝贵的时间来不断管理它们,但人们觉得他们需要它们。)
他们使用不支持双击的蹩脚工具-转到源代码行。例如,以 html 形式显示诊断堆栈跟踪的 aspx 网站。 (不要在输出窗口中记录堆栈跟踪,而是使用与编译器用于错误消息相同的格式,因此您只需双击输出窗口中的日志行即可让 Visual Studio 显示源代码。)< /p>
) 过上没有行号的生活:
确保所有日志记录都进入 Visual Studio 的输出窗口,并且其格式与编译器用于错误消息的格式完全相同,以便每一行双击输出窗口可以将您带到正确的源文件和行号。您永远不应该遇到必须从屏幕读取源文件名和行号并手动查找该源文件和该行号的情况。
尽管如此,在极少数情况下,您必须按编号查找特定的源代码行,请使用“转到行”命令。默认情况下,此命令绑定到
Ctrl+G
。如果您想知道当前所在行,请查看文本编辑器窗口底部水平滚动条右侧显示的信息,或再次按
Ctrl+G
: “转到行”对话框已填充当前行。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.