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

Change in word for vi key mappings #849

Closed
wants to merge 5 commits into from
Closed
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
28 changes: 18 additions & 10 deletions src/edit_mode/vi/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ where
if let Some('i') = input.peek() {
let _ = input.next();
match input.next() {
Some(c)
if is_valid_change_inside_left(c) || is_valid_change_inside_right(c) =>
{
Some(Command::DeleteInside(*c))
}
Some(c) if is_valid_change_inside(c) => Some(Command::DeleteInside(*c)),
_ => None,
}
} else {
Expand Down Expand Up @@ -48,11 +44,7 @@ where
if let Some('i') = input.peek() {
let _ = input.next();
match input.next() {
Some(c)
if is_valid_change_inside_left(c) || is_valid_change_inside_right(c) =>
{
Some(Command::ChangeInside(*c))
}
Some(c) if is_valid_change_inside(c) => Some(Command::ChangeInside(*c)),
_ => None,
}
} else {
Expand Down Expand Up @@ -180,6 +172,12 @@ impl Command {
Some(event) => vec![ReedlineOption::Event(event.clone())],
None => vec![],
},
Self::ChangeInside('w') => {
vec![
ReedlineOption::Edit(EditCommand::BackspaceWord),
ReedlineOption::Edit(EditCommand::DeleteWord),
]
}
Self::ChangeInside(left) if is_valid_change_inside_left(left) => {
let right = bracket_for(left);
vec![
Expand All @@ -197,6 +195,12 @@ impl Command {
Self::ChangeInside(_) => {
vec![]
}
Self::DeleteInside('w') => {
vec![
ReedlineOption::Edit(EditCommand::BackspaceWord),
ReedlineOption::Edit(EditCommand::DeleteWord),
]
}
Self::DeleteInside(left) if is_valid_change_inside_left(left) => {
let right = bracket_for(left);
vec![
Expand Down Expand Up @@ -351,6 +355,10 @@ fn bracket_for(c: &char) -> char {
}
}

pub(crate) fn is_valid_change_inside(c: &char) -> bool {
*c == 'w' || is_valid_change_inside_left(c) || is_valid_change_inside_right(c)
}

pub(crate) fn is_valid_change_inside_left(c: &char) -> bool {
matches!(c, '(' | '[' | '{' | '"' | '\'' | '`' | '<')
}
Expand Down
6 changes: 2 additions & 4 deletions src/edit_mode/vi/parser.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use super::command::{
is_valid_change_inside_left, is_valid_change_inside_right, parse_command, Command,
};
use super::command::{is_valid_change_inside, parse_command, Command};
use super::motion::{parse_motion, Motion};
use crate::{edit_mode::vi::ViMode, EditCommand, ReedlineEvent, Vi};
use std::iter::Peekable;
Expand Down Expand Up @@ -110,7 +108,7 @@ impl ParsedViSequence {
| (Some(Command::HistorySearch), ParseResult::Incomplete)
| (Some(Command::Change), ParseResult::Valid(_)) => Some(ViMode::Insert),
(Some(Command::ChangeInside(char)), ParseResult::Incomplete)
if is_valid_change_inside_left(char) || is_valid_change_inside_right(char) =>
if is_valid_change_inside(char) =>
{
Some(ViMode::Insert)
}
Expand Down