visualrepeat.txt 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. *visualrepeat.txt* Repeat command extended to visual mode.
  2. VISUALREPEAT by Ingo Karkat
  3. *visualrepeat.vim*
  4. description |visualrepeat-description|
  5. usage |visualrepeat-usage|
  6. installation |visualrepeat-installation|
  7. integration |visualrepeat-integration|
  8. limitations |visualrepeat-limitations|
  9. known problems |visualrepeat-known-problems|
  10. todo |visualrepeat-todo|
  11. history |visualrepeat-history|
  12. ==============================================================================
  13. DESCRIPTION *visualrepeat-description*
  14. This plugin defines repetition of Vim built-in normal mode commands via |.|
  15. for visual mode. Additionally, it offers functions like the popular repeat.vim
  16. plugin that allow mappings to be repeated in visual mode, too.
  17. VISUAL MODE REPETITION *
  18. This extends the built-in normal mode repeat |.| to visual mode.
  19. VISUAL MODE MAPPING REPETITION *
  20. Like with repeat.vim for normal mode, visual mode mappings can register a
  21. <Plug> mapping to be used for visual mode repetition.
  22. Likewise, normal mode mappings can (in addition to the repeat.vim registration
  23. of a normal mode mapping) register a visual mode mapping with visualrepeat.vim
  24. that will be repeated in visual mode.
  25. Operator-pending mappings end with |g@| and repeat naturally; i.e. Vim
  26. re-applies the 'opfunc' on the equivalent text (but at the current cursor
  27. position). But without a call to repeat#set(), it is impossible to repeat this
  28. operator-pending mapping to the current visual selection. Plugins cannot call
  29. repeat#set() in their operator-pending mapping, because then Vim's built-in
  30. repeat would be circumvented, the full mapping ending with g@ would be
  31. re-executed, and the repetition would then wait for the {motion}, what is not
  32. wanted.
  33. Therefore, this plugin offers a separate visualrepeat#set() function that can
  34. be invoked for operator-pending mappings. It can also be invoked for
  35. normal-mode mappings that have already called repeat#set(), and may override
  36. that mapping with a special repeat mapping for visual mode repeats. Together
  37. with the remapped {Visual}. command, this allows repetition - similar to what
  38. the built-in Vim commands do - across normal, operator-pending and visual
  39. mode.
  40. SOURCE *
  41. - Based on vimtip #1142, Repeat last command and put cursor at start of change
  42. http://vim.wikia.com/wiki/Repeat_last_command_and_put_cursor_at_start_of_change
  43. - The client interface and implementation has been based on repeat.vim
  44. (vimscript #2136) by Tim Pope.
  45. RELATED WORKS *
  46. - repeat.vim (vimscript #2136) has been the basis for this plugin and should
  47. be used in conjunction with visualrepeat.vim. (Otherwise, you'd have visual
  48. mode repeat, but no repeat in normal mode.)
  49. ==============================================================================
  50. USAGE *visualrepeat-usage*
  51. *v_.*
  52. {Visual}. Repeat last change in all visually selected lines.
  53. - characterwise: Start from cursor position.
  54. - linewise: Each line separately, starting from the
  55. current column (usually the first in this mode).
  56. - blockwise: Only the selected text. This is
  57. implemented by temporarily duplicating the selection
  58. to separate lines and repeating over those, starting
  59. from the first column.
  60. Note: If the last normal mode command included a
  61. {motion} (e.g. g~e), the repetition will also move
  62. exactly over this {motion}, NOT the visual selection!
  63. It is thus best to repeat commands that work on the
  64. entire line (e.g. g~$).
  65. ==============================================================================
  66. INSTALLATION *visualrepeat-installation*
  67. This script is packaged as a |vimball|. If you have the "gunzip" decompressor
  68. in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress
  69. the archive first, e.g. using WinZip. Inside Vim, install by sourcing the
  70. vimball or via the |:UseVimball| command. >
  71. vim visualrepeat*.vmb.gz
  72. :so %
  73. To uninstall, use the |:RmVimball| command.
  74. DEPENDENCIES *visualrepeat-dependencies*
  75. - Requires Vim 7.0 or higher.
  76. - repeat.vim (vimscript #2136) plugin (highly recommended)
  77. - |ingo-library.vim| plugin (vimscript #4433), version 1.013 or higher;
  78. optional, for blockwise repeat only
  79. ==============================================================================
  80. INTEGRATION *visualrepeat-integration*
  81. This plugin is meant to be used together with repeat.vim.
  82. This plugin has helper functions that plugins with cross-repeat functionality
  83. can use in their normal mode repeat mappings of repeated visual mode mappings.
  84. With this, you save work and allow for a consistent user experience.
  85. Define your normal mode repeat mapping like this: >
  86. nnoremap <silent> <Plug>(MyPluginVisual)
  87. \ :<C-u>execute 'normal!' visualrepeat#reapply#VisualMode(0)<Bar>
  88. \call MyPlugin#Operator('visual', "\<lt>Plug>(MyPluginVisual)")<CR>
  89. If your plugin uses a passed [count] (i.e. the count is not only used to
  90. determine the text area the mapping is applied to), you need to define a
  91. mapping: >
  92. vnoremap <silent> <expr> <SID>(ReapplyRepeatCount) visualrepeat#reapply#RepeatCount()
  93. and apply the function followed by the mapping like this: >
  94. nnoremap <silent> <script> <Plug>(MyPluginVisual)
  95. \ :<C-u>execute 'normal!' visualrepeat#reapply#VisualMode(1)<CR>
  96. \<SID>(ReapplyRepeatCount)
  97. \:<C-u>call MyPlugin#Operator('visual', v:count, "\<lt>Plug>(MyPluginVisual)")<CR>
  98. If you want to support running without visualrepeat.vim, too, provide a
  99. wrapper that defaults to |1v|: >
  100. function! s:VisualMode()
  101. let l:keys = "1v\<Esc>"
  102. silent! let l:keys = visualrepeat#reapply#VisualMode(0)
  103. return l:keys
  104. endfunction
  105. nnoremap <silent> <Plug>(MyPluginVisual)
  106. \ :<C-u>execute 'normal!' <SID>VisualMode()<Bar>
  107. \call MyPlugin#Operator('visual', "\<lt>Plug>(MyPluginVisual)")<CR>
  108. <
  109. ==============================================================================
  110. LIMITATIONS *visualrepeat-limitations*
  111. KNOWN PROBLEMS *visualrepeat-known-problems*
  112. TODO *visualrepeat-todo*
  113. IDEAS *visualrepeat-ideas*
  114. ==============================================================================
  115. HISTORY *visualrepeat-history*
  116. 1.30 15-Nov-2013
  117. - ENH: When repeating over multiple lines / a blockwise selection, keep track
  118. of added or deleted lines, and only repeat exactly on the selected lines.
  119. Thanks to Israel Chauca for sending a patch!
  120. - When a repeat on a blockwise selection has introduced additional lines,
  121. append those properly indented instead of omitting them.
  122. - With linewise and blockwise repeat, set the change marks '[,'] to the
  123. changed selection. With the latter, one previously got "E19: Mark has
  124. invalid line number" due to the removed temporary range.
  125. 1.20 14-Nov-2013
  126. - ENH: Implement blockwise repeat through temporarily moving the block to a
  127. temporary range at the end of the buffer, like the vis.vim plugin. This
  128. feature requires the ingo-library. *** You need to separately install
  129. ingo-library (vimscript #4433) version 1.013 (or higher)! ***
  130. 1.10 05-Sep-2013
  131. - Check for existence of actual visual mode mapping; do not accept a select
  132. mode mapping, because we're applying it to a visual selection.
  133. - Pass through a [count] to the :normal . command.
  134. - Add visualrepeat#reapply#VisualMode() and visualrepeat#reapply#RepeatCount()
  135. helper functions that plugins can use in their normal mode repeat mappings
  136. of repeated visual mode mappings.
  137. - Minor: Make substitute() robust against 'ignorecase'.
  138. - ENH: Use the current cursor virtual column when repeating in linewise visual
  139. mode. Inspired by
  140. http://stackoverflow.com/questions/18610564/vim-is-possible-to-use-dot-command-in-visual-block-mode
  141. - Abort further commands on error by using echoerr inside the mapping.
  142. 1.03 21-Feb-2013
  143. REGRESSION: Fix in 1.02 does not repeat recorded register when the mappings in
  144. repeat.vim and visualrepeat.vim differ.
  145. 1.02 27-Dec-2012
  146. BUG: "E121: Undefined variable: g:repeat_sequence" when using visual repeat of
  147. a mapping using registers without having used repeat.vim beforehand.
  148. 1.01 05-Apr-2012
  149. FIX: Avoid error about undefined g:repeat_reg when (a proper version of)
  150. repeat.vim isn't available.
  151. 1.00 14-Dec-2011
  152. First published version.
  153. 0.01 17-Mar-2011
  154. Split off into dedicated plugin.
  155. 0.00 30-Jul-2008
  156. Started development.
  157. ==============================================================================
  158. Copyright: (C) 2008-2013 Ingo Karkat
  159. The VIM LICENSE applies to this plugin; see |copyright|.
  160. Maintainer: Ingo Karkat <ingo@karkat.de>
  161. ==============================================================================
  162. vim:tw=78:ts=8:ft=help:norl: