question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature request] relative line numbers in vim mode

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:22
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
mtaran-googlecommented, 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)
2reactions
marijnhcommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[feature request] relative line numbers in vim mode · Issue #4116
Something I miss from using terminal vim is the option to have relative line numbers; here is an illustration: ...
Read more >
Relative line numbers - Feature requests - Obsidian Forum
Hi, Please add an option to have relative line numbers. It would make it a lot faster to navigate around a note when...
Read more >
How To Enable Relative Line Numbers With IdeaVim
How do I turn on relative line numbers? I heard there's some sort of plugin, but when searching for "relative line numbers" or...
Read more >
How do I use relative line numbers in command line mode?
Assuming your lines span from 15 to 10 lines above the current one, you can achieve what you requested using relative line numbers:...
Read more >
Vim's absolute, relative and hybrid line numbers
Vim's regular line numbers number lines absolutely, relative numbers are relative to the current line and “hybrid” numbers combine both.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found