Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vim: Add Multi Replace mode in Vim #8469

Merged
merged 19 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions assets/keymaps/vim.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"shift-v": "vim::ToggleVisualLine",
"ctrl-v": "vim::ToggleVisualBlock",
"ctrl-q": "vim::ToggleVisualBlock",
"shift-r": "vim::ToggleReplace",
"0": "vim::StartOfLine", // When no number operator present, use start of line motion
"ctrl-f": "vim::PageDown",
"pagedown": "vim::PageDown",
Expand Down Expand Up @@ -520,6 +521,15 @@
"ctrl-r +": "editor::Paste"
}
},
{
"context": "Editor && vim_mode == replace",
"bindings": {
"escape": "vim::NormalBefore",
"ctrl-c": "vim::NormalBefore",
"ctrl-[": "vim::NormalBefore",
"backspace": "vim::UndoReplace"
}
},
{
"context": "Editor && VimWaiting",
"bindings": {
Expand Down
4 changes: 3 additions & 1 deletion crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ pub struct Editor {
buffer: Model<MultiBuffer>,
/// Map of how text in the buffer should be displayed.
/// Handles soft wraps, folds, fake inlay text insertions, etc.
display_map: Model<DisplayMap>,
pub display_map: Model<DisplayMap>,
pub selections: SelectionsCollection,
pub scroll_manager: ScrollManager,
columnar_selection_tail: Option<Anchor>,
Expand Down Expand Up @@ -422,6 +422,7 @@ pub struct Editor {
_subscriptions: Vec<Subscription>,
pixel_position_of_newest_cursor: Option<gpui::Point<Pixels>>,
gutter_width: Pixels,
pub vim_replace_map: HashMap<Range<usize>, String>,
style: Option<EditorStyle>,
editor_actions: Vec<Box<dyn Fn(&mut ViewContext<Self>)>>,
show_copilot_suggestions: bool,
Expand Down Expand Up @@ -1567,6 +1568,7 @@ impl Editor {
show_cursor_names: false,
hovered_cursors: Default::default(),
editor_actions: Default::default(),
vim_replace_map: Default::default(),
show_copilot_suggestions: mode == EditorMode::Full,
custom_context_menu: None,
_subscriptions: vec![
Expand Down
8 changes: 6 additions & 2 deletions crates/vim/src/motion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ pub(crate) fn motion(motion: Motion, cx: &mut WindowContext) {
let count = Vim::update(cx, |vim, cx| vim.take_count(cx));
let operator = Vim::read(cx).active_operator();
match Vim::read(cx).state().mode {
Mode::Normal => normal_motion(motion, operator, count, cx),
Mode::Normal | Mode::Replace => normal_motion(motion, operator, count, cx),
Mode::Visual | Mode::VisualLine | Mode::VisualBlock => visual_motion(motion, count, cx),
Mode::Insert => {
// Shouldn't execute a motion in insert mode. Ignoring
Expand Down Expand Up @@ -800,7 +800,11 @@ fn left(map: &DisplaySnapshot, mut point: DisplayPoint, times: usize) -> Display
point
}

fn backspace(map: &DisplaySnapshot, mut point: DisplayPoint, times: usize) -> DisplayPoint {
pub(crate) fn backspace(
map: &DisplaySnapshot,
mut point: DisplayPoint,
times: usize,
) -> DisplayPoint {
for _ in 0..times {
point = movement::left(map, point);
if point.is_zero() {
Expand Down
2 changes: 1 addition & 1 deletion crates/vim/src/normal/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ where
cursor_positions.push(selection.start..selection.start);
}
}
Mode::Insert | Mode::Normal => {
Mode::Insert | Mode::Normal | Mode::Replace => {
let start = selection.start;
let mut end = start;
for _ in 0..count {
Expand Down
2 changes: 1 addition & 1 deletion crates/vim/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn object(object: Object, cx: &mut WindowContext) {
match Vim::read(cx).state().mode {
Mode::Normal => normal_object(object, cx),
Mode::Visual | Mode::VisualLine | Mode::VisualBlock => visual_object(object, cx),
Mode::Insert => {
Mode::Insert | Mode::Replace => {
// Shouldn't execute a text object in insert mode. Ignoring
}
}
Expand Down
Loading
Loading