Skip to main content

VimEditor

Struct VimEditor 

Source
pub struct VimEditor {
Show 26 fields pub lines: Vec<String>, pub cursor_row: usize, pub cursor_col: usize, pub mode: VimMode, pub config: VimModeConfig, pub scroll_offset: usize, pub visible_height: usize, pub undo_stack: Vec<Snapshot>, pub redo_stack: Vec<Snapshot>, pub unnamed_register: Register, pub search: SearchState, pub visual_anchor: Option<(usize, usize)>, pub pending_count: Option<usize>, pub pending_operator: Option<Operator>, pub pending_g: bool, pub pending_register: bool, pub use_system_clipboard: bool, pub pending_find: Option<(FindDirection, bool)>, pub pending_replace: bool, pub last_edit: Option<EditRecord>, pub recording_edit: Vec<KeyEvent>, pub is_recording: bool, pub modified: bool, pub command_line: String, pub command_active: bool, pub command_buffer: String,
}
Expand description

A self-contained Vim editor instance with its own buffer, cursor, mode, and state. Each view that needs a Vim editor creates its own VimEditor.

Fields§

§lines: Vec<String>§cursor_row: usize§cursor_col: usize§mode: VimMode§config: VimModeConfig§scroll_offset: usize§visible_height: usize§undo_stack: Vec<Snapshot>§redo_stack: Vec<Snapshot>§unnamed_register: Register§search: SearchState§visual_anchor: Option<(usize, usize)>§pending_count: Option<usize>§pending_operator: Option<Operator>§pending_g: bool§pending_register: bool§use_system_clipboard: bool§pending_find: Option<(FindDirection, bool)>§pending_replace: bool§last_edit: Option<EditRecord>§recording_edit: Vec<KeyEvent>§is_recording: bool§modified: bool§command_line: String§command_active: bool§command_buffer: String

Implementations§

Source§

impl VimEditor

Source

pub fn handle_key(&mut self, key: KeyEvent) -> EditorAction

Main input handler. Returns EditorAction to inform the parent.

Source§

impl VimEditor

Source

pub fn move_left(&mut self, count: usize)

Source

pub fn move_right(&mut self, count: usize)

Source

pub fn move_down(&mut self, count: usize)

Source

pub fn move_up(&mut self, count: usize)

Source

pub fn move_to_line_start(&mut self)

Source

pub fn move_to_first_non_blank(&mut self)

Source

pub fn move_to_line_end(&mut self)

Source

pub fn move_to_top(&mut self)

Source

pub fn move_to_bottom(&mut self)

Source

pub fn move_to_line(&mut self, line_num: usize)

Source

pub fn half_page_down(&mut self)

Source

pub fn half_page_up(&mut self)

Source

pub fn move_word_forward(&mut self, count: usize, big_word: bool)

Source

pub fn move_word_end(&mut self, count: usize, big_word: bool)

Source

pub fn move_word_back(&mut self, count: usize, big_word: bool)

Source

pub fn find_char_forward(&mut self, target: char, before: bool)

Source

pub fn find_char_backward(&mut self, target: char, after: bool)

Source

pub fn compute_motion_range( &self, motion: &Motion, count: usize, ) -> Option<MotionRange>

Compute the range that a motion covers from current position. Used by operators like d, y, c.

Source§

impl VimEditor

Source

pub fn execute_operator(&mut self, op: &Operator, motion: &Motion, count: usize)

Execute operator + motion combination

Source

pub fn toggle_case_at_cursor(&mut self)

Toggle case of character at cursor (~)

Source

pub fn replace_char(&mut self, new_char: char)

Replace character at cursor (r)

Source§

impl VimEditor

Start search mode

Commit the search and jump to first match

Cancel search

Source

pub fn jump_to_next_match(&mut self)

Jump to next match (n)

Source

pub fn jump_to_prev_match(&mut self)

Jump to previous match (N)

Source§

impl VimEditor

Source

pub fn enter_visual(&mut self, kind: VisualKind)

Enter visual mode

Source

pub fn visual_range(&self) -> Option<((usize, usize), (usize, usize))>

Get the ordered (start, end) of the visual selection

Source

pub fn visual_delete(&mut self)

Delete visual selection

Source

pub fn visual_yank(&mut self)

Yank visual selection

Source

pub fn visual_indent(&mut self)

Indent visual selection

Source

pub fn visual_dedent(&mut self)

Dedent visual selection

Source

pub fn exit_visual(&mut self)

Exit visual mode

Source§

impl VimEditor

Source

pub fn new(content: &str, config: VimModeConfig) -> Self

Source

pub fn new_empty(config: VimModeConfig) -> Self

Source

pub fn set_content(&mut self, content: &str)

Source

pub fn content(&self) -> String

Source

pub fn selected_text(&self) -> Option<String>

Get the visually selected text

Source

pub fn line_count(&self) -> usize

Source

pub fn current_line(&self) -> &str

Source

pub fn current_line_len(&self) -> usize

Source

pub fn clamp_cursor(&mut self)

Clamp cursor column to valid range for current line

Source

pub fn save_undo(&mut self)

Save current state for undo

Source

pub fn undo(&mut self)

Undo last change

Source

pub fn redo(&mut self)

Redo last undone change

Source

pub fn ensure_cursor_visible(&mut self)

Ensure scroll keeps cursor visible with scrolloff

Source

pub fn insert_char(&mut self, c: char)

Source

pub fn insert_newline(&mut self)

Source

pub fn backspace(&mut self)

Source

pub fn delete_char_at_cursor(&mut self)

Source

pub fn delete_line(&mut self, row: usize) -> Option<String>

Source

pub fn delete_lines(&mut self, start: usize, count: usize) -> String

Source

pub fn delete_range( &mut self, start_col: usize, end_col: usize, row: usize, ) -> String

Source

pub fn paste_after(&mut self)

Source

pub fn paste_before(&mut self)

Source

pub fn indent_line(&mut self, row: usize)

Source

pub fn dedent_line(&mut self, row: usize)

Source

pub fn take_count(&mut self) -> usize

Get effective count: pending_count or 1

Source

pub fn update_command_line(&mut self)

Update command line based on current mode

Source

pub fn copy_to_system_clipboard(&self, text: &str)

Source

pub fn paste_from_system_clipboard(&mut self)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.