diff --git a/internal/config/settings.go b/internal/config/settings.go index c8a280f2..92b4fa03 100644 --- a/internal/config/settings.go +++ b/internal/config/settings.go @@ -203,6 +203,7 @@ var defaultCommonSettings = map[string]interface{}{ "readonly": false, "rmtrailingws": false, "ruler": true, + "relativeruler": false, "savecursor": false, "saveundo": false, "scrollbar": false, diff --git a/internal/display/bufwindow.go b/internal/display/bufwindow.go index b054bfee..de688ddd 100644 --- a/internal/display/bufwindow.go +++ b/internal/display/bufwindow.go @@ -335,7 +335,14 @@ func (w *BufWindow) drawDiffGutter(backgroundStyle tcell.Style, softwrapped bool } func (w *BufWindow) drawLineNum(lineNumStyle tcell.Style, softwrapped bool, maxLineNumLength int, vloc *buffer.Loc, bloc *buffer.Loc) { - lineNum := strconv.Itoa(bloc.Y + 1) + cursorLine := w.Buf.GetActiveCursor().Loc.Y + var lineInt int + if w.Buf.Settings["relativeruler"] == false || cursorLine == bloc.Y { + lineInt = bloc.Y + 1 + } else { + lineInt = bloc.Y - cursorLine + } + lineNum := strconv.Itoa(util.Abs(lineInt)) // Write the spaces before the line number if necessary for i := 0; i < maxLineNumLength-len(lineNum); i++ { diff --git a/runtime/help/options.md b/runtime/help/options.md index a8cadba2..5e5d4f86 100644 --- a/runtime/help/options.md +++ b/runtime/help/options.md @@ -214,6 +214,12 @@ Here are the available options: default value: `true` +* `relativeruler`: make line numbers display relatively. If set to true, all lines except + for the line that the cursor is located will display the distance from the + cursor's line. + + default value: `false` + * `savecursor`: remember where the cursor was last time the file was opened and put it there when you open the file again. Information is saved to `~/.config/micro/buffers/`