Skip to content

Commit 23c9e02

Browse files
committed
Add <C-e> and <C-y> to scroll one line at a time
Recently I noticed changes with the behavior of my keybinds: map global normal <C-e> vj map global normal <C-y> vk This is because the cursor movement behavior changed with vj and vk. Scrolling window was previously blocked by the cursor. Now the cursor and selection stays in place. I think the view keyboard behaviors are consistent, and coherent with the current state. But this isn't exactly what we want from <C-e> and <C-y>. Example, when you start to scroll with <C-e> (your cursor stay in place), then you press <C-d> (your cursor is moved back to your view). Example, when you start to scroll with <C-e> (your cursor stay in place), then you press j or k (your view is pushed back to initial position). To solve this, I think we need news and differents default keybinds <C-e> and <C-y>.
1 parent 01fd655 commit 23c9e02

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

README.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ See <<Appending>> below for instructions on extending (appending to) the current
442442
* `pagedown, <c-f>`: scroll one page down
443443
* `<c-u>`: scroll half a page up
444444
* `<c-d>`: scroll half a page down
445+
* `<c-y>`: scroll one line up
446+
* `<c-e>`: scroll one line down
445447

446448
* `)`: rotate selections (the main selection becomes the next one)
447449
* `(`: rotate selections backwards

doc/pages/keys.asciidoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ the Shift modifier and moving will extend each selection instead.
193193
*<c-d>*::
194194
scroll half a page down
195195

196+
*<c-y>*::
197+
scroll one line up
198+
199+
*<c-e>*::
200+
scroll one line down
201+
196202
*;*, *<semicolon>*::
197203
reduce selections to their cursor
198204

src/context.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class KeymapManager;
2020
class AliasRegistry;
2121

2222
enum Direction { Backward = -1, Forward = 1 };
23+
enum Distance { FullScreen = 0, HalfScreen = 1, Line = 2 };
2324

2425
struct JumpList
2526
{

src/normal.cc

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,12 +1402,24 @@ void select_object(Context& context, NormalParams params)
14021402
{{alt(';')}, "run command in object context"}}));
14031403
}
14041404

1405-
template<Direction direction, bool half = false>
1405+
template<Direction direction, Distance distance = FullScreen>
14061406
void scroll(Context& context, NormalParams params)
14071407
{
14081408
const Window& window = context.window();
14091409
const int count = params.count ? params.count : 1;
1410-
const LineCount offset = (window.dimensions().line - 2) / (half ? 2 : 1) * count;
1410+
LineCount offset = 0;
1411+
1412+
switch (distance) {
1413+
case FullScreen:
1414+
offset = (window.dimensions().line - 2) * count;
1415+
break;
1416+
case HalfScreen:
1417+
offset = (window.dimensions().line - 2) / 2 * count;
1418+
break;
1419+
case Line:
1420+
offset = count;
1421+
break;
1422+
}
14111423

14121424
scroll_window(context, offset * direction, OnHiddenCursor::MoveCursorAndAnchor);
14131425
}
@@ -2422,10 +2434,12 @@ static constexpr HashMap<Key, NormalCmd, MemoryDomain::Undefined, KeymapBackend>
24222434
{ {Key::PageUp}, { "scroll one page up", scroll<Backward>} },
24232435
{ {Key::PageDown}, {"scroll one page down", scroll<Forward>} },
24242436

2425-
{ {ctrl('b')}, {"scroll one page up", scroll<Backward >} },
2437+
{ {ctrl('b')}, {"scroll one page up", scroll<Backward>} },
24262438
{ {ctrl('f')}, {"scroll one page down", scroll<Forward>} },
2427-
{ {ctrl('u')}, {"scroll half a page up", scroll<Backward, true>} },
2428-
{ {ctrl('d')}, {"scroll half a page down", scroll<Forward, true>} },
2439+
{ {ctrl('u')}, {"scroll half a page up", scroll<Backward, HalfScreen>} },
2440+
{ {ctrl('d')}, {"scroll half a page down", scroll<Forward, HalfScreen>} },
2441+
{ {ctrl('y')}, {"scroll one line up", scroll<Backward, Line>} },
2442+
{ {ctrl('e')}, {"scroll one line down", scroll<Forward, Line>} },
24292443

24302444
{ {'z'}, {"restore selections from register", restore_selections<false>} },
24312445
{ {alt('z')}, {"combine selections from register", restore_selections<true>} },

0 commit comments

Comments
 (0)