usr_31.txt 9.1 KB

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