Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative line numbers #423

Closed
rebornix opened this issue Jul 10, 2016 · 32 comments
Closed

Relative line numbers #423

rebornix opened this issue Jul 10, 2016 · 32 comments
Labels
Milestone

Comments

@rebornix
Copy link
Member

When we run commands with numeric prefix, we always need to calculate the relative line numbers. In this case, showing relative line numbers beside VS Code line number will be really helpful. But currently VS Code doesn't allow users to customize the line number section.

A dirty workaround is adding images containing Number to the gutter of each line, but it breaks the original gutter view.

@johnfn
Copy link
Member

johnfn commented Jul 10, 2016

This is actually a Vim setting proper:

http://jeffkreeftmeijer.com/2013/vims-new-hybrid-line-number-mode/

@johnfn johnfn added the size/M label Jul 12, 2016
@johnfn johnfn added this to the v0.3 milestone Jul 27, 2016
@bryphe
Copy link

bryphe commented Aug 20, 2016

I'm really enjoying VSCodeVim, but I missed this from VIM, so I implemented the gutter image concept @rebornix proposed here:
https://github.com/extr0py/vscode-relative-line-numbers

demo

It's available as the 'Relative Line Number' extension in the market place:
https://marketplace.visualstudio.com/items?itemName=extr0py.vscode-relative-line-numbers

As mentioned, the images break a few scenarios, like debugging, but at least for my use case they are helpful. It'd be nice if in the future VSCode gave us a way to customize the line number section!

@johnfn
Copy link
Member

johnfn commented Aug 20, 2016

Wow, that is very, very cool @extr0py!

Would you be interested in adding that functionality to VSCodeVim (under a setting flag)? We'd love to have it.

If not, do you mind if we just steal it? 😉

@bryphe
Copy link

bryphe commented Aug 20, 2016

Thanks! Definitely, makes sense for it to be in VSCodeVim, especially since it is a Vim setting anyway :) I've been enjoying VSCodeVim so would be great to finally contribute something.

I'd be happy to add it - I may not get chance to put together a PR until next weekend though. If you want to steal it in the meantime, go for it!

@rebornix
Copy link
Member Author

@extr0py it's insanely amazing and it's almost the same as I thought originally. The biggest number you use is 99 and I think it works on most Monitors (no one wants to show 100+ lines on one page, right?).

Since Gutter customization feature request is on track from Code side and seems ppl are not blocked with this feature, I'd like to leave this contribution to you @extr0py :)

@rebornix
Copy link
Member Author

rebornix commented Sep 7, 2016

Just send a PR to @extr0py 's relative line number extension bryphe/vscode-relative-line-numbers#3. Previously it was using setInterval and generate too many setDecorations which make the jk command hang sometimes. Now we switch to hook to vscode's selection change event and mitigate the issue (from my experience, I no longer see any lag).

Since it's redrawing the decorations for the gutter and we don't have any layer concept for gutter, this feature definitely breaks the breakpoint mark on the gutter. So I'd like to keep it a separate extension. Once my PR is merged, I'd like to write a short description about how to leverage this extension to do the relative line number feature.

@rebornix
Copy link
Member Author

Close this as we are going to have it in Code.

@vviikk
Copy link

vviikk commented Oct 18, 2016

Is this in Code already or do we need to use @extr0py's plugin?

@rebornix
Copy link
Member Author

@piggyslasher it's a Code feature http://code.visualstudio.com/updates#_improvements-to-linenumber-and-whitespace-settings you don't need to install any plugin.

@Riobe
Copy link

Riobe commented Nov 10, 2016

@rebornix Can this be reopened? This does not work like @extr0py 's plugin. It only shows the absolute on the current line, whereas I want to see the absolute on every line, and the relative on every line.

Your link is broken, I think you mean this: http://code.visualstudio.com/updates/v1_6#_improvements-to-linenumber-and-whitespace-settings (the v1_6 part). There are only 3 values, on, off, and relative. There is not an option to get the behavior of @extr0py 's plugin

@rebornix
Copy link
Member Author

@Riobe good catch, I found that I can't use feature with latest Insider but while I debug the extension, it works perfectly.

@xconverge
Copy link
Member

@Riobe now that this is in vscode it doesn't make sense to reopen this within the vscodevim plugin in my opinion, that would now be an enhancement for the core functionality in vscode

@vviikk
Copy link

vviikk commented Nov 11, 2016

Agreed. Even in vim - it's either/or.

On 10 Nov 2016 12:39 p.m., "Sean Kelly" notifications@github.com wrote:

@Riobe https://github.com/Riobe now that this is in vscode it doesn't
make sense to reopen this within the vscodevim plugin in my opinion, that
would now be an enhancement for the core functionality in vscode


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#423 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AB5h1QvNhXvw5qYn5GUvS6FV_efsfcK2ks5q8qAfgaJpZM4JI11o
.

@Shahor
Copy link

Shahor commented Nov 18, 2016

Sorry to bother everyone with this, but you all keep saying that this is in vscode but I just can't find it :/

@bryphe
Copy link

bryphe commented Nov 18, 2016

Use the editor.lineNumbers setting with a value of relative to get that behavior. Hope that helps, @Shahor

@rebornix
Copy link
Member Author

@Shahor I think right now with Stable and Insider, you can use the setting @extr0py provides, or run ex command :set relativenumber, :set number, :set nonumber to make it happen.

@Shahor
Copy link

Shahor commented Nov 19, 2016

Thanks @extr0py @rebornix :)

@PaulBGD
Copy link

PaulBGD commented Apr 1, 2017

This is one of my favorite features of Vim and it took me a bit of searching into these issues to find out that I needed to set editor.lineNumbers. Maybe put this in the README?

@xconverge
Copy link
Member

We could, but it is also a vscode thing and nothing to do with us...(although a lot of us like it)

@PaulBGD
Copy link

PaulBGD commented Apr 1, 2017

Well it's a Vim feature.

@vincentbel
Copy link
Contributor

Actually I'd like to set relative line number automatically the same as the vim numbertoggle plugin does(the source):

  • insert mode -> absolute line number
  • normal mode -> relative line number
  • lose focus -> absolute line number
  • ...

I think we can't achieve this by changing vscode editor.lineNumbers setting. Can we provide a option to achieve this?

@Chillee
Copy link
Member

Chillee commented Jul 5, 2017

@vincentbel Currently not possible, but wouldn't be that hard to add an option to do so.

@ersel
Copy link

ersel commented Mar 6, 2018

@Chillee where would one need to look to implement this?

@ersel
Copy link

ersel commented Mar 7, 2018

If anyone else is also looking for mode dependent relative line numbers as in vim-numbertoggle as pointed out by @vincentbel, see here for the solution I've come up with.

screen capture on 2018-03-07 at 22-24-29

@Chillee
Copy link
Member

Chillee commented Mar 8, 2018

@ersel If you wanted to add this to the extension proper, I think a check in modeHandler.ts plus some configuration would make it work.

@a-eid
Copy link

a-eid commented Jul 6, 2018

"editor.lineNumbers": "relative"

@avucic
Copy link

avucic commented Sep 26, 2018

If I set to relative and do this:
:t6.
wrong line is copied. The same is for jumping. Is that related to my settings? thanx in advance

mudassir-ahmed added a commit to mudassir-ahmed/dotfiles that referenced this issue Apr 6, 2020
@pablospe
Copy link

pablospe commented Aug 7, 2020

Is it possible to use relative numbers only in Normal/Visual mode but regular numbering in Insert mode? How would you programmatically select the correct option of editor.lineNumbers?

@ersel
Copy link

ersel commented Aug 7, 2020

@pablospe , that should be possible using the plugin once this PR is merged:
#5010

@MxGutierrez
Copy link

The above answers do not behave like vim's numbertoggle plugin. The following does:
"vim.smartRelativeLine": true

@pablospe
Copy link

pablospe commented Oct 6, 2020

This works great! Just one issue, if you disable the vim extension (for various reason) the smartRelativeLine remains always true. Is there a way to change this value in keybindings.json. For example, what would you add to the following command to also disable the smartRelativeLine:

keybindings.json:

    {
        "key"    : "ctrl+alt+space",
        "command": "toggleVim"
    },

@da-the-dev
Copy link

This works great! Just one issue, if you disable the vim extension (for various reason) the smartRelativeLine remains always true. Is there a way to change this value in keybindings.json. For example, what would you add to the following command to also disable the smartRelativeLine:

keybindings.json:

    {
        "key"    : "ctrl+alt+space",
        "command": "toggleVim"
    },

Any solutions for this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests