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

Closed
ahaas opened this issue Jul 14, 2016 · 6 comments
Closed

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

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

Comments

@ahaas
Copy link

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

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 commented Jan 1, 2022

How would you implement this in cm6?

@huyz
Copy link

huyz commented Jun 29, 2022

Might want to take look at:
https://github.com/nadavspi/obsidian-relative-line-numbers
https://github.com/jsjoeio/codemirror-line-numbers-relative

@marijnh
Copy link
Member

marijnh commented Jul 19, 2022

The vim code is now being maintained at https://github.com/replit/codemirror-vim/ . If this is still important, check whether there is an issue open for it there.

@marijnh marijnh closed this as completed Jul 19, 2022
@huyz
Copy link

huyz commented Jul 19, 2022

@marijnh Can you update this page https://codemirror.net/5/demo/vim.html regarding active maintenance? I know it's for v5 but it's always the first page I hit whenever I google "codemirror vim" (and not everyone knows that v6 has a different story) and everyone repeats that there's no active maintainer.

@marijnh
Copy link
Member

marijnh commented Jul 19, 2022

Good idea. Done in fbe87a2

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

6 participants