@@ -58,10 +58,6 @@ def make_default_syntax_table() -> dict[str, int]:
5858 return st
5959
6060
61- def _is_vi_word_char (c : str ) -> bool :
62- return c .isalnum () or c == '_'
63-
64-
6561def make_default_commands () -> dict [CommandName , type [Command ]]:
6662 result : dict [CommandName , type [Command ]] = {}
6763 all_commands = itertools .chain (vars (commands ).values (), vars (vi_commands ).values ())
@@ -543,190 +539,6 @@ def eow(self, p: int | None = None) -> int:
543539 p += 1
544540 return p
545541
546- def vi_eow (self , p : int | None = None ) -> int :
547- """Return the 0-based index of the last character of the word
548- following p most immediately (vi 'e' semantics).
549-
550- Vi has three character classes: word chars (alnum + _), punctuation
551- (non-word, non-whitespace), and whitespace. 'e' moves to the end
552- of the current or next word/punctuation sequence."""
553- if p is None :
554- p = self .pos
555- b = self .buffer
556-
557- if not b :
558- return 0
559-
560- # Helper to check if at end of current sequence
561- def at_sequence_end (pos : int ) -> bool :
562- if pos >= len (b ) - 1 :
563- return True
564- curr_is_word = _is_vi_word_char (b [pos ])
565- next_is_word = _is_vi_word_char (b [pos + 1 ])
566- curr_is_space = b [pos ].isspace ()
567- next_is_space = b [pos + 1 ].isspace ()
568- if curr_is_word :
569- return not next_is_word
570- elif not curr_is_space :
571- # Punctuation - at end if next is word or whitespace
572- return next_is_word or next_is_space
573- return True
574-
575- # If already at end of a word/punctuation, move forward
576- if p < len (b ) and at_sequence_end (p ):
577- p += 1
578-
579- # Skip whitespace
580- while p < len (b ) and b [p ].isspace ():
581- p += 1
582-
583- if p >= len (b ):
584- return len (b ) - 1
585-
586- # Move to end of current word or punctuation sequence
587- if _is_vi_word_char (b [p ]):
588- while p + 1 < len (b ) and _is_vi_word_char (b [p + 1 ]):
589- p += 1
590- else :
591- # Punctuation sequence
592- while p + 1 < len (b ) and not _is_vi_word_char (b [p + 1 ]) and not b [p + 1 ].isspace ():
593- p += 1
594-
595- return min (p , len (b ) - 1 )
596-
597- def vi_forward_word (self , p : int | None = None ) -> int :
598- """Return the 0-based index of the first character of the next word
599- (vi 'w' semantics).
600-
601- Vi has three character classes: word chars (alnum + _), punctuation
602- (non-word, non-whitespace), and whitespace. 'w' moves to the start
603- of the next word or punctuation sequence."""
604- if p is None :
605- p = self .pos
606- b = self .buffer
607-
608- if not b or p >= len (b ):
609- return max (0 , len (b ) - 1 ) if b else 0
610-
611- # Skip current word or punctuation sequence
612- if _is_vi_word_char (b [p ]):
613- # On a word char - skip word chars
614- while p < len (b ) and _is_vi_word_char (b [p ]):
615- p += 1
616- elif not b [p ].isspace ():
617- # On punctuation - skip punctuation
618- while p < len (b ) and not _is_vi_word_char (b [p ]) and not b [p ].isspace ():
619- p += 1
620-
621- # Skip whitespace to find next word or punctuation
622- while p < len (b ) and b [p ].isspace ():
623- p += 1
624-
625- # Clamp to valid buffer range
626- return min (p , len (b ) - 1 ) if b else 0
627-
628- def vi_forward_word_ws (self , p : int | None = None ) -> int :
629- """Return the 0-based index of the first character of the next WORD
630- (vi 'W' semantics).
631-
632- Treats white space as the only separator."""
633- if p is None :
634- p = self .pos
635- b = self .buffer
636-
637- if not b or p >= len (b ):
638- return max (0 , len (b ) - 1 ) if b else 0
639-
640- # Skip all non-whitespace (the current WORD)
641- while p < len (b ) and not b [p ].isspace ():
642- p += 1
643-
644- # Skip whitespace to find next WORD
645- while p < len (b ) and b [p ].isspace ():
646- p += 1
647-
648- # Clamp to valid buffer range
649- return min (p , len (b ) - 1 ) if b else 0
650-
651- def vi_bow (self , p : int | None = None ) -> int :
652- """Return the 0-based index of the beginning of the word preceding p
653- (vi 'b' semantics).
654-
655- Vi has three character classes: word chars (alnum + _), punctuation
656- (non-word, non-whitespace), and whitespace. 'b' moves to the start
657- of the current or previous word/punctuation sequence."""
658- if p is None :
659- p = self .pos
660- b = self .buffer
661-
662- if not b or p <= 0 :
663- return 0
664-
665- p -= 1
666-
667- # Skip whitespace going backward
668- while p >= 0 and b [p ].isspace ():
669- p -= 1
670-
671- if p < 0 :
672- return 0
673-
674- # Now skip the word or punctuation sequence we landed in
675- if _is_vi_word_char (b [p ]):
676- while p > 0 and _is_vi_word_char (b [p - 1 ]):
677- p -= 1
678- else :
679- # Punctuation sequence
680- while p > 0 and not _is_vi_word_char (b [p - 1 ]) and not b [p - 1 ].isspace ():
681- p -= 1
682-
683- return p
684-
685- def vi_bow_ws (self , p : int | None = None ) -> int :
686- """Return the 0-based index of the beginning of the WORD preceding p
687- (vi 'B' semantics).
688-
689- Treats white space as the only separator."""
690- if p is None :
691- p = self .pos
692- b = self .buffer
693-
694- if not b or p <= 0 :
695- return 0
696-
697- p -= 1
698-
699- # Skip whitespace going backward
700- while p >= 0 and b [p ].isspace ():
701- p -= 1
702-
703- if p < 0 :
704- return 0
705-
706- # Now skip the WORD we landed in
707- while p > 0 and not b [p - 1 ].isspace ():
708- p -= 1
709-
710- return p
711-
712- def find_char_forward (self , char : str , p : int | None = None ) -> int | None :
713- """Find next occurrence of char after p. Returns index or None."""
714- if p is None :
715- p = self .pos
716- for i in range (p + 1 , len (self .buffer )):
717- if self .buffer [i ] == char :
718- return i
719- return None
720-
721- def find_char_backward (self , char : str , p : int | None = None ) -> int | None :
722- """Find previous occurrence of char before p. Returns index or None."""
723- if p is None :
724- p = self .pos
725- for i in range (p - 1 , - 1 , - 1 ):
726- if self .buffer [i ] == char :
727- return i
728- return None
729-
730542 def bol (self , p : int | None = None ) -> int :
731543 """Return the 0-based index of the line break preceding p most
732544 immediately.
0 commit comments