usr_31.txt (9303B)
1 *usr_31.txt* Nvim 2 3 4 VIM USER MANUAL by Bram Moolenaar 5 6 7 Exploiting the GUI 8 9 10 Vim works well in a terminal, but the GUI has a few extra items. A file 11 browser can be used for commands that use a file. A dialog to make a choice 12 between alternatives. Use keyboard shortcuts to access menu items quickly. 13 14 |31.1| The file browser 15 |31.2| Confirmation 16 |31.3| Menu shortcuts 17 |31.4| Vim window position and size 18 |31.5| Various 19 20 Next chapter: |usr_32.txt| The undo tree 21 Previous chapter: |usr_30.txt| Editing programs 22 Table of contents: |usr_toc.txt| 23 24 ============================================================================== 25 *31.1* The file browser 26 27 When using the File/Open... menu you get a file browser. This makes it easier 28 to find the file you want to edit. But what if you want to split a window to 29 edit another file? There is no menu entry for this. You could first use 30 Window/Split and then File/Open..., but that's more work. 31 Since you are typing most commands in Vim, opening the file browser with a 32 typed command is possible as well. To make the split command use the file 33 browser, prepend "browse": > 34 35 :browse split 36 37 Select a file and then the ":split" command will be executed with it. If you 38 cancel the file dialog nothing happens, the window isn't split. 39 You can also specify a file name argument. This is used to tell the file 40 browser where to start. Example: > 41 42 :browse split /etc 43 44 The file browser will pop up, starting in the directory "/etc". 45 46 The ":browse" command can be prepended to just about any command that opens a 47 file. 48 If no directory is specified, Vim will decide where to start the file 49 browser. By default it uses the same directory as the last time. Thus when 50 you used ":browse split" and selected a file in "/usr/local/share", the next 51 time you use a ":browse" it will start in "/usr/local/share" again. 52 This can be changed with the 'browsedir' option. It can have one of three 53 values: 54 55 last Use the last directory browsed (default) 56 buffer Use the same directory as the current buffer 57 current use the current directory 58 59 For example, when you are in the directory "/usr", editing the file 60 "/usr/local/share/readme", then the command: > 61 62 :set browsedir=buffer 63 :browse edit 64 65 Will start the browser in "/usr/local/share". Alternatively: > 66 67 :set browsedir=current 68 :browse edit 69 70 Will start the browser in "/usr". 71 72 Note: 73 To avoid using the mouse, most file browsers offer using key presses 74 to navigate. Since this is different for every system, it is not 75 explained here. Vim uses a standard browser when possible, your 76 system documentation should contain an explanation on the keyboard 77 shortcuts somewhere. 78 79 When you are not using the GUI version, you could use the file explorer window 80 to select files like in a file browser. However, this doesn't work for the 81 ":browse" command. See |netrw-browse|. 82 83 ============================================================================== 84 *31.2* Confirmation 85 86 Vim protects you from accidentally overwriting a file and other ways to lose 87 changes. If you do something that might be a bad thing to do, Vim produces an 88 error message and suggests appending ! if you really want to do it. 89 To avoid retyping the command with the !, you can make Vim give you a 90 dialog. You can then press "OK" or "Cancel" to tell Vim what you want. 91 For example, you are editing a file and made changes to it. You start 92 editing another file with: > 93 94 :confirm edit foo.txt 95 96 Vim will pop up a dialog that looks something like this: 97 98 +-----------------------------------+ 99 | | 100 | ? Save changes to "bar.txt"? | 101 | | 102 | YES NO CANCEL | 103 +-----------------------------------+ 104 105 Now make your choice. If you do want to save the changes, select "YES". If 106 you want to lose the changes for ever: "NO". If you forgot what you were 107 doing and want to check what really changed use "CANCEL". You will be back in 108 the same file, with the changes still there. 109 110 Just like ":browse", the ":confirm" command can be prepended to most commands 111 that edit another file. They can also be combined: > 112 113 :confirm browse edit 114 115 This will produce a dialog when the current buffer was changed. Then it will 116 pop up a file browser to select the file to edit. 117 118 Note: 119 In the dialog you can use the keyboard to select the choice. 120 Typically the <Tab> key and the cursor keys change the choice. 121 Pressing <Enter> selects the choice. This depends on the system 122 though. 123 124 When you are not using the GUI, the ":confirm" command works as well. Instead 125 of popping up a dialog, Vim will print the message at the bottom of the Vim 126 window and ask you to press a key to make a choice. > 127 128 :confirm edit main.c 129 < Save changes to "Untitled"? ~ 130 [Y]es, (N)o, (C)ancel: ~ 131 132 You can now press the single key for the choice. You don't have to press 133 <Enter>, unlike other typing on the command line. 134 135 ============================================================================== 136 *31.3* Menu shortcuts 137 138 The keyboard is used for all Vim commands. The menus provide a simple way to 139 select commands, without knowing what they are called. But you have to move 140 your hand from the keyboard and grab the mouse. 141 Menus can often be selected with keys as well. This depends on your 142 system, but most often it works this way. Use the <Alt> key in combination 143 with the underlined letter of a menu. For example, <A-w> (<Alt> and w) pops 144 up the Window menu. 145 In the Window menu, the "split" item has the p underlined. To select it, 146 let go of the <Alt> key and press p. 147 148 After the first selection of a menu with the <Alt> key, you can use the cursor 149 keys to move through the menus. <Right> selects a submenu and <left> closes 150 it. <Esc> also closes a menu. <Enter> selects a menu item. 151 152 There is a conflict between using the <Alt> key to select menu items, and 153 using <Alt> key combinations for mappings. The 'winaltkeys' option tells Vim 154 what it should do with the <Alt> key. 155 The default value "menu" is the smart choice: If the key combination is a 156 menu shortcut it can't be mapped. All other keys are available for mapping. 157 The value "no" doesn't use any <Alt> keys for the menus. Thus you must use 158 the mouse for the menus, and all <Alt> keys can be mapped. 159 The value "yes" means that Vim will use any <Alt> keys for the menus. Some 160 <Alt> key combinations may also do other things than selecting a menu. 161 162 ============================================================================== 163 *31.4* Vim window position and size 164 165 To see the current Vim window position on the screen use: > 166 167 :winpos 168 169 This will only work in the GUI. The output may look like this: 170 171 Window position: X 272, Y 103 ~ 172 173 The position is given in screen pixels. Now you can use the numbers to move 174 Vim somewhere else. For example, to move it to the left a hundred pixels: > 175 176 :winpos 172 103 177 < 178 Note: 179 There may be a small offset between the reported position and where 180 the window moves. This is because of the border around the window. 181 This is added by the window manager. 182 183 You can use this command in your startup script to position the window at a 184 specific position. 185 186 The size of the Vim window is computed in characters. Thus this depends on 187 the size of the font being used. You can see the current size with this 188 command: > 189 190 :set lines columns 191 192 To change the size set the 'lines' and/or 'columns' options to a new value: > 193 194 :set lines=50 195 :set columns=80 196 197 Obtaining the size works in a terminal just like in the GUI. Setting the size 198 is not possible in most terminals. 199 200 You can start the X-Windows version of gvim with an argument to specify the 201 size and position of the window: > 202 203 gvim -geometry {width}x{height}+{x-offset}+{y-offset} 204 205 {width} and {height} are in characters, {x-offset} and {y-offset} are in 206 pixels. Example: > 207 208 gvim -geometry 80x25+100+300 209 210 ============================================================================== 211 *31.5* Various 212 213 You can use gvim to edit an e-mail message. In your e-mail program you must 214 select gvim to be the editor for messages. When you try that, you will 215 see that it doesn't work: The mail program thinks that editing is finished, 216 while gvim is still running! 217 What happens is that gvim disconnects from the shell it was started in. 218 That is fine when you start gvim in a terminal, so that you can do other work 219 in that terminal. But when you really want to wait for gvim to finish, you 220 must prevent it from disconnecting. The "-f" argument does this: > 221 222 gvim -f file.txt 223 224 The "-f" stands for foreground. Now Vim will block the shell it was started 225 in until you finish editing and exit. 226 227 228 DELAYED START OF THE GUI 229 230 On Unix it's possible to first start Vim in a terminal. That's useful if you 231 do various tasks in the same shell. If you are editing a file and decide you 232 want to use the GUI after all, you can start it with: > 233 234 :gui 235 236 Vim will open the GUI window and no longer use the terminal. You can continue 237 using the terminal for something else. The "-f" argument is used here to run 238 the GUI in the foreground. You can also use ":gui -f". 239 240 241 ============================================================================== 242 243 Next chapter: |usr_32.txt| The undo tree 244 245 Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl: