diff --git a/metainfo.xml b/metainfo.xml index cf9e1c26bb..b565707247 100644 --- a/metainfo.xml +++ b/metainfo.xml @@ -111,6 +111,7 @@
  • Adds `MoveTabToLeft` and `MoveTabToRight` actions to move tabs around (#1695)
  • Adds `MoveTabTo` action to move tabs to a specific position (#1695)
  • Ensure inserting new tabs happens right next to the currently active tab (#1695)
  • +
  • Adds CenterCursor (`zz`) vi motion
  • diff --git a/src/vtbackend/ViCommands.cpp b/src/vtbackend/ViCommands.cpp index 8364c8b332..61639d25df 100644 --- a/src/vtbackend/ViCommands.cpp +++ b/src/vtbackend/ViCommands.cpp @@ -1085,6 +1085,11 @@ CellLocation ViCommands::translateToCellLocationAndRecord(ViMotion motion, unsig case ViMotion::JumpToLastJumpPoint: return _jumpHistory.jumpToLast(cursorPosition); case ViMotion::JumpToMarkBackward: return _jumpHistory.jumpToMarkBackward(cursorPosition); case ViMotion::JumpToMarkForward: return _jumpHistory.jumpToMarkForward(cursorPosition); + case ViMotion::CenterCursor: { + _terminal->viewport().makeVisibleWithinSafeArea(unbox(cursorPosition.line), + LineCount(_terminal->pageSize().lines / 2)); + return cursorPosition; + } } crispy::unreachable(); } diff --git a/src/vtbackend/ViInputHandler.cpp b/src/vtbackend/ViInputHandler.cpp index 7a71a0ea82..d7300d70f4 100644 --- a/src/vtbackend/ViInputHandler.cpp +++ b/src/vtbackend/ViInputHandler.cpp @@ -69,7 +69,7 @@ void ViInputHandler::registerAllCommands() std::array, 2> { { std::pair { 'i', TextObjectScope::Inner }, std::pair { 'a', TextObjectScope::A } } }; - auto constexpr MotionMappings = std::array, 47> { { + auto constexpr MotionMappings = std::array, 48> { { // clang-format off { "$", ViMotion::LineEnd }, { "%", ViMotion::ParenthesisMatching }, @@ -118,6 +118,7 @@ void ViInputHandler::registerAllCommands() { "``",ViMotion::JumpToLastJumpPoint }, { "C-O",ViMotion::JumpToMarkBackward }, { "C-I",ViMotion::JumpToMarkForward }, + { "zz",ViMotion::CenterCursor }, // clang-format on } }; diff --git a/src/vtbackend/ViInputHandler.h b/src/vtbackend/ViInputHandler.h index fbadc65ede..7abb3f23f0 100644 --- a/src/vtbackend/ViInputHandler.h +++ b/src/vtbackend/ViInputHandler.h @@ -103,6 +103,7 @@ enum class ViMotion : uint8_t JumpToLastJumpPoint, // '' or `` (jump to last jump) JumpToMarkBackward, // JumpToMarkForward, // + CenterCursor, // zz }; enum class ViOperator : uint8_t @@ -383,6 +384,7 @@ struct std::formatter: formatter case ViMotion::GlobalCurlyOpenDown: name = "GlobalCurlyOpenDown"; break; case ViMotion::LineMarkUp: name = "LineMarkUp"; break; case ViMotion::LineMarkDown: name = "LineMarkDown"; break; + case ViMotion::CenterCursor: name = "CenterCursor"; break; } return formatter::format(name, ctx); }