Relative line numbers in Visual Studio

23.9k views Asked by At

I'm pretty sure I know the answer to this one cause I've been searching everywhere, but if anyone knows he's probably on this site.

Is it possible to display line numbers that are relative to the cursor position in Visual Studio? The line where the cursor is would always be 0, the line above would be 1 as well as the line below, etc.

Perhaps there is an addin that can do that? Given that other addins like Rockscroll can modify the margins in the VS text editor.

Thanks!

5

There are 5 answers

0
Sbu On

For Visual Studio 2019 and vsvim users, Relative Number will now do the job.

Note that if you had regular line numbers in Visual Studio, this will show you 2 line numbers columns by default. You can disable VS default line numbers, and :set number and :set nonumber will toggle the extension's column.

0
zklinger On

You may want to check out my RelativeLineNumbers Visual Studio 2010 extension. Hope you find it useful.

4
Thomas Glaser On

Seems most extensions for relative line numbers do not support Visual Studio 2022 yet.

Fortunately, if you use VsVim, it supports this directly. But it needs to enabled with :set relativenumber.

To make it persistent, create a .vimrc (%userprofile%\.vimrc) with this content:

set relativenumber
0
Chen Wang On

If you are using vscode-vim, you toggle the feature Smart Relative Line open in the user settings.

  1. ctrl + shift + P and search for user settings
  2. in user settings, search for smart relative line
  3. toggle this option open.

This will set absolute line number in insert mode, while relative otherwise. Quiet handy.

2
JoePerkins On

Since VSCode 1.6 you can set editor.lineNumbers with the value of relative in the settings.json file or in File>Preferences>Settings.

Line Numbers option in VSCode settings.