Implement relative line numbers
Opened this issue · 2 comments
Relative line numbers in Vim has been one of our most requested features for our Vim integration. we could obviously roll our own if we wanted to via another extension but would be great if we could bake this in to the codemirror-vim plugin directly and have it be configurable.
@nightwing how doable and worth it do you think this is?
@sergeichestakov this is quite easy to implement
import { lineNumbers } from '@codemirror/view';
function formatNumber() {
return lineNumbers({
formatNumber: (lineNo, state) => {
if (lineNo > state.doc.lines) {
return lineNo;
}
const cursorLine = state.doc.lineAt(state.selection.asSingle().ranges[0].to).number;
if (lineNo === cursorLine) {
return lineNo < 10 ? lineNo + "\xB7" : lineNo + "";
} else {
return Math.abs(cursorLine - lineNo).toString();
}
},
});
}
We probably can use a compartment to include this in vim extension and make it configurable via set relativenumber
But i am not sure how to make this work for set number
, as it is already part of basicSetup
awesome, nice! yeah as for the conflict I think we can try to give it a higher precedence then the line numbers gutter that ships with basicSetup. Otherwise, if that doesn't work, I think it's ok to assume that most users of this extension have more complex use cases that don't involve just using basicSetup and / or are able to filter out the relevant extension if need be. I think wrapping in the right Prec
should do the trick though