*gui_mac.txt*	For Vim version 7.1.  Last change: 2008 May 25


		  VIM REFERENCE MANUAL    by Bjorn Winckler


The MacVim Graphical User Interface			*macvim* *gui-macvim*

 0. Important!			|macvim-important|
 1. MacVim differences		|macvim-differences|
 2. Starting MacVim		|macvim-start|
 3. Preferences			|macvim-preferences|
 4. Special colors		|macvim-colors|
 5. Menus			|macvim-menus|
 6. Toolbar			|macvim-toolbar|
 7. Dialogs			|macvim-dialogs|
 8. System services		|macvim-services|
 9. Known bugs/missing features	|macvim-todo|
10. Hints			|macvim-hints|

Other relevant documentation:
|gui.txt|	For generic items of the GUI.
|os_mac.txt|	For Mac specific items.

{Vi does not have a GUI}

==============================================================================
0. Important!						*macvim-important*

MacVim is still under development...this is not the finished product!  If you
have problems with MacVim then make it known either by adding an issue report
on the MacVim project page >
	http://code.google.com/p/macvim
or by posting to the vim_mac mailing list 		*vim_mac*  >
	http://groups.google.com/group/vim_mac

Remember to keep checking the project page for new snapshots or use the
automatic updating feature which can be enabled in the preferences pane.  (If
you downloaded this copy from somewhere else, you might want to go there now
to make sure that you have got the latest version.)

==============================================================================
1. MacVim differences					*macvim-differences*

One of the goals of MacVim is to make Vim behave like a proper Mac OS X
application.  For this reason MacVim behaves slightly different from other GUI
ports of Vim.  Most of the modifications are provided in the system gvimrc
file; you can quickly open this file and look at it yourself by typing: >
	:tabe $VIM/gvimrc
Note that this file will be overwritten each time you update MacVim, so it is
better to keep your own modifications inside "~/.gvimrc".

							*macvim-windows*
There is some confusion regarding the term "window" in MacVim since it means
one thing to Vim and another to MacVim.  A "window" in Vim is what opens up
when you type ":sp", whereas a "window" in MacVim is the GUI window which
contains the text view, scrollbars, toolbar and tabline.  To avoid confusion,
the former is referred to as a Vim-window, whereas the latter is simply called
a window.

							*macvim-encoding*
It is not possible to modify 'termencoding' in MacVim; this option is forcibly
set to "utf-8".  The option 'encoding' also defaults to "utf-8" (as opposed to
"latin1" in the other GUI ports).

Note: UTF-8 can represent all characters defined in Unicode, which includes
all characters in all other standard encodings, so it should be perfectly safe
to edit files in any encoding while 'encoding' is set to "utf-8".  Of course,
you may need to set 'fileencodings' to auto-detect the encoding of the files
you edit, or force the detection with |++enc| on the command line.

However, if you are editing files that use multiple encodings (container
formats like MIME or Unix mbox files) or no standard encoding (binary data,
see also |edit-binary|), you may want to prevent MacVim from re-encoding the
file at all. In this situation, you will need to set both 'encoding' and
'fileencodings' to a simple single-byte encoding such as Latin1 so that when
the file is read into memory, the original bytes are left untouched.

							*macvim-movement*
Some Mac OS X standard key mappings involving Cmd or Option and an arrow key
are set up by default in "$VIM/gvimrc".  You can quickly disable all of these
by adding the following lines to your "~/.vimrc" (not .gvimrc) file: >
	if has("gui_macvim")
	  let macvim_skip_cmd_opt_movement = 1
	endif
Note: These are the only key mappings that MacVim makes (not counting menu key
equivalents which are not set up with :map).

							*macvim-shift-movement*
Text editors on Mac OS X lets the user hold down shift+movement key to extend
the selection.  Also, pressing a printable key whilst selecting replaces the
current selection with that character.  MacVim can emulate this kind of
behaviour (by providing key bindings and by setting 'keymodel' and
'selectmode' to non-default values) although it is not enabled by default.  To
make MacVim behave more like TextEdit and less like Vim, add the following
lines to your "~/.vimrc" (not .gvimrc) file: >
	if has("gui_macvim")
	  let macvim_hig_shift_movement = 1
	endif
<
							*macvim-drag-n-drop*
Dragging files and dropping them on a window opens those files in tabs in that
window, unless Vim is in command-line mode.  In command-line mode the names of
the files are added to the command line.  Holding down modifier keys whilst
dragging is not supported.

If a file is dropped on the Dock icon, it is always opened in a new tab
regardless of the mode Vim is currently in.  The same holds if you
double-click on a file in the Finder.

							*macvim-default-menu*
The default menu in MacVim has been changed to conform better with the Apple
Human Interface Guidelines (HIG).  At the moment this breaks the localized
menus, so only English menus are supported.

Note: The menus are a work in progress.  If you know something about the HIG
and want to contribute to MacVim you could do so by making the menus better.

							*macvim-window-title*
The default window title does not include the argument list because it looks
really bad once you start using tabs.  For example, dropping two files, then
dropping two more, and switching back to the first tab would cause weird
strings like "((3) of 2)" to appear in the window title.

							*macvim-options*
These are the non-standard options that MacVim supports:
	'fullscreen' 'fuoptions' 'toolbariconsize' 'transparency' 'antialias'

							*macvim-find*
Whenever you search for something in Vim (e.g. using "/") the search query is
copied to the OS X "Find Pasteboard".  The idea is that if you search for
something and switch to another application, then you can hit <D-g> (or <D-G>)
to repeat the search in the new app.  The same feature works if you search in
some app, switch to MacVim and hit <D-g>.

Note that the command |n| is not the same as <D-g>.  The former will repeat
the last search made in Vim, whereas the latter searches for the string on the
OS X Find Pasteboard using the action findNext: (see |:macaction|).

The <D-g> key equivalent is a great way to bring a search from one window to
another in MacVim.  Simply search for something in one window (using "/") then
switch to another (e.g. with <D-`>) and hit <D-g> and the search will be
repeated in the new window.

					*macvim-backspace* *macvim-delete*
The 'backspace' option is set in the system vimrc to make the delete key
behave in a more familiar way to new users.  If you dislike this non-default
behaviour, then add the line "set backspace&" to your "~/.vimrc" file.

==============================================================================
2. Starting MacVim					*macvim-start*

The easiest way to start MacVim is by double-clicking its icon in the Finder,
but most users will probably prefer to use the Terminal.  First some Finder
related ways of starting MacVim are described, then Terminal is discussed.
Note that you can put MacVim anywhere on your hard drive, but in this help
file it is assumed that you have put it inside your /Applications folder.

MacVim automatically registers itself as an editor of several standard file
formats.  This enables you to double-click a file to open it with MacVim (if
it is not associated with another program), or to right-click a file to bring
up the "Open with" menu.  You can also drag and drop files onto the Dock icon
to open them in tabs in a new window, or you can drop them in an already open
window to open the files in tabs in that specific window.  Finally, you can
use Mac OS X System Services to open files in MacVim, see |macvim-services|.

There are essentially two ways to start MacVim from Terminal: either call the
Vim binary with the -g switch >
	/Applications/MacVim.app/Contents/MacOS/Vim -g file ...
or use the "open" command (which is of limited use since it cannot be used to
pass parameters to Vim) >
	open -a MacVim file ...
<
							*mvim*
To save yourself from having to type the entire path to the Vim binary each
time you start MacVim, you could create an alias such as >
	alias gvim='/Applications/MacVim.app/Contents/MacOS/Vim -g'
and add that to "~/.profile".  A more flexible way to start MacVim is to use
the shell script "mvim" which comes bundled with MacVim.  Put this script in a
folder in your path and then simply type "mvim" to start MacVim.  This script
will try to find MacVim.app in various typical folders such as >
	~/Applications              ~/Applications/vim
	/Applications               /Applications/vim
	/Applications/Utilities     /Applications/Utilities/vim
If you would rather put MacVim.app in some other directory then that is also
possible, simply set the environment variable VIM_APP_DIR to whatever folder
you have placed MacVim.app in.

Note: Starting MacVim by creating a symlink to >
	.../MacVim.app/Contents/MacOS/Vim
with 'ln -s' does not work.

Once in terminal Vim it is possible to start MacVim by using the following
command:
	:gui [++opt] [+cmd] [-f|-b] [files...]
Note: Forking ("-b") currently does not work.

						*odbeditor* *external-editor*
MacVim can act as an 'external editor' for Mac OS X applications that support
the ODB Editor Protocol (or the 'external editor' protocol).  Each application
has different ways of configuring this option, check the application's
documentation.  Once configured properly MacVim can be used to open files in
such an application.

A technical note: MacVim handles file open, modified and closed events.  In
the open event the FTok and Burl parameters are parsed (the latter is ignored
at the moment though).  In the modified and closed events the Tokn parameter
is sent back to the server application.

==============================================================================
3. Preferences				    *macvim-prefs* *macvim-preferences*

Some settings are global to the MacVim application and would not make sense as
Vim options.  These settings are stored in a user default database and can be
accessed via the "MacVim/Preferences..." menu item.

Not all entries in the user defaults database are exposed via the preference
panel, usually because they should not be changed by the user under normal
circumstances.  These options can still be changed with the "defaults" command
by opening Terminal and typing >
	defaults write org.vim.MacVim KEY VALUE
Check the man page on "defaults" for more information on this command as well
as general information regarding Mac OS X user defaults.

Here is a list of relevant dictionary entries:

KEY				VALUE ~
MMAtsuiRenderer			enable ATSUI renderer [bool]
MMCellWidthMultiplier		width of a normal glyph in em units [float]
MMDialogsTrackPwd		open/save dialogs track the Vim pwd [bool]
MMLoginShellArgument		login shell parameter [string]
MMLoginShellCommand		which shell to use to launch Vim [string]
MMNoFontSubstitution		disable automatic font substitution [bool]
MMTabMaxWidth			maximum width of a tab [int]
MMTabMinWidth			minimum width of a tab [int]
MMTabOptimumWidth		default width of a tab [int]
MMTextInsetBottom		text area offset in pixels [int]
MMTextInsetLeft			text area offset in pixels [int]
MMTextInsetRight		text area offset in pixels [int]
MMTextInsetTop			text area offset in pixels [int]
MMTexturedWindow		use brushed metal window (Tiger only) [bool]
MMTranslateCtrlClick		interpret ctrl-click as right-click [bool]
MMZoomBoth			zoom button maximizes both directions [bool]

As an example, if you have more than one mouse button and would wish to free
up Ctrl-click so you can bind it to something else, then the appropriate
command is: >
	defaults write org.vim.MacVim MMTranslateCtrlClick 0

If you wish to restore all user defaults to their starting values, open
Terminal and type: >
	defaults delete org.vim.MacVim
<
							*macvim-login-shell*
Applications opened from the Finder do not automatically source the user's
environment variables (which are typically set in .profile or .bashrc).  This
presents a problem when using |:!| to execute commands in the shell since e.g.
$PATH might not be set properly.  To work around this problem MacVim can start
new Vim processes via a login shell so that all environment variables are set.

By default MacVim uses the $SHELL environment variable to determine which
shell to use (if $SHELL is not set "/bin/bash" is used).  It is possible to
override this choice by setting the user default MMLoginShellCommand to the
shell that should be used (e.g. "/bin/tcsh").  MacVim tries to make the shell
a login shell by prepending argv[0] with a dash.  If you use an exotic shell
and need to pass it a parameter to make it a login shell then you can set the
user default MMLoginShellArgument (e.g. to "-l").  Finally, if the "bash"
shell is used, then "-l" is automatically added as an argument.  To override
this behaviour set MMLoginShellArgument to "--".

==============================================================================
4. Special colors					*macvim-colors*

The colors in MacVim are defined in two dictionaries inside the "Resources"
folder of the application bundle (MacVim.app/Contents/Resources).  It is
possible to add more colors by modifying these files.  Color names are case
insensitive when accessed from Vim, but in the dictionary they must be
lowercase.

							*SystemColors.plist*
There are only a few system colors that can be accessed from Vim.  These
colors are defined in the dictionary "SystemColors.plist".  This dictionary
stores (key, value) pairs where the key is the name of the color and the
value is an NSColor selector name.

The most useful system colors are: >
	MacSelectedTextBackgroundColor
	MacSecondarySelectedColor
The former is the "Highlight Color" which can be changed in the "Appearance"
section of the System Preferences.  The latter is the selection color used by
a Cocoa application when it is not in focus.

							*Colors.plist*
Apart from the system colors, it is also possible to use the standard X11
color names (see http://en.wikipedia.org/wiki/X11_color_names) which usually
come in a file called "rgb.txt".  MacVim does not have such a file, instead it
keeps these colors in a dictionary called "Colors.plist". The key in this
dictionary is the name of the color and the value is an RGB value on the form
#rrggbb stored as an integer.

							*macvim-colorscheme*
MacVim ships with a custom color scheme that is used instead of the default
Vim color scheme.  The color scheme can be changed with >
	:colorscheme macvim
If you prefer a dark background color, then type >
	:set bg=dark
after having loaded the "macvim" color scheme.

The color scheme uses the the system "Highlight Color", which can be changed in
the "Appearance" pane of the System Preferences.  It also changes the
highlight color when a window becomes inactive.

If you have any comments regarding this colors cheme (is it better or worse
than the default?) then post them to |vim_mac|.

==============================================================================
5. Menus						*macvim-menus*

Menus in Mac OS X behave slightly different from other platforms.  For that
reason two new commands have been added to Vim.  To understand what these
commands do you must first understand how menus work on OS X.

Each entry in a menu is called a "menu item".  With each menu item is
associated: a title, a key equivalent and an action message.  When a menu is
displayed the title is shown on the left and the key equivalent (if any) is
shown on the right.  Key equivalents enable you to access a menu item using
the keyboard instead of having to use the mouse.  When a menu item is clicked
it will send it's associated action message.  Actions can be used to instruct
MacVim to paste some text (paste:), open a new window (newWindow:), etc.
Certain actions are standard throughout OS X which is why MacVim must be able
to set these for each menu item.  (E.g. the menu item "Edit.Paste" must be
bound to the action "paste:" otherwise pasting won't work in dialogs since
that is the action that instructs them to paste something.)

Menus are configured using the |:macmenu| command and the |:macaction| command
can be used to send action messages.

						*:maca* *:macaction*
:maca[ction] {action:}	Send the message "action:" to the first responder.
			The list of allowed actions can be seen by typing
			    :maca <C-d>
			An attempt to send an action not listed here will
			result in an error.  This list is specified in a
			property list file called |Actions.plist|.

						*:macm* *:macmenu*
:mac[menu] {menu} {key}={arg} ...
			Set Mac specific properties for {menu}.  The
			properties that can be set are:
			    action	the action this menu sends
			    alt		"yes" if alternate of previous menu
			    key		the key equivalent of this menu
			This command must be used in a startup file, for
			example in "~/.gvimrc".  It has no effect otherwise.

			For convenience, a menu with "action=name:" which is
			bound to <Nop> will act as if bound to
			":maca name:<CR>".  Thus, if "Menu.Item" is given by
			    :an Menu.Item <Nop>
			    :macm Menu.Item action=name:
			then ":emenu Menu.Item" is equivalent to
			":maca name:".

			The key equivalent is specified with the <D-..>
			syntax.  Note that key equivalents must contain the
			Cmd modifier flag (<D-...>), and they take precedence
			over normal mappings.
			Use the syntax "key=<nop>" to clear the key equivalent
			of a menu.  This can be used to free up a key
			combination that is set in the system gvimrc so that
			it may be mapped to using ":map".

			Recognised values of "alt" are "0", "no", "1", and
			"yes".  The default is "no".  An alternate menu must
			have the same key equivalent as the previous menu,
			except the modifier flags must differ.  The alternate
			menu is by default hidden and only shows up when the
			modifier is held down.

Here are some examples on how to use these commands:

1. Create a menu item with title "New Window" under the "File" menu, with key
equivalent Cmd-n, which opens a new window when selected: >
	:an 10.290 File.New\ Window <Nop>
	:macm File.New\ Window action=newWindow: key=<D-n>
2. Change the key equivalent to cycle through tabs to Cmd-Left/Right: >
	:macm Window.Previous\ Tab  key=<D-Left>
	:macm Window.Next\ Tab	    key=<D-Right>
3. Create a mapping in normal mode which closes the current tab/window: >
	:map <C-w> :maca performClose:<CR>
>

The standard Vim menus are modified in "$VIM/gvimrc".  Take a look at that
file for more examples on how to set up menus.  Note: When no window is open a
minimal default menu is used.  The default menu is set up in MainMenu.nib
which resides in "Resources/English.lproj/" folder inside the app bundle.

							*Actions.plist*
Some action messages would not be suitable to call from within Vim, so there
is a dictionary called "Actions.plist" (in the Resources folder of the
application bundle) which contains all actions that may be called.  The key in
this dictionary is the name of the action message (case sensitive), the value
is not used.

Hint: The |:macaction| command supports command-line completion so you can
enter ":maca<Space><C-d>" to see a list of all available actions.

Here is a random assortment of actions from Actions.plist which might be
useful.  

Action				Description ~
fileOpen:			Show "File Open" dialog
findNext:			Search forward using the "Find Pasteboard"
findPrevious:			Search backward using the "Find Pasteboard"
fontSizeDown:			Decrease font size
fontSizeUp:			Increase font size
hide:				Hide MacVim
miniaturizeAll:			Minimize all windows to the dock
newWindow:			Open a new (empty) window
orderFrontCharacterPalette:	Show the the "Special Characters" dialog
orderFrontFontPanel:		Show the Font panel
orderFrontPreferencePanel:	Show the Preferences panel
performMiniaturize:		Minimize window to the dock
performZoom:			Zoom window (same as clicking the green blob)
terminate:			Quit MacVim
zoomAll:			Zoom all windows
_cycleWindows:			Select next window (similar to <D-`>)
_cycleWindowsBackwards:		Select previous window (similar to <D-S-`>)

==============================================================================
6. Toolbar						*macvim-toolbar*

The toolbar in MacVim works just like in the other GUIs (see |gui-toolbar|),
with the addition of two separator items (see |menu-separator|).  You can use
them as follows: >
	:an ToolBar.-space1-        <Nop>
	:an ToolBar.-flexspace2-    <Nop>
The first example creates an empty space on the toolbar, the second creates an
empty space which will shink or expand so that the items to the right of it
are right-aligned.  A space (flexspace) will be created for any toolbar item
whose name begins with "-space" ("-flexspace") and ends with "-"

Toolbar icons should be tiff, png or icns, of dimension 32x32 or 24x24 pixels.
The larger size is used when 'tbis' is "medium" or "large", otherwise the
smaller size is used (which is the default).  If the icon file only contains
one dimension then Mac OS X will scale the icon to the appropriate dimension
if necessary.  To avoid this, use a file format which supports multiple
resolutions (such as icns) and provide both 32x32 and 24x24 versions of the
icon.

Note: Only a subset of the builtin toolbar items presently have icons.  If no
icon can be found a warning triangle is displayed instead.

==============================================================================
7. Dialogs						*macvim-dialogs*

Dialogs can be controlled with the keyboard in two ways.  By default each
button in a dialog is bound to a key.  The button that is highlighted by blue
is bound to Enter, and any button with the title "Cancel" is bound to Escape.
Other buttons are usually bound to the first letter in the title of the
button.  There is no visual feedback to indicate which letter a button is
bound to, so sometimes some experimentation might be required in order to
figure out which key to press.

The second way of controlling dialogs with the keyboard is to enable "Full
keyboard access" in the "Keyboard & Mouse" pane of the System Preferences (you
can also toggle this on or off by pressing Ctrl-F7).  Once keyboard access is
enabled it is possible to move between buttons with Tab and pressing Space to
select the current button.  The current button is indicated with a blue
outline.

==============================================================================
8. System services					*macvim-services*

MacVim supports a few system services.  These can be accessed from the MacVim
submenu in the Services menu.  For services to work, MacVim.app should be
located in the /Applications folder.  (You might have to logout and then login
again before Mac OS X detects the MacVim services.)

These are the currently supported services:
* New Tab Containing Selection: Opens a new tab in the topmost window and
  pastes the currently selected text in that tab.  A new window will be
  opened if necessary.
* Open Selected File in Tab: If the selected text represents a file
  name, then the corresponding file is opened in a new tab in the topmost
  window.
* Open Selected File in Window: Same as the above, but always open in a new
  window.

==============================================================================
9. Known bugs/missing features				*macvim-todo*

Here are some of the bigger bugs in MacVim.  Of course there are others, but
these are ones that are know and/or which were judged major.

- Localized menus are not supported.  Choosing anything but "English" in the
  "International" pane of "System Prefences" may break the menus (and
  toolbar).
- Some Unicode characters are not handled well (e.g. nonspacing marks)
- Sometimes multibyte characters look "too wide", i.e. they overlap the
  following character.  It might help to change 'ambiwidth', or override the
  automatic font substitution by setting 'guifontwide' manually.
- Printing
- No find/replace dialog

If you find new bugs then add a new issue at http://code.google.com/p/macvim/
or post your findings to the |vim_mac| mailing list.  If you are missing
feature X in MacVim then voice your opinion on the |vim_mac| mailing list; it
might be simple to implement, but unless somebody asks for a particular
feature then there is little incentive to add it.

==============================================================================
10. Hints						*macvim-hints*

In this section some general (not necessarily MacVim specific) hints are
given.

Scenario: ~
You try opening a bunch of files in tabs but not all files get
opened in their own tab.
Solution: ~
To get around this, set 'tabpagemax' to something big in your
.gvimrc file (e.g. ":set tabpagemax=100").

Scenario: ~
You want to open a file in a tab in an already opened window, but typing
"mvim filename" in Terminal opens it up in a separate window.
Solution: ~
Use the |--remote-tab| switch.  If you have several windows open you
might have to specify which window you want the file to open in by using the
|--servername| switch.  The title of a window usually ends in something like
"VIM" or "VIM3" --- this is the server name of that window.  So to open a file
named "foobar.txt" in a window whose title ends in "VIM3" you would type (the
order of the arguments matters): >
	mvim --servername VIM3 --remote-tab foobar.txt
For more information, consult the |client-server| manual page.

Scenario: ~
You like to be able to select text by holding down shift and
pressing the arrow keys and find the Vim way of selecting text strange.
Solution: ~
See |macvim-shift-movement|.

Scenario: ~
You do not want MacVim to set up any key mappings.
Solution: ~
See |macvim-movement|.

Scenario: ~
Enabling localized menus breaks the toolbar and the menus as well.
Solution: ~
This is a know problem, see |macvim-todo|.

Scenario: ~
You dislike the default font (DejaVu Sans Mono).
Solution: ~
The standard fixed width font on other Mac OS X applications is
Monaco.  If you prefer this font then add the following line to your
"~/.gvimrc" (note that Monaco does not come in italic and bold variants): >
	set guifont=Monaco:h10
The suffix ":h10" specifies the point size of the font should be "10" (see
'guifont' for more information on how to set the font).

Scenario: ~
When you click the (green) zoom button you want the window to maximize
horizontally as well as vertically.
Solution: ~
Hold down Cmd and click the zoom button.  If you prefer this to be the default
action, then set the user default MMZoomBoth (see |macvim-prefs|).

Scenario: ~
Typing feels sluggish when the cursor is just before a right bracket (i.e. ')',
'}', or ']').
Solution: ~
Disable the "matchparen" plugin (see |matchparen|) by typing :NoMatchParen.
If that helps, then you can permanently disable "matchparen" by adding the
following line to your "~/.vimrc": >
	let loaded_matchparen=1
<

Scenario: ~
You can't find the information on MacVim you thought should be in
this manual page.
Solution: ~
Post your question on the |vim_mac| mailing list and wait for an
answer.

 vim:tw=78:sw=4:ts=8:ft=help:norl:
