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

[feature request] relative line numbers in vim mode #4116

Open
ahaas opened this issue Jul 14, 2016 · 2 comments
Open

[feature request] relative line numbers in vim mode #4116

ahaas opened this issue Jul 14, 2016 · 2 comments
Labels

Comments

@ahaas
Copy link

@ahaas ahaas commented Jul 14, 2016

Something I miss from using terminal vim is the option to have relative line numbers; here is an illustration: http://jeffkreeftmeijer.com/images/relativenumber.gif

It would be enabled with :set relativenumber and was very useful for quickly jumping up and down to the desired line (e.g. 10j goes down ten lines) Without them, jumping a desired line often involves either guessing the offset, or repeatedly tapping j/k (an antipattern). One could also jump to the absolute line number, e.g. 1234gg, however for large files this is pretty slow.

Relative line numbers as an option would definitely be great to have in vim mode.

@adrianheine adrianheine added the vim label Sep 7, 2018
@mtaran-google
Copy link
Contributor

@mtaran-google mtaran-google commented Oct 4, 2018

FYI, with today's CodeMirror APIs this is actually not that hard. Basic hacky implementation that works on codemirror.net:

function showRelativeLines(cm) {
  const lineNum = cm.getCursor().line + 1;
  if (cm.state.curLineNum === lineNum) {
    return;
  }
  cm.state.curLineNum = lineNum;
  cm.setOption('lineNumberFormatter', l => 
    l === lineNum ? lineNum : Math.abs(lineNum - l));
}
editor.on('cursorActivity', showRelativeLines)

@jsjoeio
Copy link

@jsjoeio jsjoeio commented Jan 1, 2022

How would you implement this in cm6?

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

Successfully merging a pull request may close this issue.

None yet
4 participants