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