summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjeremycostanzo <56163564+jeremycostanzo@users.noreply.github.com>2022-06-09 23:08:18 +0200
committerGitHub <noreply@github.com>2022-06-10 00:08:18 +0300
commitfdcf99b0c17214d2318298bc4ea911931c3b9ece (patch)
tree85acf79129bf9c3e2eaafacd2d4596a9fee4983d
parent90552e3e7f8f085919a39435a8a68b3a2f633e54 (diff)
downloadalacritty-fdcf99b0c17214d2318298bc4ea911931c3b9ece.tar.gz
alacritty-fdcf99b0c17214d2318298bc4ea911931c3b9ece.zip
Add vi action to center view around vi cursor
-rw-r--r--CHANGELOG.md1
-rw-r--r--alacritty.yml3
-rw-r--r--alacritty/src/config/bindings.rs4
-rw-r--r--alacritty/src/input.rs9
4 files changed, 17 insertions, 0 deletions
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<KeyBinding> {
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<T: EventListener> Execute<T> 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());
},