diff --git a/CHANGELOG.md b/CHANGELOG.md index 46a9d77b..637785a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Support for OpenGL ES 2.0 - Escape sequence to set underline color (`CSI 58 : 2 : Ps : Ps : Ps m`/`CSI 58 : 5 : Ps m`) - Escape sequence to reset underline color (`CSI 59 m`) +- Vi mode keybinding (z) to center view around vi mode cursor ### Changed diff --git a/alacritty.yml b/alacritty.yml index 8b668ca5..3ba6a7f5 100644 --- a/alacritty.yml +++ b/alacritty.yml @@ -625,6 +625,8 @@ # - ToggleBlockSelection # - ToggleSemanticSelection # Toggle semantic selection based on `selection.semantic_escape_chars`. +# - CenterAroundViCursor +# Center view around vi mode cursor # # - Vi mode exclusive cursor motion actions: # @@ -778,6 +780,7 @@ #- { key: V, mods: Control, mode: Vi|~Search, action: ToggleBlockSelection } #- { key: V, mods: Alt, mode: Vi|~Search, action: ToggleSemanticSelection } #- { key: Return, mode: Vi|~Search, action: Open } + #- { key: Z, mode: Vi|~Search, action: CenterAroundViCursor } #- { key: K, mode: Vi|~Search, action: Up } #- { key: J, mode: Vi|~Search, action: Down } #- { key: H, mode: Vi|~Search, action: Left } diff --git a/alacritty/src/config/bindings.rs b/alacritty/src/config/bindings.rs index 4c706811..c48b2d75 100644 --- a/alacritty/src/config/bindings.rs +++ b/alacritty/src/config/bindings.rs @@ -275,6 +275,8 @@ pub enum ViAction { SearchEnd, /// Launch the URL below the vi mode cursor. Open, + /// Centers the screen around the vi mode cursor. + CenterAroundViCursor, } /// Search mode specific actions. @@ -498,6 +500,8 @@ pub fn default_key_bindings() -> Vec { ViAction::SearchPrevious; Return, +BindingMode::VI, ~BindingMode::SEARCH; ViAction::Open; + Z, +BindingMode::VI, ~BindingMode::SEARCH; + ViAction::CenterAroundViCursor; K, +BindingMode::VI, ~BindingMode::SEARCH; ViMotion::Up; J, +BindingMode::VI, ~BindingMode::SEARCH; diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs index 0f389851..0441ecb4 100644 --- a/alacritty/src/input.rs +++ b/alacritty/src/input.rs @@ -230,6 +230,15 @@ impl Execute for Action { ctx.mark_dirty(); } }, + Action::Vi(ViAction::CenterAroundViCursor) => { + let term = ctx.terminal(); + let display_offset = term.grid().display_offset() as i32; + let target = -display_offset + term.screen_lines() as i32 / 2 - 1; + let line = term.vi_mode_cursor.point.line; + let scroll_lines = target - line.0; + + ctx.scroll(Scroll::Delta(scroll_lines)); + }, Action::Search(SearchAction::SearchFocusNext) => { ctx.advance_search_origin(ctx.search_direction()); },