Documentation
¶
Overview ¶
Package vim provides vim-style modal editing for BubbleTea text input.
Index ¶
- type Buffer
- func (b *Buffer) CharUnderCursor() rune
- func (b *Buffer) Content() string
- func (b *Buffer) CurrentLine() string
- func (b *Buffer) CurrentLineLen() int
- func (b *Buffer) Cursor() Position
- func (b *Buffer) CursorOffset() int
- func (b *Buffer) DeleteChar() string
- func (b *Buffer) DeleteCharBefore() string
- func (b *Buffer) DeleteLine() string
- func (b *Buffer) DeleteRange(start, end Position) string
- func (b *Buffer) DeleteToEndOfLine() string
- func (b *Buffer) FirstNonBlank()
- func (b *Buffer) Insert(text string)
- func (b *Buffer) JoinLines()
- func (b *Buffer) LineCount() int
- func (b *Buffer) Lines() []string
- func (b *Buffer) NewLineAbove()
- func (b *Buffer) NewLineBelow()
- func (b *Buffer) Paste()
- func (b *Buffer) PasteBefore()
- func (b *Buffer) ReplaceChar(r rune)
- func (b *Buffer) SetContent(content string)
- func (b *Buffer) SetCursor(pos Position)
- func (b *Buffer) SetCursorFromOffset(offset int)
- func (b *Buffer) SetCursorInsert(pos Position)
- func (b *Buffer) SetYank(content string)
- func (b *Buffer) Yank() string
- func (b *Buffer) YankLine() string
- func (b *Buffer) YankRange(start, end Position) string
- type Editor
- func (e *Editor) CommandBuffer() string
- func (e *Editor) Content() string
- func (e *Editor) Cursor() Position
- func (e *Editor) CursorOffset() int
- func (e *Editor) EnsureCursorVisible()
- func (e *Editor) IsCommandMode() bool
- func (e *Editor) Mode() Mode
- func (e *Editor) SetContent(content string)
- func (e *Editor) SetCursorInsert(pos Position)
- func (e *Editor) SetSize(width, height int)
- func (e *Editor) SetSyntax(s *SyntaxStyler)
- func (e *Editor) State() *State
- func (e *Editor) Update(msg tea.KeyMsg) (cmd string, quit bool)
- func (e *Editor) View(cfg ViewConfig) string
- func (e *Editor) VisualSelection() (start, end Position, active bool)
- type Mode
- type Motion
- func FindCharBackward(b *Buffer, char rune, count int, till bool) Motion
- func FindCharForward(b *Buffer, char rune, count int, till bool) Motion
- func MatchBracket(b *Buffer) Motion
- func MoveBigWordBackward(b *Buffer, count int) Motion
- func MoveBigWordEnd(b *Buffer, count int) Motion
- func MoveBigWordForward(b *Buffer, count int) Motion
- func MoveDown(b *Buffer, count int) Motion
- func MoveLeft(b *Buffer, count int) Motion
- func MoveParagraphBackward(b *Buffer, count int) Motion
- func MoveParagraphForward(b *Buffer, count int) Motion
- func MoveRight(b *Buffer, count int) Motion
- func MoveToDocumentEnd(b *Buffer) Motion
- func MoveToDocumentStart(b *Buffer) Motion
- func MoveToFirstNonBlank(b *Buffer) Motion
- func MoveToLine(b *Buffer, lineNum int) Motion
- func MoveToLineEnd(b *Buffer) Motion
- func MoveToLineStart(b *Buffer) Motion
- func MoveUp(b *Buffer, count int) Motion
- func MoveWordBackward(b *Buffer, count int) Motion
- func MoveWordEnd(b *Buffer, count int) Motion
- func MoveWordForward(b *Buffer, count int) Motion
- type Operator
- type Position
- type State
- func (s *State) AccumulateCount(digit int)
- func (s *State) ClearOperator()
- func (s *State) EnterCommand()
- func (s *State) EnterInsert()
- func (s *State) EnterVisual(cursorPos int)
- func (s *State) EnterVisualLine(cursorPos int)
- func (s *State) GetCount() int
- func (s *State) HasPendingOperator() bool
- func (s *State) IsVisual() bool
- func (s *State) Reset()
- func (s *State) SetOperator(op Operator)
- func (s *State) VisualRange(cursorPos int) (start, end int)
- type SyntaxStyler
- type TextObject
- type UndoEntry
- type UndoStack
- func (s *UndoStack) CanRedo() bool
- func (s *UndoStack) CanUndo() bool
- func (s *UndoStack) Clear()
- func (s *UndoStack) Redo(currentContent string, currentCursor Position) *UndoEntry
- func (s *UndoStack) Save(content string, cursor Position)
- func (s *UndoStack) Undo(currentContent string, currentCursor Position) *UndoEntry
- type ViewConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer provides vim-style operations on a text buffer.
func (*Buffer) CharUnderCursor ¶
CharUnderCursor returns the character under the cursor.
func (*Buffer) CurrentLine ¶
CurrentLine returns the current line.
func (*Buffer) CurrentLineLen ¶
CurrentLineLen returns the length of the current line.
func (*Buffer) CursorOffset ¶
CursorOffset returns the absolute offset of the cursor in the content.
func (*Buffer) DeleteChar ¶
DeleteChar deletes the character under the cursor.
func (*Buffer) DeleteCharBefore ¶
DeleteCharBefore deletes the character before the cursor (backspace).
func (*Buffer) DeleteLine ¶
DeleteLine deletes the current line.
func (*Buffer) DeleteRange ¶
DeleteRange deletes text between two positions.
func (*Buffer) DeleteToEndOfLine ¶
DeleteToEndOfLine deletes from cursor to end of line.
func (*Buffer) FirstNonBlank ¶
func (b *Buffer) FirstNonBlank()
FirstNonBlank moves cursor to first non-blank character on current line.
func (*Buffer) JoinLines ¶
func (b *Buffer) JoinLines()
JoinLines joins the current line with the next.
func (*Buffer) NewLineAbove ¶
func (b *Buffer) NewLineAbove()
NewLineAbove inserts a new line above and moves cursor.
func (*Buffer) NewLineBelow ¶
func (b *Buffer) NewLineBelow()
NewLine inserts a new line below and moves cursor.
func (*Buffer) PasteBefore ¶
func (b *Buffer) PasteBefore()
PasteBefore inserts yanked text before the cursor.
func (*Buffer) ReplaceChar ¶
ReplaceChar replaces the character under cursor.
func (*Buffer) SetContent ¶
SetContent replaces the entire buffer content.
func (*Buffer) SetCursor ¶
SetCursor sets the cursor position with bounds checking. In normal mode, cursor is clamped to lineLen-1 (on last char).
func (*Buffer) SetCursorFromOffset ¶
SetCursorFromOffset sets cursor position from absolute offset.
func (*Buffer) SetCursorInsert ¶
SetCursorInsert sets cursor position for insert mode (allows col == lineLen).
type Editor ¶
type Editor struct {
// contains filtered or unexported fields
}
Editor is a vim-style text editor component.
func (*Editor) CommandBuffer ¶
CommandBuffer returns the current command buffer (for : commands).
func (*Editor) CursorOffset ¶
CursorOffset returns the absolute cursor offset.
func (*Editor) EnsureCursorVisible ¶
func (e *Editor) EnsureCursorVisible()
EnsureCursorVisible adjusts scroll offset to keep cursor visible.
func (*Editor) IsCommandMode ¶
IsCommandMode returns true if in command mode.
func (*Editor) SetContent ¶
SetContent replaces the buffer content.
func (*Editor) SetCursorInsert ¶
SetCursorInsert sets the cursor position for insert mode (allows col == lineLen).
func (*Editor) SetSyntax ¶
func (e *Editor) SetSyntax(s *SyntaxStyler)
SetSyntax enables syntax highlighting for the editor content.
func (*Editor) View ¶
func (e *Editor) View(cfg ViewConfig) string
View renders the editor content with cursor and selection highlighting.
func (*Editor) VisualSelection ¶
VisualSelection returns the visual selection range, if in visual mode.
type Mode ¶
type Mode int
Mode represents the current vim editing mode.
const ( // ModeNormal is the default mode for navigation and commands. ModeNormal Mode = iota // ModeInsert allows text entry. ModeInsert // ModeVisual allows character-wise selection. ModeVisual // ModeVisualLine allows line-wise selection. ModeVisualLine // ModeCommand is for ex-style commands (e.g., :wq). ModeCommand )
type Motion ¶
type Motion struct {
Start Position
End Position
Linewise bool // True for line-based motions (dd, yy, etc.)
}
Motion represents the result of a motion command.
func FindCharBackward ¶
FindCharBackward finds the count-th occurrence of char backward.
func FindCharForward ¶
FindCharForward finds the count-th occurrence of char forward.
func MatchBracket ¶
MatchBracket implements vim's % motion: jump to matching bracket.
func MoveBigWordBackward ¶
MoveBigWordBackward moves cursor backward by count WORDs.
func MoveBigWordEnd ¶
MoveBigWordEnd moves cursor to end of current/next WORD.
func MoveBigWordForward ¶
MoveBigWordForward moves cursor forward by count WORDs (whitespace-delimited).
func MoveParagraphBackward ¶
MoveParagraphBackward moves to start of previous paragraph.
func MoveParagraphForward ¶
MoveParagraphForward moves to start of next paragraph.
func MoveToDocumentEnd ¶
MoveToDocumentEnd moves cursor to last line of document.
func MoveToDocumentStart ¶
MoveToDocumentStart moves cursor to start of document.
func MoveToFirstNonBlank ¶
MoveToFirstNonBlank moves cursor to first non-blank character.
func MoveToLine ¶
MoveToLine moves cursor to a specific line number (1-indexed).
func MoveToLineEnd ¶
MoveToLineEnd moves cursor to end of line.
func MoveToLineStart ¶
MoveToLineStart moves cursor to start of line (column 0).
func MoveWordBackward ¶
MoveWordBackward moves cursor backward by count words.
func MoveWordEnd ¶
MoveWordEnd moves cursor to end of current/next word.
func MoveWordForward ¶
MoveWordForward moves cursor forward by count words.
type State ¶
type State struct {
Mode Mode
PendingOp Operator
Count int // Numeric count prefix (e.g., 3dw)
PendingMotion bool // Waiting for a motion after operator
FindChar rune // Character for f/F/t/T motions
FindForward bool // Direction for find
FindTill bool // Stop before (t/T) vs on (f/F) the character
LastFindChar rune // Last character used in f/F/t/T
LastFindFwd bool
LastFindTill bool
VisualStart int // Start position for visual mode
CommandBuffer string
// Multi-key sequence state
PendingKey rune // For g (gg), z (zz), etc.
AwaitingChar bool // Waiting for character input (f/F/t/T)
AwaitingReplace bool // Waiting for replacement character (r)
AwaitingTextObj bool // Waiting for text object type (diw, ci", etc.)
TextObjInner bool // Inner vs around for text objects
TextObjOperator Operator // Operator to apply with text object
}
State holds the current vim editing state.
func (*State) AccumulateCount ¶
AccumulateCount accumulates a digit into the count prefix.
func (*State) ClearOperator ¶
func (s *State) ClearOperator()
ClearOperator clears the pending operator.
func (*State) EnterVisual ¶
EnterVisual switches to visual mode.
func (*State) EnterVisualLine ¶
EnterVisualLine switches to visual line mode.
func (*State) HasPendingOperator ¶
HasPendingOperator returns true if there's a pending operator.
func (*State) Reset ¶
func (s *State) Reset()
Reset clears pending operations and returns to normal mode.
func (*State) SetOperator ¶
SetOperator sets a pending operator and waits for motion.
func (*State) VisualRange ¶
VisualRange returns the start and end of the visual selection. The returned range is always ordered (start <= end).
type SyntaxStyler ¶
type SyntaxStyler struct {
// contains filtered or unexported fields
}
SyntaxStyler tokenizes content and provides per-offset styles for rendering. It caches results and only re-tokenizes when content changes.
func NewMarkdownStyler ¶
func NewMarkdownStyler() *SyntaxStyler
NewMarkdownStyler creates a SyntaxStyler configured for markdown.
func (*SyntaxStyler) StyleAt ¶
func (s *SyntaxStyler) StyleAt(offset int) lipgloss.Style
StyleAt returns the style for the character at the given byte offset.
type TextObject ¶
TextObject represents a text selection from a text object.
func AroundBracket ¶
func AroundBracket(b *Buffer, open, close rune) TextObject
AroundBracket selects content including brackets (a(, a), ab, a{, a}, aB, a[, a]).
func AroundQuote ¶
func AroundQuote(b *Buffer, quote rune) TextObject
AroundQuote selects content including quotes (a" or a').
func AroundWord ¶
func AroundWord(b *Buffer) TextObject
AroundWord selects the word under cursor plus surrounding whitespace (aw).
func InnerBracket ¶
func InnerBracket(b *Buffer, open, close rune) TextObject
InnerBracket selects content inside brackets (i(, i), ib, i{, i}, iB, i[, i]).
func InnerQuote ¶
func InnerQuote(b *Buffer, quote rune) TextObject
InnerQuote selects content inside quotes (i" or i').
type UndoEntry ¶
type UndoEntry struct {
Content string // Buffer content before the change
Cursor Position // Cursor position before the change
}
UndoEntry represents a single undoable change.
type UndoStack ¶
type UndoStack struct {
// contains filtered or unexported fields
}
UndoStack manages undo/redo history.
func NewUndoStack ¶
NewUndoStack creates a new undo stack with the given maximum size.
type ViewConfig ¶
type ViewConfig struct {
// Styles
NormalText lipgloss.Style
CursorBlock lipgloss.Style // For normal mode cursor (inverted)
CursorInsert lipgloss.Style // For insert mode cursor position
Selection lipgloss.Style // For visual mode selection
LineNumber lipgloss.Style
CommandLine lipgloss.Style
ShowLineNums bool
}
ViewConfig configures the editor view rendering.
func DefaultViewConfig ¶
func DefaultViewConfig() ViewConfig
DefaultViewConfig returns default styles using the theme package for adaptive colors.