home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vim53os2.zip / vim-5.3 / doc / visual.txt < prev    next >
Text File  |  1998-08-30  |  14KB  |  350 lines

  1. *visual.txt*    For Vim version 5.3.  Last modification: 1998 Aug 17
  2.  
  3.  
  4.           VIM REFERENCE MANUAL    by Bram Moolenaar
  5.  
  6.  
  7. Visual mode                    *Visual-mode* *visual-mode*
  8.  
  9. Visual mode is a flexible and easy way to select a piece of text for an
  10. operator.  It is the only way to select a block of text.
  11.  
  12. 1. Using Visual mode            |visual-use|
  13. 2. Starting and stopping Visual mode    |visual-start|
  14. 3. Changing the Visual area        |visual-change|
  15. 4. Operating on the Visual area        |visual-operators|
  16. 5. Repeating                |visual-repeat|
  17. 6. Examples                |visual-examples|
  18. 7. Select mode                |Select-mode|
  19.  
  20. {Vi has no Visual mode, the name "visual" is used for Normal mode, to
  21. distinguish it from Ex mode}
  22.  
  23. ==============================================================================
  24. 1. Using Visual mode                    *visual-use*
  25.  
  26. Using Visual mode consists of three parts:
  27. 1. Mark the start of the text with "v", "V" or CTRL-V.
  28.    The character under the cursor will be used as the start.
  29. 2. Move to the end of the text.
  30.    The text from the start of the Visual mode up to and including the
  31.    character under the cursor is highlighted.
  32. 3. Hit an operator.
  33.    The highlighted characters will be operated upon.
  34.  
  35. The 'highlight' option can be used to set the display mode to use for
  36. highlighting in Visual mode.
  37.  
  38. The highlighted text includes the character under the cursor.  On terminals
  39. where it is possible to make the cursor invisible the cursor position is
  40. also highlighted.  On terminals where this is not possible the cursor is
  41. displayed normally.  If your cursor cannot be made invisible and you want Vim
  42. to highlight the character under the cursor anyway, you could set the 't_cv'
  43. and 't_ci' options to something harmless, for example:
  44. >    :set t_cv=^[^[ t_ci=^[^[
  45.  
  46. With "v" the text before the start position and after the end position will
  47. not be highlighted.  However, All uppercase and non-alpha operators, except
  48. "~", will work on whole lines anyway.  See the list of operators below.
  49.  
  50.                             *visual-block*
  51. With CTRL-V (blockwise Visual mode) the highlighted text will be a rectangle
  52. between start position and the cursor.  However, some operators work on whole
  53. lines anyway (see the list below).  The change and substitute operators will
  54. delete the highlighted text and then start insertion at the top left
  55. position.
  56.  
  57. ==============================================================================
  58. 2. Starting and stopping Visual mode            *visual-start*
  59.  
  60.                         *v* *characterwise-visual*
  61. v            start Visual mode per character.
  62.  
  63.                         *V* *linewise-visual*
  64. V            start Visual mode linewise.
  65.  
  66.                         *CTRL-V* *blockwise-visual*
  67. CTRL-V            start Visual mode blockwise.
  68.  
  69. If you use <Esc>, click the left mouse button or use any command that
  70. does a jump to another buffer while in Visual mode, the highlighting stops
  71. and no text is affected.  Also when you hit "v" in characterwise Visual mode,
  72. "CTRL-V" in blockwise Visual mode or "V" in linewise Visual mode.  If you hit
  73. CTRL-Z the highlighting stops and the editor is suspended or a new shell is
  74. started |CTRL-Z|.
  75.  
  76.           new mode after typing:        *v_v* *v_CTRL-V* *v_V*
  77. old mode         "v"          "CTRL-V"             "V"    ~
  78.  
  79. Normal            Visual       blockwise Visual      linewise Visual
  80. Visual            Normal       blockwise Visual      linewise Visual
  81. blockwise Visual    Visual       Normal          linewise Visual
  82. linewise Visual     Visual       blockwise Visual      Normal
  83.  
  84.                             *gv* *v_gv*
  85. gv            Start Visual mode with the same area as the previous
  86.             area and the same mode.  In Visual mode the current and
  87.             the previous Visual area are exchanged.
  88.  
  89.                             *<LeftMouse>*
  90. <LeftMouse>        Set the current cursor position.  If Visual mode is
  91.             active it is stopped.  Only when 'mouse' option is
  92.             contains 'n' or 'a'.  If the position is within 'so'
  93.             lines from the last line on the screen the text is
  94.             scrolled up.  If the position is within 'so' lines from
  95.             the first line on the screen the text is scrolled
  96.             down.
  97.  
  98.                             *<RightMouse>*
  99. <RightMouse>        Start Visual mode if it is not active.  The text from
  100.             the cursor position to the position of the click is
  101.             highlighted.  If Visual mode was already active move
  102.             the start or end of the highlighted text, which ever
  103.             is closest, to the position of the click.  Only when
  104.             'mouse' option contains 'n' or 'a'.
  105.  
  106.             Note: when 'mousemodel' is set to "popup",
  107.             <S-LeftMouse> has to be used instead of <RightMouse>.
  108.  
  109.                             *<LeftRelease>*
  110. <LeftRelease>        This works like a <LeftMouse>, if it is not a
  111.             the same position as <LeftMouse>.  In an xterm you
  112.             won't see the selected area until the button is
  113.             released.  Only when 'mouse' option contains 'n' or
  114.             'a'.
  115.  
  116. If Visual mode is not active and the "v", "V" or CTRL-V is preceded with a
  117. count, the size of the previously highlighted area is used for a start.  You
  118. can then move the end of the highlighted area and give an operator.  The type
  119. of the old area is used (character, line or blockwise).
  120. - Linewise Visual mode: The number of lines is multiplied with the count.
  121. - Blockwise Visual mode: The number of lines and columns is multiplied with
  122.   the count.
  123. - Normal Visual mode within one line: The number of characters is multiplied
  124.   with the count.
  125. - Normal Visual mode with several lines: The number of lines is multiplied
  126.   with the count, in the last line the same number of characters is used as
  127.   in the last line in the previously highlighted area.
  128. The start of the text is the Cursor position.  If the "$" command was used as
  129. one of the last commands to extend the highlighted text, the area will be
  130. extended to the rightmost column of the longest line.
  131.  
  132. If you want to highlight exactly the same area as the last time, you can use
  133. "gv" |gv| |v_gv|.
  134.  
  135.                             *v_CTRL-C*
  136. CTRL-C            In Visual mode: Stop Visual mode.  When insert mode is
  137.             pending (the mode message shows
  138.             "-- (insert) VISUAL --"), it is also stopped.
  139.  
  140. ==============================================================================
  141. 3. Changing the Visual area                *visual-change*
  142.  
  143.                             *v_o*
  144. o            Go to Other end of highlighted text: The current
  145.             cursor position becomes the start of the highlighted
  146.             text and the cursor is moved to the other end of the
  147.             highlighted text.  The highlighted area remains the
  148.             same.
  149.  
  150.                             *v_O*
  151. O            Go to Other end of highlighted text.  This is like
  152.             "o", but in Visual block mode the cursor moves to the
  153.             other corner in the same line.  When the corner is at
  154.             a character that occupies more than one position on
  155.             the screen (e.g., a <Tab>), the highlighted text may
  156.             change.
  157.  
  158.                             *v_$*
  159. When the "$" command is used with blockwise Visual mode, the right end of the
  160. highlighted text will be determined by the longest highlighted line.  This
  161. stops when a motion command is used that does not move straight up or down.
  162.  
  163. For moving the end of the block many commands can be used, but you cannot
  164. use Ex commands, commands that make changes or abandon the file.  Commands
  165. (starting with) ".pPiIaAO&", CTRL-^, "Z", CTRL-], CTRL-T, CTRL-R, CTRL-I
  166. and CTRL-O cause a beep and Visual mode continues.
  167.  
  168.  
  169. ==============================================================================
  170. 4. Operating on the Visual area                *visual-operators*
  171.  
  172. The operators that can be used are:
  173.     ~    switch case                    |v_~|
  174.     d    delete                        |v_d|
  175.     c    change                        |v_c|
  176.     y    yank                        |v_y|
  177.     >    shift right (1)(*)                |v_>|
  178.     <    shift left (1)(*)                |v_<|
  179.     !    filter through external command (1)        |v_!|
  180.     =    filter through 'equalprg' option command (1)    |v_=|
  181.     gq    format lines to 'textwidth' length (1)        |v_gq|
  182.  
  183. The objects that can be used are:
  184.     aw    a word (with white space)            |v_aw|
  185.     iw    inner word                    |v_iw|
  186.     aW    a WORD (with white space)            |v_aW|
  187.     iW    inner WORD                    |v_iW|
  188.     as    a sentence (with white space)            |v_as|
  189.     is    inner sentence                    |v_is|
  190.     ap    a paragraph (with white space)            |v_ap|
  191.     ip    inner paragraph                    |v_ip|
  192.     ab    a () block (with braces)            |v_ab|
  193.     ib    inner () block                    |v_ib|
  194.     aB    a {} block (with brackets)            |v_aB|
  195.     iB    inner {} block                    |v_iB|
  196.  
  197. Additionally the following commands can be used:
  198.     :    start ex command for highlighted lines (1)    |v_:|
  199.     r    change                        |v_r|
  200.     s    change                        |v_s|
  201.     C    change (2)                    |v_C|
  202.     S    change (2)                    |v_S|
  203.     R    change (2)                    |v_R|
  204.     x    delete                        |v_x|
  205.     D    delete (3)                    |v_D|
  206.     X    delete (2)                    |v_X|
  207.     Y    yank (2)                    |v_Y|
  208.     J    join (1)                    |v_J|
  209.     U    make uppercase                    |v_U|
  210.     u    make lowercase                    |v_u|
  211.     ^]    find tag                    |v_CTRL-]|
  212.  
  213. (1): Always whole lines, see |:visual_example|.
  214. (2): Whole lines when not using CTRL-V.
  215. (3): Whole lines when not using CTRL-V, delete until the end of the line when
  216.      using CTRL-V.
  217. (*): In a future a blockwise shift will move the block only, not whole
  218.      lines.
  219.  
  220. Note that the ":vmap" command can be used to specifically map keys in Visual
  221. mode.
  222.  
  223. If you want to give a register name using the """ command, do this just before
  224. typing the operator character: "v{move-around}"xd".
  225.  
  226. If you want to give a count to the command, do this just before typing the
  227. operator character: "v{move-around}3>" (move lines 3 indents to the right).
  228.  
  229.                             *{move-around}*
  230. The {move-around} is any sequence of movement commands.  Note the difference
  231. with {motion}, which is only ONE movement command.
  232.  
  233. ==============================================================================
  234. 5. Repeating                        *visual-repeat*
  235.  
  236. When repeating a Visual mode operator, the operator will be applied to the
  237. same amount of text as the last time:
  238. - Linewise Visual mode: The same number of lines.
  239. - Blockwise Visual mode: The same number of lines and columns.
  240. - Normal Visual mode within one line: The same number of characters.
  241. - Normal Visual mode with several lines: The same number of lines, in the
  242.   last line the same number of characters as in the last line the last time.
  243. The start of the text is the Cursor position.  If the "$" command was used as
  244. one of the last commands to extend the highlighted text, the repeating will
  245. be applied up to the rightmost column of the longest line.
  246.  
  247.  
  248. ==============================================================================
  249. 6. Examples                        *visual-examples*
  250.  
  251.                             *:visual_example*
  252. Currently the ":" command works on whole lines only.  When you select part of
  253. a line, doing something like ":!date" will replace the whole line.  If you
  254. want only part of the line to be replaced you will have to make a mapping for
  255. it.  In a future release ":" may work on partial lines.
  256.  
  257. Here is an example, to replace the selected text with the output of "date":
  258. >    :vmap _a <Esc>`>a<CR><Esc>`<i<CR><Esc>!!date<CR>kJJ
  259.  
  260. (In the <> notation |<>|, when typing it you should type it literally; you
  261. need to remove the 'B' and '<' flags from 'cpoptions')
  262.  
  263. What this does is:
  264. <Esc>        stop Visual mode
  265. `>        go to the end of the Visual area
  266. a<CR><Esc>    break the line after the Visual area
  267. `<        jump to the start of the Visual area
  268. i<CR><Esc>    break the line before the Visual area
  269. !!date<CR>    filter the Visual text through date
  270. kJJ        Join the lines back together
  271.  
  272.                             *visual-search*
  273. Here is an idea for a mapping that makes it possible to do a search for the
  274. selected text:
  275. >    :vmap X y/<C-R>"<CR>
  276.  
  277. (In the <> notation |<>|, when typing it you should type it literally; you
  278. need to remove the 'B' and '<' flags from 'cpoptions')
  279.  
  280. Note that special characters (like '.' and '*') will cause problems.
  281.  
  282. ==============================================================================
  283. 7. Select mode                        *Select-mode*
  284.  
  285. Select mode looks like Visual mode, but the commands accepted are quite
  286. different.  This resembles the selection mode in Microsoft Windows.
  287. When the 'showmode' option is set, "-- SELECT --" is shown in the last line.
  288.  
  289. Entering Select mode:
  290. - Using the mouse to select an area, and 'selectmode' contains "mouse".
  291.   'mouse' must also contain a flag for the current mode.
  292. - Using a non-printable movement command, with the Shift key pressed, and
  293.   'selectmode' contains "key".  For example: <S-Left> and <S-End>.  'keymodel'
  294.   must also contain "startsel".
  295. - Using "v", "V" or CTRL-V command, and 'selectmode' contains "cmd".
  296. - Using "gh", "gH" or "g_CTRL-H" command in Normal mode.
  297. - From Visual mode, press CTRL-G.            *v_CTRL-G*
  298.  
  299. Commands in Select mode:
  300. - Printable characters, <NL> and <CR> cause the selection to be deleted, and
  301.   Vim enters Insert mode.  The typed character is inserted.
  302. - Non-printable movement commands, with the Shift key pressed, extend the
  303.   selection.  'keymodel' must include "startsel".
  304. - Non-printable movement commands, with the Shift key NOT pressed, stop Select
  305.   mode.  'keymodel' must include "stopsel".
  306. - ESC stops Select mode.
  307. - CTRL-O switches to Visual mode for the duration of one command.
  308. - CTRL-G switches to Visual mode.
  309.  
  310. Otherwise, typed characters are handled as in Visual mode.
  311.  
  312. When using an operator in Select mode, and the selection is linewise, the
  313. selected lines are operated upon, but like in characterwise selection.  For
  314. example, when a whole line is deleted, it can later be pasted halfway a line.
  315.  
  316.  
  317. Mappings and menus in Select mode.            *Select-mode-mapping*
  318.  
  319. In Select mode the mappings and menus of Visual mode are used.  Before it is
  320. executed, Vim automatically switches to Visual mode, so that the same
  321. behaviour as in Visual mode is effective.
  322.  
  323. After the mapping or menu finishes, the selection is enabled again and Select
  324. mode entered, unless the selected area was deleted, another buffer became
  325. the current one or the window layout was changed.
  326.  
  327.                             *gV* *v_gV*
  328. gV            Avoid the automatic reselection of the Visual area
  329.             after a Select mode mapping or menu has fininished.
  330.             Put this just before the end of the mapping or menu.
  331.             At least it should be after any operations on the
  332.             selection.
  333.  
  334.                             *gh*
  335. gh            Start Select mode, characterwise.  This is like "v",
  336.             but starts Select mode instead of Visual mode.
  337.             Mnemonic: "get highlighted".
  338.  
  339.                             *gH*
  340. gH            Start Select mode, linewise.  This is like "V",
  341.             but starts Select mode instead of Visual mode.
  342.             Mnemonic: "get Highlighted".
  343.  
  344.                             *g_CTRL-H*
  345. g CTRL-H        Start Select mode, blockwise.  This is like CTRL-V,
  346.             but starts Select mode instead of Visual mode.
  347.             Mnemonic: "get Highlighted".
  348.  
  349.  vim:tw=78:ts=8:sw=8:
  350.