usr_09.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. *usr_09.txt* For Vim version 9.0. Last change: 2017 Aug 11
  2. VIM USER MANUAL - by Bram Moolenaar
  3. Using the GUI
  4. Vim works in an ordinary terminal, while gVim has a Graphical User Interface
  5. (GUI). It can do the same things and a few more. The GUI offers menus, a
  6. toolbar, scrollbars and other items. This chapter is about these extra things
  7. that the GUI offers.
  8. |09.1| Parts of the GUI
  9. |09.2| Using the mouse
  10. |09.3| The clipboard
  11. |09.4| Select mode
  12. Next chapter: |usr_10.txt| Making big changes
  13. Previous chapter: |usr_08.txt| Splitting windows
  14. Table of contents: |usr_toc.txt|
  15. ==============================================================================
  16. *09.1* Parts of the GUI
  17. You might have an icon on your desktop that starts gvim. Otherwise, one of
  18. these commands should do it: >
  19. gvim file.txt
  20. vim -g file.txt
  21. If this doesn't work you don't have a version of Vim with GUI support. You
  22. will have to install one first.
  23. Vim will open a window and display "file.txt" in it. What the window looks
  24. like depends on the version of Vim. It should resemble the following picture
  25. (for as far as this can be shown in ASCII!).
  26. +----------------------------------------------------+
  27. | file.txt + (~/dir) - VIM X | <- window title
  28. +----------------------------------------------------+
  29. | File Edit Tools Syntax Buffers Window Help | <- menubar
  30. +----------------------------------------------------+
  31. | aaa bbb ccc ddd eee fff ggg hhh iii jjj | <- toolbar
  32. | aaa bbb ccc ddd eee fff ggg hhh iii jjj |
  33. +----------------------------------------------------+
  34. | file text | ^ |
  35. | ~ | # |
  36. | ~ | # | <- scrollbar
  37. | ~ | # |
  38. | ~ | # |
  39. | ~ | # |
  40. | | V |
  41. +----------------------------------------------------+
  42. The largest space is occupied by the file text. This shows the file in the
  43. same way as in a terminal. With some different colors and another font
  44. perhaps.
  45. THE WINDOW TITLE
  46. At the very top is the window title. This is drawn by your window system.
  47. Vim will set the title to show the name of the current file. First comes the
  48. name of the file. Then some special characters and the directory of the file
  49. in parens. These special characters can be present:
  50. - The file cannot be modified (e.g., a help file)
  51. + The file contains changes
  52. = The file is read-only
  53. =+ The file is read-only, contains changes anyway
  54. If nothing is shown you have an ordinary, unchanged file.
  55. THE MENUBAR
  56. You know how menus work, right? Vim has the usual items, plus a few more.
  57. Browse them to get an idea of what you can use them for. A relevant submenu
  58. is Edit/Global Settings. You will find these entries:
  59. Toggle Toolbar make the toolbar appear/disappear
  60. Toggle Bottom Scrollbar make a scrollbar appear/disappear at the bottom
  61. Toggle Left Scrollbar make a scrollbar appear/disappear at the left
  62. Toggle Right Scrollbar make a scrollbar appear/disappear at the right
  63. On most systems you can tear-off the menus. Select the top item of the menu,
  64. the one that looks like a dashed line. You will get a separate window with
  65. the items of the menu. It will hang around until you close the window.
  66. THE TOOLBAR
  67. This contains icons for the most often used actions. Hopefully the icons are
  68. self-explanatory. There are tooltips to get an extra hint (move the mouse
  69. pointer to the icon without clicking and don't move it for a second).
  70. The "Edit/Global Settings/Toggle Toolbar" menu item can be used to make the
  71. toolbar disappear. If you never want a toolbar, use this command in your
  72. vimrc file: >
  73. :set guioptions-=T
  74. This removes the 'T' flag from the 'guioptions' option. Other parts of the
  75. GUI can also be enabled or disabled with this option. See the help for it.
  76. THE SCROLLBARS
  77. By default there is one scrollbar on the right. It does the obvious thing.
  78. When you split the window, each window will get its own scrollbar.
  79. You can make a horizontal scrollbar appear with the menu item
  80. Edit/Global Settings/Toggle Bottom Scrollbar. This is useful in diff mode, or
  81. when the 'wrap' option has been reset (more about that later).
  82. When there are vertically split windows, only the windows on the right side
  83. will have a scrollbar. However, when you move the cursor to a window on the
  84. left, it will be this one that the scrollbar controls. This takes a bit of
  85. time to get used to.
  86. When you work with vertically split windows, consider adding a scrollbar on
  87. the left. This can be done with a menu item, or with the 'guioptions' option:
  88. >
  89. :set guioptions+=l
  90. This adds the 'l' flag to 'guioptions'.
  91. ==============================================================================
  92. *09.2* Using the mouse
  93. Standards are wonderful. In Microsoft Windows, you can use the mouse to
  94. select text in a standard manner. The X Window system also has a standard
  95. system for using the mouse. Unfortunately, these two standards are not the
  96. same.
  97. Fortunately, you can customize Vim. You can make the behavior of the mouse
  98. work like an X Window system mouse or a Microsoft Windows mouse. The following
  99. command makes the mouse behave like an X Window mouse: >
  100. :behave xterm
  101. The following command makes the mouse work like a Microsoft Windows mouse: >
  102. :behave mswin
  103. The default behavior of the mouse on UNIX systems is xterm. The default
  104. behavior on a Microsoft Windows system is selected during the installation
  105. process. For details about what the two behaviors are, see |:behave|. Here
  106. follows a summary.
  107. XTERM MOUSE BEHAVIOR
  108. Left mouse click position the cursor
  109. Left mouse drag select text in Visual mode
  110. Middle mouse click paste text from the clipboard
  111. Right mouse click extend the selected text until the mouse
  112. pointer
  113. MSWIN MOUSE BEHAVIOR
  114. Left mouse click position the cursor
  115. Left mouse drag select text in Select mode (see |09.4|)
  116. Left mouse click, with Shift extend the selected text until the mouse
  117. pointer
  118. Middle mouse click paste text from the clipboard
  119. Right mouse click display a pop-up menu
  120. The mouse can be further tuned. Check out these options if you want to change
  121. the way how the mouse works:
  122. 'mouse' in which mode the mouse is used by Vim
  123. 'mousemodel' what effect a mouse click has
  124. 'mousetime' time between clicks for a double-click
  125. 'mousehide' hide the mouse while typing
  126. 'selectmode' whether the mouse starts Visual or Select mode
  127. ==============================================================================
  128. *09.3* The clipboard
  129. In section |04.7| the basic use of the clipboard was explained. There is one
  130. essential thing to explain about X-windows: There are actually two places to
  131. exchange text between programs. MS-Windows doesn't have this.
  132. In X-Windows there is the "current selection". This is the text that is
  133. currently highlighted. In Vim this is the Visual area (this assumes you are
  134. using the default option settings). You can paste this selection in another
  135. application without any further action.
  136. For example, in this text select a few words with the mouse. Vim will
  137. switch to Visual mode and highlight the text. Now start another gvim, without
  138. a file name argument, so that it displays an empty window. Click the middle
  139. mouse button. The selected text will be inserted.
  140. The "current selection" will only remain valid until some other text is
  141. selected. After doing the paste in the other gvim, now select some characters
  142. in that window. You will notice that the words that were previously selected
  143. in the other gvim window are displayed differently. This means that it no
  144. longer is the current selection.
  145. You don't need to select text with the mouse, using the keyboard commands for
  146. Visual mode works just as well.
  147. THE REAL CLIPBOARD
  148. Now for the other place with which text can be exchanged. We call this the
  149. "real clipboard", to avoid confusion. Often both the "current selection" and
  150. the "real clipboard" are called clipboard, you'll have to get used to that.
  151. To put text on the real clipboard, select a few different words in one of
  152. the gvims you have running. Then use the Edit/Copy menu entry. Now the text
  153. has been copied to the real clipboard. You can't see this, unless you have
  154. some application that shows the clipboard contents (e.g., KDE's Klipper).
  155. Now select the other gvim, position the cursor somewhere and use the
  156. Edit/Paste menu. You will see the text from the real clipboard is inserted.
  157. USING BOTH
  158. This use of both the "current selection" and the "real clipboard" might sound
  159. a bit confusing. But it is very useful. Let's show this with an example.
  160. Use one gvim with a text file and perform these actions:
  161. - Select two words in Visual mode.
  162. - Use the Edit/Copy menu to get these words onto the clipboard.
  163. - Select one other word in Visual mode.
  164. - Use the Edit/Paste menu item. What will happen is that the single selected
  165. word is replaced with the two words from the clipboard.
  166. - Move the mouse pointer somewhere else and click the middle button. You
  167. will see that the word you just overwrote with the clipboard is inserted
  168. here.
  169. If you use the "current selection" and the "real clipboard" with care, you can
  170. do a lot of useful editing with them.
  171. USING THE KEYBOARD
  172. If you don't like using the mouse, you can access the current selection and
  173. the real clipboard with two registers. The "* register is for the current
  174. selection.
  175. To make text become the current selection, use Visual mode. For example,
  176. to select a whole line just press "V".
  177. To insert the current selection before the cursor: >
  178. "*P
  179. Notice the uppercase "P". The lowercase "p" puts the text after the cursor.
  180. The "+ register is used for the real clipboard. For example, to copy the text
  181. from the cursor position until the end of the line to the clipboard: >
  182. "+y$
  183. Remember, "y" is yank, which is Vim's copy command.
  184. To insert the contents of the real clipboard before the cursor: >
  185. "+P
  186. It's the same as for the current selection, but uses the plus (+) register
  187. instead of the star (*) register.
  188. ==============================================================================
  189. *09.4* Select mode
  190. And now something that is used more often on MS-Windows than on X-Windows.
  191. But both can do it. You already know about Visual mode. Select mode is like
  192. Visual mode, because it is also used to select text. But there is an obvious
  193. difference: When typing text, the selected text is deleted and the typed text
  194. replaces it.
  195. To start working with Select mode, you must first enable it (for MS-Windows
  196. it is probably already enabled, but you can do this anyway): >
  197. :set selectmode+=mouse
  198. Now use the mouse to select some text. It is highlighted like in Visual mode.
  199. Now press a letter. The selected text is deleted, and the single letter
  200. replaces it. You are in Insert mode now, thus you can continue typing.
  201. Since typing normal text causes the selected text to be deleted, you can not
  202. use the normal movement commands "hjkl", "w", etc. Instead, use the shifted
  203. function keys. <S-Left> (shifted cursor left key) moves the cursor left. The
  204. selected text is changed like in Visual mode. The other shifted cursor keys
  205. do what you expect. <S-End> and <S-Home> also work.
  206. You can tune the way Select mode works with the 'selectmode' option.
  207. ==============================================================================
  208. Next chapter: |usr_10.txt| Making big changes
  209. Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl: