$ show AndrewRadev/splitjoin.vim
This is a Vim plugin that provides keybindings (gS/gJ) to split single-line code constructs into multiple lines and join them back, covering 30+ languages. The architecture uses a callback-based system where per-filetype scripts register split/join callbacks in buffer-local variables, and the main engine (autoload/sj.vim) iterates through them. The codebase is modular and well-structured, with reusable utility functions for text replacement, cursor management, and parsing (e.g., sj#argparser). Each language has dedicated autoload files that implement specific transformations (e.g., hashes, blocks, if-clauses). The plugin supports customization via many settings and alignment through external plugins. It is thoroughly tested with RSpec/Vimrunner and is actively maintained.
The LLM identified 5 files worth highlighting for reuse:
Core utility module providing generic Vim functions for cursor stack management (sj#PushCursor/PopCursor), text replacement via motions (sj#ReplaceMotion), line/column replacements, string trimming, search with skip pattern, and alignment helpers. These functions are used across all language-specific split/join modules and could be extracted for use in any Vim plugin that needs robust text manipulation.
A generic constructor-based argument parser that handles nested brackets, string delimiters, and comma separation. It uses a dictionary with methods (Process, PushArg, JumpPair, etc.) to simulate object-oriented programming in Vimscript. This parser is extended by language-specific parsers (ruby, json, rust_struct, etc.) and provides a reusable pattern for parsing comma-separated lists in any domain.
Comprehensive implementation of split/join for Ruby constructs: if-clauses, hashes, blocks, method arguments, arrays, strings/heredocs, module namespaces, and more. It demonstrates non-trivial parsing using the Ruby-specific argument parser (sj#argparser#ruby) and handles many edge cases (comments, interpolation, cursor position). This is a reference implementation for adding a new language to the plugin.
Splits and joins Rust-specific constructs: struct literals, match expressions, closures, question mark operators, import lists, and if-let blocks. Uses advanced bracket jumping (sj#JumpBracketsTill) and a specialized struct parser (sj#argparser#rust_struct) to handle attributes, visibility modifiers, and trailing commas. Demonstrates high craftsmanship in handling complex nested syntax.
Handles split/join for YAML arrays and maps, including support for nested structures, complex keys, comments, and indentation management. Contains helper functions for reading nested children, splitting array bodies respecting strings and sub-containers, and handling array-in-array and map-in-array hierarchies. This is a well-isolated module that solves a recurring data problem (YAML formatting) with careful edge-case handling.