diff --git a/README.asciidoc b/README.asciidoc index ef41500f..8dc6d122 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -386,6 +386,8 @@ view. * `vk`: scroll the window count line upward * `vl`: scroll the window count columns right +Using `V` will lock view mode until `` is hit + Marks ~~~~~ diff --git a/src/normal.cc b/src/normal.cc index 8be4b792..28347413 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -229,10 +229,18 @@ void goto_commands(Context& context, NormalParams params) } } +template void view_commands(Context& context, NormalParams params) { + const int count = params.count; on_next_key_with_autoinfo(context, KeymapMode::View, - [params](Key key, Context& context) { + [count](Key key, Context& context) { + if (key == Key::Escape) + return; + + if (lock) + view_commands(context, {}); + auto cp = key.codepoint(); if (not cp or not context.has_window()) return; @@ -256,16 +264,16 @@ void view_commands(Context& context, NormalParams params) context.window().display_line_at(cursor.line, window.dimensions().line-1); break; case 'h': - context.window().scroll(-std::max(1, params.count)); + context.window().scroll(-std::max(1, count)); break; case 'j': - context.window().scroll( std::max(1, params.count)); + context.window().scroll( std::max(1, count)); break; case 'k': - context.window().scroll(-std::max(1, params.count)); + context.window().scroll(-std::max(1, count)); break; case 'l': - context.window().scroll( std::max(1, params.count)); + context.window().scroll( std::max(1, count)); break; } }, "view", @@ -1496,7 +1504,8 @@ static NormalCmdDesc cmds[] = { 'g', "go to location", goto_commands }, { 'G', "extend to location", goto_commands }, - { 'v', "move view", view_commands }, + { 'v', "move view", view_commands }, + { 'V', "move view (locked)", view_commands }, { 'y', "yank selected text", yank }, { 'p', "paste after selected text", repeated> },