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