diff --git a/doc.go b/doc.go index 6561d9e9..36651c9f 100644 --- a/doc.go +++ b/doc.go @@ -324,6 +324,7 @@ Change the current working directory to the next/previous jumplist item. bottom (default 'G' and '') Move the current file selection to the top/bottom of the directory. +A count can be specified to move to a specific line, for example use `3G` to move to the third line. high (default 'H') middle (default 'M') diff --git a/docstring.go b/docstring.go index 0e535294..7946d2c4 100644 --- a/docstring.go +++ b/docstring.go @@ -332,7 +332,9 @@ Change the current working directory to the next/previous jumplist item. top (default 'gg' and '') bottom (default 'G' and '') -Move the current file selection to the top/bottom of the directory. +Move the current file selection to the top/bottom of the directory. A count can +be specified to move to a specific line, for example use '3G' to move to the +third line. high (default 'H') middle (default 'M') diff --git a/eval.go b/eval.go index 4e9ddc6a..e6b7adfc 100644 --- a/eval.go +++ b/eval.go @@ -1425,7 +1425,13 @@ func (e *callExpr) eval(app *app, args []string) { if !app.nav.init { return } - if app.nav.top() { + var moved bool + if e.count == 0 { + moved = app.nav.top() + } else { + moved = app.nav.move(e.count - 1) + } + if moved { app.ui.loadFile(app, true) app.ui.loadFileInfo(app.nav) } @@ -1433,7 +1439,13 @@ func (e *callExpr) eval(app *app, args []string) { if !app.nav.init { return } - if app.nav.bottom() { + var moved bool + if e.count == 0 { + moved = app.nav.bottom() + } else { + moved = app.nav.move(e.count - 1) + } + if moved { app.ui.loadFile(app, true) app.ui.loadFileInfo(app.nav) } diff --git a/lf.1 b/lf.1 index 01b8fe73..10cdd113 100644 --- a/lf.1 +++ b/lf.1 @@ -377,7 +377,7 @@ Change the current working directory to the next/previous jumplist item. bottom (default 'G' and '') .EE .PP -Move the current file selection to the top/bottom of the directory. +Move the current file selection to the top/bottom of the directory. A count can be specified to move to a specific line, for example use `3G` to move to the third line. .PP .EX high (default 'H') diff --git a/nav.go b/nav.go index faf1b880..d8254914 100644 --- a/nav.go +++ b/nav.go @@ -1099,6 +1099,19 @@ func (nav *nav) low() bool { return old != dir.ind } +func (nav *nav) move(index int) bool { + old := nav.currDir().ind + + switch { + case index < old: + return nav.up(old - index) + case index > old: + return nav.down(index - old) + default: + return false + } +} + func (nav *nav) toggleSelection(path string) { if _, ok := nav.selections[path]; ok { delete(nav.selections, path) diff --git a/opts.go b/opts.go index 56f91f5a..48324be3 100644 --- a/opts.go +++ b/opts.go @@ -161,10 +161,10 @@ func init() { gOpts.keys["l"] = &callExpr{"open", nil, 1} gOpts.keys[""] = &callExpr{"open", nil, 1} gOpts.keys["q"] = &callExpr{"quit", nil, 1} - gOpts.keys["gg"] = &callExpr{"top", nil, 1} - gOpts.keys[""] = &callExpr{"top", nil, 1} - gOpts.keys["G"] = &callExpr{"bottom", nil, 1} - gOpts.keys[""] = &callExpr{"bottom", nil, 1} + gOpts.keys["gg"] = &callExpr{"top", nil, 0} + gOpts.keys[""] = &callExpr{"top", nil, 0} + gOpts.keys["G"] = &callExpr{"bottom", nil, 0} + gOpts.keys[""] = &callExpr{"bottom", nil, 0} gOpts.keys["H"] = &callExpr{"high", nil, 1} gOpts.keys["M"] = &callExpr{"middle", nil, 1} gOpts.keys["L"] = &callExpr{"low", nil, 1}