Skip to content

vimscript

This directory provides comprehensive Talon support for Vimscript development. It coordinates syntax-specific scoping, native functions, operators, and structural syntax formatting to make writing Vimscript by voice efficient and context-aware.

The functionality is split across two core files:

  • vimscript.py: Establishes the underlying vocabulary, syntax rules, and formatters using Python.
  • vimscript.talon: Maps natural language commands to text actions, setting up the context for Vimscript files.

How It Works

When a file with the Vimscript language type (code.language: vimscript) is active, Talon dynamically loads the rules in this directory.

1. Language Scoping and Variables

Vimscript relies heavily on prefix-based variable scoping (e.g., g: for global, s: for script-local, a: for arguments). vimscript.py defines a registry mapping spoken forms to these prefixes:

  • "argument" or "arg" $\rightarrow$ a:
  • "buffer" or "buf" $\rightarrow$ b:
  • "window" or "win" $\rightarrow$ w:
  • "tab" $\rightarrow$ t:
  • "global" $\rightarrow$ g:
  • "local" $\rightarrow$ l:
  • "script local" $\rightarrow$ s:

These are exposed as a custom capture (<user.vimscript_scope>), which is then utilized in vimscript.talon to declare or assign variables. For example, saying "assign global variable my setting" will output let g:my_setting.

2. Native Functions

Commonly used built-in Vimscript functions are registered for fast invocation:

  • "string len" $\rightarrow$ strlen
  • "get line" $\rightarrow$ getline
  • "set line" $\rightarrow$ setline
  • "length" $\rightarrow$ len

The <user.vimscript_functions> capture handles inserting these function names directly.

3. Standard Interface Implementations

vimscript.py integrates Vimscript with Talon's global coding patterns (like user.code_operators) by overriding default actions:

  • Operators: Maps assignment (=, +=, -=, *=, /=) and basic mathematical operations (+, -, *, /).
  • Function Declarations: Hooks into Talon's snippet framework to output formatted function declarations (e.g., public, private, and protected functions mapped to SNAKE_CASE naming formatters).

4. Control Flow and Syntax Blocks

vimscript.talon defines voice commands for the structural keywords of the language. This allows you to close out loops and conditionals rapidly without manual typing:

  • "state command" $\rightarrow$ command!
  • "state end if" $\rightarrow$ endif
  • "state end for" $\rightarrow$ endfor
  • "state end while" $\rightarrow$ endwhile
  • "state end function" $\rightarrow$ endfunction