I frequently use the go-to line (Ctrl+G) feature to jump to specific lines, and I'd love to see support for relative line numbers in the future.
Relative line-jumping could be added by parsing signs at the beginning of the command:
| Command | Action
| ------------ | ------------------
| Ctrl+G, n | Jump to line n
| Ctrl+G, +n | Jump to line min(line_count, current_line + n)
| Ctrl+G, -n | Jump to line max(1, current_line - n)
Currently, the + sign is ignored, the - sign produces a nonsensical output ("Go to line -20") and jumps to line 1. I believe that parsing of signs wouldn't break anyone's workflow in any way.
@usernamehw This was two years ago, might wanna give it another chance.
It's not a feature that bloats the editor in any way, imho it doesn't interfere with the objective of keeping VSCode lean and fast.
Of course, that's not for me to decide, but I think it would be nice to give it a chance and think about it.
As I see it, the current behavior is actually flawed, because negative line numbers are already parsed even though they don't serve a real-world purpose. Implementing signed line numbers properly would fix this behavior and provide a very usable new feature at the same time.
Couldn't this be accomplished with an extension?
@thecakeisalie25 I'm sure it could, I just think it should be part of the core functionality. The current behavior is kinda broken, it would be a small addition that wouldn't cause any problems and it would replace a currently broken mechanism (signed numbers in the go-to box) with a functional one.
@SplittyDev Fair. And it shouldn't be that hard to implement:
if(goto.startsWith("+")
{
line+=goto.toInt();
}
else if(gotoInput.startsWith("-")
{
line-=goto.toInt();
}
else
{
currentGotoMethod(goto);
}
I vote +1.
@thecakeisalie25 Even easier:
if (goto.startsWith ("+") || goto.startsWith ("-")) goto = currentLine + Number (goto)
currentGotoMethod (goto);
In case anyone is looking for an extension that implements this functionality, this one has been released for a few months. Seems to implement the missing feature, albeit not as seamless as a built-in solution could.
I am not seeing a good way to implement this into core right now because a while ago we added support for negative line numbers that would navigate from the end of the file. We would have to find another syntax to support relative navigation or change this support which may be surprising.
Since there is an extension I would tend to mark this as closed, but give it a couple of days for feedback.
I guess one way would be ~N and ~-N
Examples:
~20 // jumps 20 lines ahead
~-20 // jumps 20 lines behind
I understand it though if this isn't a priority in any way.
Not sure if people would actually use this, would be nice go gather some more feedback
I think this is not easily discoverable and would prefer an extra command to trigger this as the extension suggests.
I second the closing. With an extension in place & the syntax being occupied in the meantime, I don't think there's a nice way for this to go forward in core. If extension installations are an indicator, the feature isn't hugely popular either.
We closed this issue because we don't plan to address it in the foreseeable future. You can find more detailed information about our decision-making process here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.
If you wonder what we are up to, please see our roadmap and issue reporting guidelines.
Thanks for your understanding and happy coding!
In case anyone is looking for an extension that implements this functionality, this one has been released for a few months. Seems to implement the missing feature, albeit not as seamless as a built-in solution could.
Just for quick reference if anyone comes across this after searching, the extension mentioned is 2 years plus old and has never been updated. There is a bug with it when jumping lines when you have a text selection. It's original source code is also not available, which makes it impossible to build on top off / contribute a change, thus I made an alternative to it!
https://marketplace.visualstudio.com/items?itemName=EnkelDigital.relative-goto
Do check it out, this extension is open source on github and you are free to fork / contribute to it!
It also contains more than just jumping using relative lines, it also allows you to select a text between your original cursor position to the final jump destination.
Most helpful comment
Just for quick reference if anyone comes across this after searching, the extension mentioned is 2 years plus old and has never been updated. There is a bug with it when jumping lines when you have a text selection. It's original source code is also not available, which makes it impossible to build on top off / contribute a change, thus I made an alternative to it!
https://marketplace.visualstudio.com/items?itemName=EnkelDigital.relative-goto
Do check it out, this extension is open source on github and you are free to fork / contribute to it!
It also contains more than just jumping using relative lines, it also allows you to select a text between your original cursor position to the final jump destination.