-
Notifications
You must be signed in to change notification settings - Fork 2
Create text transformation mappings and commands.
vim-scripts/TextTransform
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This is a mirror of http://www.vim.org/scripts/script.php?script_id=4005 DESCRIPTION This plugin allows you to build your own text transformations. You only supply the transformation algorithm in the form of a Vim function that takes a string and returns the transformed text (think substitute()), and TextTransform will create all appropriate mappings and / or commands with a single call! Do you often perform the same :substitute commands over and over again? You may be able to save yourself a lot of typing by creating custom commands and mappings for it. Because the mappings (like built-in Vim commands such as gU or g?) are applicable to text moved over by {motion}, entire lines, and the visual selection, you'll also have way more flexibility and places where you can apply them (compared to the line-based range of :substitute). RELATED WORKS - Idea, design and implementation are based on Tim Pope's unimpaired.vim plugin (vimscript #1590). It implements XML, URL and C String encoding mappings, but isn't extensible with other algorithms. The TextTransform plugin enhances unimpaired's transformation function with handling of text objects and a list of selection fallbacks, and allows to not only create mappings, but also transformation commands. USAGE TextTransform#MakeMappings( {mapArgs}, {key}, {algorithm} [, {selectionModes}] ) Create normal and visual mode mappings that apply {algorithm} to the text covered by {motion}, [count] line(s), and the visual selection. TextTransform#MakeCommand( {commandOptions}, {commandName}, {algorithm} [, {options}] ) Create a custom command {commandName} that takes a range (defaulting to the current line), and applies {algorithm} to the line(s). TextTransform#MakeSelectionCommand( {commandOptions}, {commandName}, {algorithm}, {selectionModes} ) Create a custom command {commandName} that applies {algorithm} on the TextTransform-selectionModes specified by {selectionModes}, or the current visual selection (when invoked from visual mode). EXAMPLE Here's a stupid transformation function that replaces all alphabetic characters with "X": function! BlankOut( text ) return substitute(a:text, '\a', 'X', 'g') endfunction With this, this single call: call TextTransform#MakeMappings('', '<Leader>x', 'BlankOut') creates this set of mappings: <Leader>x{motion} transforms the text covered by {motion} <Leader>xx transforms [count] line(s) {Visual}<Leader>x transforms the visual selection You can set up a command for this transformation just as easily: call TextTransform#MakeCommand('', 'TextBlankOut', 'BlankOut') so you can blank out the next three lines via :.,.+2TextBlankOut
About
Create text transformation mappings and commands.
Resources
Stars
Watchers
Forks
Packages 0
No packages published