MCPcopy Index your code
hub / github.com/codeaashu/claude-code / handleVimInput

Function handleVimInput

src/hooks/useVimInput.ts:175–295  ·  view source on GitHub ↗
(rawInput: string, key: Key)

Source from the content-addressed store, hash-verified

173 }
174
175 function handleVimInput(rawInput: string, key: Key): void {
176 const state = vimStateRef.current
177 // Run inputFilter in all modes so stateful filters disarm on any key,
178 // but only apply the transformed input in INSERT — NORMAL-mode command
179 // lookups expect single chars and a prepended space would break them.
180 const filtered = inputFilter ? inputFilter(rawInput, key) : rawInput
181 const input = state.mode === 'INSERT' ? filtered : rawInput
182 const cursor = Cursor.fromText(props.value, props.columns, textInput.offset)
183
184 if (key.ctrl) {
185 textInput.onInput(input, key)
186 return
187 }
188
189 // NOTE(keybindings): This escape handler is intentionally NOT migrated to the keybindings system.
190 // It's vim's standard INSERT->NORMAL mode switch - a vim-specific behavior that should not be
191 // configurable via keybindings. Vim users expect Esc to always exit INSERT mode.
192 if (key.escape && state.mode === 'INSERT') {
193 switchToNormalMode()
194 return
195 }
196
197 // Escape in NORMAL mode cancels any pending command (replace, operator, etc.)
198 if (key.escape && state.mode === 'NORMAL') {
199 vimStateRef.current = { mode: 'NORMAL', command: { type: 'idle' } }
200 return
201 }
202
203 // Pass Enter to base handler regardless of mode (allows submission from NORMAL)
204 if (key.return) {
205 textInput.onInput(input, key)
206 return
207 }
208
209 if (state.mode === 'INSERT') {
210 // Track inserted text for dot-repeat
211 if (key.backspace || key.delete) {
212 if (state.insertedText.length > 0) {
213 vimStateRef.current = {
214 mode: 'INSERT',
215 insertedText: state.insertedText.slice(
216 0,
217 -(lastGrapheme(state.insertedText).length || 1),
218 ),
219 }
220 }
221 } else {
222 vimStateRef.current = {
223 mode: 'INSERT',
224 insertedText: state.insertedText + input,
225 }
226 }
227 textInput.onInput(input, key)
228 return
229 }
230
231 if (state.mode !== 'NORMAL') {
232 return

Callers

nothing calls this directly

Calls 4

lastGraphemeFunction · 0.85
createOperatorContextFunction · 0.85
transitionFunction · 0.85
fromTextMethod · 0.80

Tested by

no test coverage detected