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