Skip to content
Newer
Older
100644 63 lines (49 sloc) 2.89 KB
46bd1c6 Version 1.00: Initial upload
Ingo Karkat authored
1 This is a mirror of http://www.vim.org/scripts/script.php?script_id=4005
2
3 DESCRIPTION
4 This plugin allows you to build your own text transformations. You only supply
5 the transformation algorithm in the form of a Vim function that takes a string
6 and returns the transformed text (think substitute()), and TextTransform
7 will create all appropriate mappings and / or commands with a single call!
8
9 Do you often perform the same :substitute commands over and over again? You
10 may be able to save yourself a lot of typing by creating custom commands and
11 mappings for it. Because the mappings (like built-in Vim commands such as gU
12 or g?) are applicable to text moved over by {motion}, entire lines, and the
13 visual selection, you'll also have way more flexibility and places where you
14 can apply them (compared to the line-based range of :substitute).
15
16 RELATED WORKS
17 - Idea, design and implementation are based on Tim Pope's unimpaired.vim
18 plugin (vimscript #1590). It implements XML, URL and C String encoding
19 mappings, but isn't extensible with other algorithms.
20 The TextTransform plugin enhances unimpaired's transformation function with
21 handling of text objects and a list of selection fallbacks, and allows to
22 not only create mappings, but also transformation commands.
23
24
25 USAGE
26 TextTransform#MakeMappings( {mapArgs}, {key}, {algorithm} [, {selectionModes}] )
27
28 Create normal and visual mode mappings that apply
29 {algorithm} to the text covered by {motion}, [count]
30 line(s), and the visual selection.
31
32 TextTransform#MakeCommand( {commandOptions}, {commandName}, {algorithm} [, {options}] )
33
34 Create a custom command {commandName} that takes a
35 range (defaulting to the current line), and applies
36 {algorithm} to the line(s).
37
38 TextTransform#MakeSelectionCommand( {commandOptions}, {commandName}, {algorithm}, {selectionModes} )
39
40 Create a custom command {commandName} that applies
41 {algorithm} on the TextTransform-selectionModes
42 specified by {selectionModes}, or the current visual
43 selection (when invoked from visual mode).
44
45 EXAMPLE
46 Here's a stupid transformation function that replaces all alphabetic
47 characters with "X":
48 function! BlankOut( text )
49 return substitute(a:text, '\a', 'X', 'g')
50 endfunction
51 With this, this single call:
52 call TextTransform#MakeMappings('', '<Leader>x', 'BlankOut')
53 creates this set of mappings:
54
55 <Leader>x{motion} transforms the text covered by {motion}
56 <Leader>xx transforms [count] line(s)
57 {Visual}<Leader>x transforms the visual selection
58
59 You can set up a command for this transformation just as easily:
60 call TextTransform#MakeCommand('', 'TextBlankOut', 'BlankOut')
61 so you can blank out the next three lines via
62 :.,.+2TextBlankOut
Something went wrong with that request. Please try again.