Fix typo in help on :maca
[MacVim.git] / runtime / doc / gui_mac.txt
blob48b0518c1aa4d1b08422a0c7eb51611c4b711b89
1 *gui_mac.txt*   For Vim version 7.1.  Last change: 2008 Mar 16
4                   VIM REFERENCE MANUAL    by Bjorn Winckler
7 The MacVim Graphical User Interface                     *macvim* *gui-macvim*
9  0. Important!                  |macvim-important|
10  1. MacVim differences          |macvim-differences|
11  2. Starting MacVim             |macvim-start|
12  3. Preferences                 |macvim-preferences|
13  4. Special colors              |macvim-colors|
14  5. Menus                       |macvim-menus|
15  6. Toolbar                     |macvim-toolbar|
16  7. Dialogs                     |macvim-dialogs|
17  8. System services             |macvim-services|
18  9. Known bugs/missing features |macvim-todo|
19 10. Hints                       |macvim-hints|
21 Other relevant documentation:
22 |gui.txt|       For generic items of the GUI.
23 |os_mac.txt|    For Mac specific items.
25 {Vi does not have a GUI}
27 ==============================================================================
28 0. Important!                                           *macvim-important*
30 MacVim is still under development...this is not the finished product!  If you
31 have problems with MacVim then make it known either by adding an issue report
32 on the MacVim project page >
33         http://code.google.com/p/macvim
34 or by posting to the vim_mac mailing list               *vim_mac*  >
35         http://groups.google.com/group/vim_mac
37 Remember to keep checking the project page for new snapshots or use the
38 automatic updating feature which can be enabled in the preferences pane.  (If
39 you downloaded this copy from somewhere else, you might want to go there now
40 to make sure that you have got the latest version.)
42 ==============================================================================
43 1. MacVim differences                                   *macvim-differences*
45 One of the goals of MacVim is to make Vim behave like a proper Mac OS X
46 application.  For this reason MacVim behaves slightly different from other GUI
47 ports of Vim.  Most of the modifications are provided in the system gvimrc
48 file; you can quickly open this file and look at it yourself by typing: >
49         :tabe $VIM/gvimrc
50 Note that this file will be overwritten each time you update MacVim, so it is
51 better to keep your own modifications inside "~/.gvimrc".
53                                                         *macvim-windows*
54 There is some confusion regarding the term "window" in MacVim since it means
55 one thing to Vim and another to MacVim.  A "window" in Vim is what opens up
56 when you type ":sp", whereas a "window" in MacVim is the GUI window which
57 contains the text view, scrollbars, toolbar and tabline.  To avoid confusion,
58 the former is referred to as a Vim-window, whereas the latter is simply called
59 a window.
61                                                         *macvim-encoding*
62 It is not possible to modify 'termencoding' in MacVim; this option is forcibly
63 set to "utf-8".  The option 'encoding' also defaults to "utf-8" (as opposed to
64 "latin1" in the other GUI ports).
66 Note: UTF-8 can represent all characters defined in Unicode, which includes
67 all characters in all other standard encodings, so it should be perfectly safe
68 to edit files in any encoding while 'encoding' is set to "utf-8".  Of course,
69 you may need to set 'fileencodings' to auto-detect the encoding of the files
70 you edit, or force the detection with |++enc| on the command line.
72 However, if you are editing files that use multiple encodings (container
73 formats like MIME or Unix mbox files) or no standard encoding (binary data,
74 see also |edit-binary|), you may want to prevent MacVim from re-encoding the
75 file at all. In this situation, you will need to set both 'encoding' and
76 'fileencodings' to a simple single-byte encoding such as Latin1 so that when
77 the file is read into memory, the original bytes are left untouched.
79                                                         *macvim-movement*
80 Some Mac OS X standard key mappings involving Cmd or Option and an arrow key
81 are set up by default in "$VIM/gvimrc".  You can quickly disable all of these
82 by adding the following lines to your "~/.vimrc" (not .gvimrc) file: >
83         if has("gui_macvim")
84           let macvim_skip_cmd_opt_movement = 1
85         endif
86 Note: These are the only key mappings that MacVim makes (not counting menu key
87 equivalents which are not set up with :map).
89                                                         *macvim-shift-movement*
90 Text editors on Mac OS X lets the user hold down shift+movement key to extend
91 the selection.  Also, pressing a printable key whilst selecting replaces the
92 current selection with that character.  MacVim can emulate this kind of
93 behaviour (by providing key bindings and by setting 'keymodel' and
94 'selectmode' to non-default values) although it is not enabled by default.  To
95 make MacVim behave more like TextEdit and less like Vim, add the following
96 lines to your "~/.vimrc" (not .gvimrc) file: >
97         if has("gui_macvim")
98           let macvim_hig_shift_movement = 1
99         endif
101                                                         *macvim-drag-n-drop*
102 Dragging files and dropping them on a window opens those files in tabs in that
103 window, unless Vim is in command-line mode.  In command-line mode the names of
104 the files are added to the command line.  Holding down modifier keys whilst
105 dragging is not supported.
107 If a file is dropped on the Dock icon, it is always opened in a new tab
108 regardless of the mode Vim is currently in.  The same holds if you
109 double-click on a file in the Finder.
111                                                         *macvim-default-menu*
112 The default menu in MacVim has been changed to conform better with the Apple
113 Human Interface Guidelines (HIG).  At the moment this breaks the localized
114 menus, so only English menus are supported.
116 Note: The menus are a work in progress.  If you know something about the HIG
117 and want to contribute to MacVim you could do so by making the menus better.
119                                                         *macvim-window-title*
120 The default window title does not include the argument list because it looks
121 really bad once you start using tabs.  For example, dropping two files, then
122 dropping two more, and switching back to the first tab would cause weird
123 strings like "((3) of 2)" to appear in the window title.
125                                                         *macvim-options*
126 These are the non-standard options that MacVim supports:
127         'fullscreen' 'fuoptions' 'toolbariconsize' 'transparency'
129                                                         *macvim-find*
130 Whenever you search for something in Vim (e.g. using "/") the search query is
131 copied to the OS X "Find Pasteboard".  The idea is that if you search for
132 something and switch to another application, then you can hit <D-g> (or <D-G>)
133 to repeat the search in the new app.  The same feature works if you search in
134 some app, switch to MacVim and hit <D-g>.
136 Note that the command |n| is not the same as <D-g>.  The former will repeat
137 the last search made in Vim, whereas the latter searches for the string on the
138 OS X Find Pasteboard using the action findNext: (see |:macaction|).
140 The <D-g> key equivalent is a great way to bring a search from one window to
141 another in MacVim.  Simply search for something in one window (using "/") then
142 switch to another (e.g. with <D-`>) and hit <D-g> and the search will be
143 repeated in the new window.
145 ==============================================================================
146 2. Starting MacVim                                      *macvim-start*
148 The easiest way to start MacVim is by double-clicking its icon in the Finder,
149 but most users will probably prefer to use the Terminal.  First some Finder
150 related ways of starting MacVim are described, then Terminal is discussed.
151 Note that you can put MacVim anywhere on your hard drive, but in this help
152 file it is assumed that you have put it inside your /Applications folder.
154 MacVim automatically registers itself as an editor of several standard file
155 formats.  This enables you to double-click a file to open it with MacVim (if
156 it is not associated with another program), or to right-click a file to bring
157 up the "Open with" menu.  You can also drag and drop files onto the Dock icon
158 to open them in tabs in a new window, or you can drop them in an already open
159 window to open the files in tabs in that specific window.  Finally, you can
160 use Mac OS X System Services to open files in MacVim, see |macvim-services|.
162 There are essentially two ways to start MacVim from Terminal: either call the
163 Vim binary with the -g switch >
164         /Applications/MacVim.app/Contents/MacOS/Vim -g file ...
165 or use the "open" command (which is of limited use since it cannot be used to
166 pass parameters to Vim) >
167         open -a MacVim file ...
169                                                         *mvim*
170 To save yourself from having to type the entire path to the Vim binary each
171 time you start MacVim, you could create an alias such as >
172         alias gvim='/Applications/MacVim.app/Contents/MacOS/Vim -g'
173 and add that to "~/.profile".  A more flexible way to start MacVim is to use
174 the shell script "mvim" which comes bundled with MacVim.  Put this script in a
175 folder in your path and then simply type "mvim" to start MacVim.  This script
176 will try to find MacVim.app in various typical folders such as >
177         ~/Applications              ~/Applications/vim
178         /Applications               /Applications/vim
179         /Applications/Utilities     /Applications/Utilities/vim
180 If you would rather put MacVim.app in some other directory then that is also
181 possible, simply set the environment variable VIM_APP_DIR to whatever folder
182 you have placed MacVim.app in.
184 Note: Starting MacVim by creating a symlink to >
185         .../MacVim.app/Contents/MacOS/Vim
186 with 'ln -s' does not work.
188 Once in terminal Vim it is possible to start MacVim by using the following
189 command:
190         :gui [++opt] [+cmd] [-f|-b] [files...]
191 Note: Forking ("-b") currently does not work.
193                                                 *odbeditor* *external-editor*
194 MacVim can act as an 'external editor' for Mac OS X applications that support
195 the ODB Editor Protocol (or the 'external editor' protocol).  Each application
196 has different ways of configuring this option, check the application's
197 documentation.  Once configured properly MacVim can be used to open files in
198 such an application.
200 A technical note: MacVim handles file open, modified and closed events.  In
201 the open event the FTok and Burl parameters are parsed (the latter is ignored
202 at the moment though).  In the modified and closed events the Tokn parameter
203 is sent back to the server application.
205 ==============================================================================
206 3. Preferences                              *macvim-prefs* *macvim-preferences*
208 Some settings are global to the MacVim application and would not make sense as
209 Vim options.  These settings are stored in a user default database and can be
210 accessed via the "MacVim/Preferences..." menu item.
212 Not all entries in the user defaults database are exposed via the preference
213 panel, usually because they should not be changed by the user under normal
214 circumstances.  These options can still be changed with the "defaults" command
215 by opening Terminal and typing >
216         defaults write org.vim.MacVim KEY VALUE
217 Check the man page on "defaults" for more information on this command as well
218 as general information regarding Mac OS X user defaults.
220 Here is a list of relevant dictionary entries:
222 KEY                             VALUE ~
223 MMAtsuiRenderer                 enable ATSUI renderer [bool]
224 MMCellWidthMultiplier           width of a normal glyph in em units [float]
225 MMLoginShellArgument            login shell parameter [string]
226 MMLoginShellCommand             which shell to use to launch Vim [string]
227 MMNoFontSubstitution            disable automatic font substitution [bool]
228 MMTabMaxWidth                   maximum width of a tab [int]
229 MMTabMinWidth                   minimum width of a tab [int]
230 MMTabOptimumWidth               default width of a tab [int]
231 MMTextInsetBottom               text area offset in pixels [int]
232 MMTextInsetLeft                 text area offset in pixels [int]
233 MMTextInsetRight                text area offset in pixels [int]
234 MMTextInsetTop                  text area offset in pixels [int]
235 MMTexturedWindow                use brushed metal window (Tiger only) [bool]
236 MMTranslateCtrlClick            interpret ctrl-click as right-click [bool]
237 MMZoomBoth                      zoom button maximizes both directions [bool]
239 As an example, if you have more than one mouse button and would wish to free
240 up Ctrl-click so you can bind it to something else, then the appropriate
241 command is: >
242         defaults write org.vim.MacVim MMTranslateCtrlClick 0
244 If you wish to restore all user defaults to their starting values, open
245 Terminal and type: >
246         defaults delete org.vim.MacVim
248                                                         *macvim-login-shell*
249 Applications opened from the Finder do not automatically source the user's
250 environment variables (which are typically set in .profile or .bashrc).  This
251 presents a problem when using |:!| to execute commands in the shell since e.g.
252 $PATH might not be set properly.  To work around this problem MacVim can start
253 new Vim processes via a login shell so that all environment variables are set.
255 By default MacVim uses the $SHELL environment variable to determine which
256 shell to use (if $SHELL is not set "/bin/bash" is used).  It is possible to
257 override this choice by setting the user default MMLoginShellCommand to the
258 shell that should be used (e.g. "/bin/tcsh").  MacVim tries to make the shell
259 a login shell by prepending argv[0] with a dash.  If you use an exotic shell
260 and need to pass it a parameter to make it a login shell then you can set the
261 user default MMLoginShellArgument (e.g. to "-l").  Finally, if the "bash"
262 shell is used, then "-l" is automatically added as an argument.  To override
263 this behaviour set MMLoginShellArgument to "--".
265 ==============================================================================
266 4. Special colors                                       *macvim-colors*
268 The colors in MacVim are defined in two dictionaries inside the "Resources"
269 folder of the application bundle (MacVim.app/Contents/Resources).  It is
270 possible to add more colors by modifying these files.  Color names are case
271 insensitive when accessed from Vim, but in the dictionary they must be
272 lowercase.
274                                                         *SystemColors.plist*
275 There are only a few system colors that can be accessed from Vim.  These
276 colors are defined in the dictionary "SystemColors.plist".  This dictionary
277 stores (key, value) pairs where the key is the name of the color and the
278 value is an NSColor selector name.
280 The most useful system colors are: >
281         MacSelectedTextBackgroundColor
282         MacSecondarySelectedColor
283 The former is the "Highlight Color" which can be changed in the "Appearance"
284 section of the System Preferences.  The latter is the selection color used by
285 a Cocoa application when it is not in focus.
287                                                         *Colors.plist*
288 Apart from the system colors, it is also possible to use the standard X11
289 color names (see http://en.wikipedia.org/wiki/X11_color_names) which usually
290 come in a file called "rgb.txt".  MacVim does not have such a file, instead it
291 keeps these colors in a dictionary called "Colors.plist". The key in this
292 dictionary is the name of the color and the value is an RGB value on the form
293 #rrggbb stored as an integer.
295                                                         *macvim-colorscheme*
296 MacVim ships with a custom color scheme that is used instead of the default
297 Vim color scheme.  The color scheme can be changed with >
298         :colorscheme macvim
299 If you prefer a dark background color, then type >
300         :set bg=dark
301 after having loaded the "macvim" color scheme.
303 The color scheme uses the the system "Highlight Color", which can be changed in
304 the "Appearance" pane of the System Preferences.  It also changes the
305 highlight color when a window becomes inactive.
307 If you have any comments regarding this colors cheme (is it better or worse
308 than the default?) then post them to |vim_mac|.
310 ==============================================================================
311 5. Menus                                                *macvim-menus*
313                                                 *:macm* *:macmenukey*
314 MacVim has a special way of binding keys to menu items that differs from other
315 Vim GUI ports.  A menu binding is called a "key equivalent" in Mac OS X
316 terminology, this is displayed on the right side of a menu item.  The
317 ":macmenukey" command is used to set the key equivalent of a menu item.  This
318 command takes two parameters, the first names the menu item to bind to, the
319 second gives the key combination.  For example: >
320         :macmenukey File.New\ Tab <D-t>
321 This sets the key equivalent of the "New Tab" menu item under the "File" menu
322 to Cmd+t.
324 Note that key equivalents:
325         * must contain the Cmd modifier flag (<D-...>)
326         * take precedence over normal mappings made with ":map"
327         * can only be modified during startup (e.g. in .gvimrc)
329 It is possible to reset a key equivalent by calling :macmenukey with a menu
330 name but no key.  This is so that the default key equivalents can be reset in
331 "~/.gvimrc".  For example, if you would like to free up <D-s> (which is the
332 key equivalent of "File.Save") then add the following line to "~/.gvimrc": >
333         macmenukey File.Save
334 Now you can use :map to bind <D-s> to whatever you like.
336 It is not necessary to reset a key equivalent if all you want to do is to
337 change the key equivalent of a menu item.  For example, say you want to use
338 <D-M-Right> as the key equivalent for "Next Tab", then add the following line
339 to "~/.gvimrc": >
340         macmenukey Window.Next\ Tab <D-M-Right>
342                                                 *:maca* *:macaction*
343 It is typical for menu items in Cocoa applications to bind to Objective-C
344 selectors.  To support this, MacVim introduces the |:macaction| command.  This
345 command takes the name of an action message as its only parameter.  (An action
346 message is an Objective-C message with "void" return type and a single
347 parameter of type "id".)  For example, the "New Window" menu item on the
348 "File" menu is created in the following manner: >
349         :an 10.290 File.New\ Window :macaction newWindow:<CR>
351 Note 1: A menu item which is bound to |:macaction| will automatically be bound
352 to that action in all modes (as if ":an" was used).  It is not possible to
353 bind to |:macaction| in one mode only.
354 Note 2: The action is "nil-targeted", which means it is passed down the first
355 responder chain.
357                                                         *Actions.plist*
358 Some action messages would not be suitable to call from within Vim, so there
359 is a dictionary called "Actions.plist" (in the Resources folder of the
360 application bundle) which contains all actions that may be called.  The key in
361 this dictionary is the name of the action message (case sensitive), the value
362 is not used.
364 Note: The |:macaction| command supports tab-completion so to cycle through
365 all available actions type ":maca<Space><Tab>" and keep pressing <Tab>.
367 Here is a random assortment of actions from Actions.plist which might be
368 useful.  
370 Action                          Description ~
371 findNext:                       Search forward using the "Find Pasteboard"
372 findPrevious:                   Search backward using the "Find Pasteboard"
373 fontSizeDown:                   Decrease font size
374 fontSizeUp:                     Increase font size
375 newWindow:                      Open a new (empty) window
376 orderFrontCharacterPalette:     Show the the "Special Characters" dialog
377 orderFrontFontPanel:            Show the Font panel
378 orderFrontPreferencePanel:      Show the Preferences panel
379 performZoom:                    Zoom window (same as clicking the green blob)
380 selectNextWindow:               Select next window (similar to <D-`>)
381 selectPreviousWindow:           Select previous window (similar to <S-D-`>)
383 As an example, to map <C-z> to performZoom: you could do something like this: >
384         :map <silent> <C-z> :macaction performZoom:<CR>
385 A better way to map to performZoom: would be to set the key equivalent of the
386 menu item "Window.Zoom" to the above action.  This can be done by adding the
387 following line to "~/.gvimrc": >
388         macmenukey Window.Zoom <D-C-z>
389 (Note that key equivalents must contain the 'D' flag.)
391 ==============================================================================
392 6. Toolbar                                              *macvim-toolbar*
394 The toolbar in MacVim works just like in the other GUIs (see |gui-toolbar|),
395 with the addition of two separator items (see |menu-separator|).  You can use
396 them as follows: >
397         :an ToolBar.-space1-        <Nop>
398         :an ToolBar.-flexspace2-    <Nop>
399 The first example creates an empty space on the toolbar, the second creates an
400 empty space which will shink or expand so that the items to the right of it
401 are right-aligned.  A space (flexspace) will be created for any toolbar item
402 whose name begins with "-space" ("-flexspace") and ends with "-"
404 Toolbar icons should be tiff, png or icns, of dimension 32x32 or 24x24 pixels.
405 The larger size is used when 'tbis' is "medium" or "large", otherwise the
406 smaller size is used (which is the default).  If the icon file only contains
407 one dimension then Mac OS X will scale the icon to the appropriate dimension
408 if necessary.  To avoid this, use a file format which supports multiple
409 resolutions (such as icns) and provide both 32x32 and 24x24 versions of the
410 icon.
412 Note: Only a subset of the builtin toolbar items presently have icons.  If no
413 icon can be found a warning triangle is displayed instead.
415 ==============================================================================
416 7. Dialogs                                              *macvim-dialogs*
418 Dialogs can be controlled with the keyboard in two ways.  By default each
419 button in a dialog is bound to a key.  The button that is highlighted by blue
420 is bound to Enter, and any button with the title "Cancel" is bound to Escape.
421 Other buttons are usually bound to the first letter in the title of the
422 button.  There is no visual feedback to indicate which letter a button is
423 bound to, so sometimes some experimentation might be required in order to
424 figure out which key to press.
426 The second way of controlling dialogs with the keyboard is to enable "Full
427 keyboard access" in the "Keyboard & Mouse" pane of the System Preferences (you
428 can also toggle this on or off by pressing Ctrl-F7).  Once keyboard access is
429 enabled it is possible to move between buttons with Tab and pressing Space to
430 select the current button.  The current button is indicated with a blue
431 outline.
433 ==============================================================================
434 8. System services                                      *macvim-services*
436 MacVim supports a few system services.  These can be accessed from the MacVim
437 submenu in the Services menu.  For services to work, MacVim.app should be
438 located in the /Applications folder.  (You might have to logout and then login
439 again before Mac OS X detects the MacVim services.)
441 These are the currently supported services:
442 * New Tab Containing Selection: Opens a new tab in the topmost window and
443   pastes the currently selected text in that tab.  A new window will be
444   opened if necessary.
445 * Open Selected File in Tab: If the selected text represents a file
446   name, then the corresponding file is opened in a new tab in the topmost
447   window.
448 * Open Selected File in Window: Same as the above, but always open in a new
449   window.
451 ==============================================================================
452 9. Known bugs/missing features                          *macvim-todo*
454 Here are some of the bigger bugs in MacVim.  Of course there are others, but
455 these are ones that are know and/or which were judged major.
457 - Localized menus are not supported.  Choosing anything but "English" in the
458   "International" pane of "System Prefences" may break the menus (and
459   toolbar).
460 - Some Unicode characters are not handled well (e.g. nonspacing marks)
461 - Sometimes multibyte characters look "too wide", i.e. they overlap the
462   following character.  It might help to change 'ambiwidth', or override the
463   automatic font substitution by setting 'guifontwide' manually.
464 - Printing
465 - No find/replace dialog
467 If you find new bugs then add a new issue at http://code.google.com/p/macvim/
468 or post your findings to the |vim_mac| mailing list.  If you are missing
469 feature X in MacVim then voice your opinion on the |vim_mac| mailing list; it
470 might be simple to implement, but unless somebody asks for a particular
471 feature then there is little incentive to add it.
473 ==============================================================================
474 10. Hints                                               *macvim-hints*
476 In this section some general (not necessarily MacVim specific) hints are
477 given.
479 Scenario: ~
480 You try opening a bunch of files in tabs but not all files get
481 opened in their own tab.
482 Solution: ~
483 To get around this, set 'tabpagemax' to something big in your
484 .gvimrc file (e.g. ":set tabpagemax=100").
486 Scenario: ~
487 You want to open a file in a tab in an already opened window, but typing
488 "mvim filename" in Terminal opens it up in a separate window.
489 Solution: ~
490 Use the |--remote-tab| switch.  If you have several windows open you
491 might have to specify which window you want the file to open in by using the
492 |--servername| switch.  The title of a window usually ends in something like
493 "VIM" or "VIM3" --- this is the server name of that window.  So to open a file
494 named "foobar.txt" in a window whose title ends in "VIM3" you would type (the
495 order of the arguments matters): >
496         mvim --servername VIM3 --remote-tab foobar.txt
497 For more information, consult the |client-server| manual page.
499 Scenario: ~
500 You like to be able to select text by holding down shift and
501 pressing the arrow keys and find the Vim way of selecting text strange.
502 Solution: ~
503 See |macvim-shift-movement|.
505 Scenario: ~
506 You do not want MacVim to set up any key mappings.
507 Solution: ~
508 See |macvim-movement|.
510 Scenario: ~
511 Enabling localized menus breaks the toolbar and the menus as well.
512 Solution: ~
513 This is a know problem, see |macvim-todo|.
515 Scenario: ~
516 You dislike the default font (DejaVu Sans Mono).
517 Solution: ~
518 The standard fixed width font on other Mac OS X applications is
519 Monaco.  If you prefer this font then add the following line to your
520 "~/.gvimrc" (note that Monaco does not come in italic and bold variants): >
521         set guifont=Monaco:h10
522 The suffix ":h10" specifies the point size of the font should be "10" (see
523 'guifont' for more information on how to set the font).
525 Scenario: ~
526 When you click the (green) zoom button you want the window to maximize
527 horizontally as well as vertically.
528 Solution: ~
529 Hold down Cmd and click the zoom button.  If you prefer this to be the default
530 action, then set the user default MMZoomBoth (see |macvim-prefs|).
532 Scenario: ~
533 Typing feels sluggish when the cursor is just before a right bracket (i.e. ')',
534 '}', or ']').
535 Solution: ~
536 Disable the "matchparen" plugin (see |matchparen|) by typing :NoMatchParen.
537 If that helps, then you can permanently disable "matchparen" by adding the
538 following line to your "~/.vimrc": >
539         let loaded_matchparen=1
542 Scenario: ~
543 You can't find the information on MacVim you thought should be in
544 this manual page.
545 Solution: ~
546 Post your question on the |vim_mac| mailing list and wait for an
547 answer.
549  vim:tw=78:sw=4:ts=8:ft=help:norl: