makecols.vim: converting lists to columns made simple
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
9.2 KiB

  1. *makecols.txt* Plugin for converting lists to columns
  2. Author: Levi Olson <http://leviolson.com/>
  3. License: Same terms as Vim itself (see |license|)
  4. This plugin is only available if 'compatible' is not set.
  5. INTRODUCTION *makecols*
  6. This plugin is a tool for converting lists into columns.
  7. Details follow on the exact semantics, but first, consider the following
  8. examples. An asterisk (*) is used to denote the cursor position.
  9. Old text Command New text ~
  10. "Hello *world!" ds" Hello world!
  11. [123+4*56]/2 cs]) (123+456)/2
  12. "Look ma, I'm *HTML!" cs"<q> <q>Look ma, I'm HTML!</q>
  13. if *x>3 { ysW( if ( x>3 ) {
  14. my $str = *whee!; vllllS' my $str = 'whee!';
  15. While a few features of this plugin will work in older versions of Vim,
  16. Vim 7 is recommended for full functionality.
  17. MAPPINGS *surround-mappings*
  18. Delete surroundings is *ds* . The next character given determines the target
  19. to delete. The exact nature of the target is explained in |surround-targets|
  20. but essentially it is the last character of a |text-object|. This mapping
  21. deletes the difference between the "i"nner object and "a"n object. This is
  22. easiest to understand with some examples:
  23. Old text Command New text ~
  24. "Hello *world!" ds" Hello world!
  25. (123+4*56)/2 ds) 123+456/2
  26. <div>Yo!*</div> dst Yo!
  27. Change surroundings is *cs* . It takes two arguments, a target like with
  28. |ds|, and a replacement. *cS* changes surroundings, placing the surrounded
  29. text on its own line(s) like |yS|. Details about the second argument can be
  30. found below in |surround-replacements|. Once again, examples are in order.
  31. Old text Command New text ~
  32. "Hello *world!" cs"' 'Hello world!'
  33. "Hello *world!" cs"<q> <q>Hello world!</q>
  34. (123+4*56)/2 cs)] [123+456]/2
  35. (123+4*56)/2 cs)[ [ 123+456 ]/2
  36. <div>Yo!*</div> cst<p> <p>Yo!</p>
  37. *ys* takes a valid Vim motion or text object as the first object, and wraps
  38. it using the second argument as with |cs|. (It's a stretch, but a good
  39. mnemonic for "ys" is "you surround".)
  40. Old text Command New text ~
  41. Hello w*orld! ysiw) Hello (world)!
  42. As a special case, *yss* operates on the current line, ignoring leading
  43. whitespace.
  44. Old text Command New text ~
  45. Hello w*orld! yssB {Hello world!}
  46. There is also *yS* and *ySS* which indent the surrounded text and place it
  47. on a line of its own.
  48. In visual mode, a simple "S" with an argument wraps the selection. This is
  49. referred to as the *vS* mapping, although ordinarily there will be
  50. additional keystrokes between the v and S. In linewise visual mode, the
  51. surroundings are placed on separate lines and indented. In blockwise visual
  52. mode, each line is surrounded.
  53. A "gS" in visual mode, known as *vgS* , behaves similarly. In linewise visual
  54. mode, the automatic indenting is suppressed. In blockwise visual mode, this
  55. enables surrounding past the end of the line with 'virtualedit' set (there
  56. seems to be no way in Vim Script to differentiate between a jagged end of line
  57. selection and a virtual block selected past the end of the line, so two maps
  58. were needed).
  59. *i_CTRL-G_s* *i_CTRL-G_S*
  60. Finally, there is an experimental insert mode mapping on <C-G>s and <C-S>.
  61. Beware that the latter won't work on terminals with flow control (if you
  62. accidentally freeze your terminal, use <C-Q> to unfreeze it). The mapping
  63. inserts the specified surroundings and puts the cursor between them. If,
  64. immediately after the mapping and before the replacement, a second <C-S> or
  65. carriage return is pressed, the prefix, cursor, and suffix will be placed on
  66. three separate lines. <C-G>S (not <C-G>s) also exhibits this behavior.
  67. TARGETS *surround-targets*
  68. The |ds| and |cs| commands both take a target as their first argument. The
  69. possible targets are based closely on the |text-objects| provided by Vim.
  70. All targets are currently just one character.
  71. Eight punctuation marks, (, ), {, }, [, ], <, and >, represent themselves
  72. and their counterparts. If the opening mark is used, contained whitespace is
  73. also trimmed. The targets b, B, r, and a are aliases for ), }, ], and >
  74. (the first two mirror Vim; the second two are completely arbitrary and
  75. subject to change).
  76. Three quote marks, ', ", `, represent themselves, in pairs. They are only
  77. searched for on the current line.
  78. A t is a pair of HTML or XML tags. See |tag-blocks| for details. Remember
  79. that you can specify a numerical argument if you want to get to a tag other
  80. than the innermost one.
  81. The letters w, W, and s correspond to a |word|, a |WORD|, and a |sentence|,
  82. respectively. These are special in that they have nothing to delete, and
  83. used with |ds| they are a no-op. With |cs|, one could consider them a
  84. slight shortcut for ysi (cswb == ysiwb, more or less).
  85. A p represents a |paragraph|. This behaves similarly to w, W, and s above;
  86. however, newlines are sometimes added and/or removed.
  87. REPLACEMENTS *surround-replacements*
  88. A replacement argument is a single character, and is required by |cs|, |ys|,
  89. and |vS|. Undefined replacement characters (with the exception of alphabetic
  90. characters) default to placing themselves at the beginning and end of the
  91. destination, which can be useful for characters like / and |.
  92. If either ), }, ], or > is used, the text is wrapped in the appropriate pair
  93. of characters. Similar behavior can be found with (, {, and [ (but not <),
  94. which append an additional space to the inside. Like with the targets above,
  95. b, B, r, and a are aliases for ), }, ], and >. To fulfill the common need for
  96. code blocks in C-style languages, <C-}> (which is really <C-]>) adds braces on
  97. lines separate from the content.
  98. If t or < is used, Vim prompts for an HTML/XML tag to insert. You may specify
  99. attributes here and they will be stripped from the closing tag. If replacing a
  100. tag, its attributes are kept in the new tag. End your input with > to discard
  101. the those attributes. If <C-T> is used, the tags will appear on lines by
  102. themselves.
  103. If s is used, a leading but not trailing space is added. This is useful for
  104. removing parentheses from a function call with csbs.
  105. CUSTOMIZING *surround-customizing*
  106. The following adds a potential replacement on "-" (ASCII 45) in PHP files.
  107. (To determine the ASCII code to use, :echo char2nr("-")). The carriage
  108. return will be replaced by the original text.
  109. >
  110. autocmd FileType php let b:surround_45 = "<?php \r ?>"
  111. <
  112. This can be used in a PHP file as in the following example.
  113. Old text Command New text ~
  114. print "Hello *world!" yss- <?php print "Hello world!" ?>
  115. Additionally, one can use a global variable for globally available
  116. replacements.
  117. >
  118. let g:surround_45 = "<% \r %>"
  119. let g:surround_61 = "<%= \r %>"
  120. <
  121. Advanced, experimental, and subject to change: One can also prompt for
  122. replacement text. The syntax for this is to surround the replacement in pairs
  123. of low numbered control characters. If this sounds confusing, that's because
  124. it is (but it makes the parsing easy). Consider the following example for a
  125. LaTeX environment on the "l" replacement.
  126. >
  127. let g:surround_108 = "\\begin{\1environment: \1}\r\\end{\1\1}"
  128. <
  129. When this replacement is used, the user is prompted with an "environment: "
  130. prompt for input. This input is inserted between each set of \1's.
  131. Additional inputs up to \7 can be used.
  132. Furthermore, one can specify a regular expression substitution to apply.
  133. >
  134. let g:surround_108 = "\\begin{\1environment: \1}\r\\end{\1\r}.*\r\1}"
  135. <
  136. This will remove anything after the first } in the input when the text is
  137. placed within the \end{} slot. The first \r marks where the pattern begins,
  138. and the second where the replacement text begins.
  139. Here's a second example for creating an HTML <div>. The substitution cleverly
  140. prompts for an id, but only adds id="" if it is non-blank. You may have to
  141. read this one a few times slowly before you understand it.
  142. >
  143. let g:surround_{char2nr("d")} = "<div\1id: \r..*\r id=\"&\"\1>\r</div>"
  144. <
  145. Inputting text replacements is a proof of concept at this point. The ugly,
  146. unintuitive interface and the brevity of the documentation reflect this.
  147. Finally, It is possible to always append a string to surroundings in insert
  148. mode (and only insert mode). This is useful with certain plugins and mappings
  149. that allow you to jump to such markings.
  150. >
  151. let g:surround_insert_tail = "<++>"
  152. <
  153. ISSUES *surround-issues*
  154. Vim could potentially get confused when deleting/changing occurs at the very
  155. end of the line. Please report any repeatable instances of this.
  156. Do we need to use |inputsave()|/|inputrestore()| with the tag replacement?
  157. Indenting is handled haphazardly. Need to decide the most appropriate
  158. behavior and implement it. Right now one can do :let b:surround_indent = 1
  159. (or the global equivalent) to enable automatic re-indenting by Vim via |=|;
  160. should this be the default?
  161. vim:tw=78:ts=8:ft=help:norl: