*gui.txt*       For Vim version 5.0j.  Last modification: 1997 May 30


		  VIM REFERENCE MANUAL    by Bram Moolenaar


Vim's Graphical User Interface				*gui*

1. Starting the GUI		|gui-start|
2. GUI Resources		|gui_resources|
3. Scrollbars			|gui_scrollbars|
4. Mouse Control		|gui_mouse|
5. Making GUI Selections	|gui_selections|
6. Menus			|gui_menus|
7. Extras			|gui_extras|
8. Shell Commands		|gui_pty|
9. Compiling			|gui_compiling|

==============================================================================
1. Starting the GUI					*gui-start* *GUI*

First you must make sure you actually compile Vim with the GUI code included.
You can check this with the ":version" command, it should include "+GUI_Motif"
or "+GUI_Athena".  Then you may run the GUI version of Vim in either of these
ways:
    gvim [options] [files...]
    vim -g [options] [files...]

So if you call the executable "gvim", or make "gvim" a link to the executable,
then the GUI version will automatically be used.  Additional characters may be
added after "gvim", for example "gvim-5".

You may also start up the GUI from within the terminal version by using one of
these commands:
	:gui [+cmd] [-f] [files...]			*:gu* *:gui*
	:gvim [+cmd] [-f] [files...]			*:gv* *:gvim*

							*gui_fork*
When the GUI is started, it does a fork() and exits the current process.
When gvim was started from a shell this makes the shell accept further
commands.  If you don't want this (e.g. when using gvim for a mail program
that waits for gvim to exit), start gvim with "gvim -f", "vim -gf" or use
":gui -f".  Don't use "vim -fg", because "-fg" specifies the foreground
color.  If you want the GUI to run in the foreground always, include the 'f'
flag in 'guioptions'.  |-f|.

							*gui_init*
When the GUI starts up initializations are carried out, in this order:
- If the system menu file exists, it is sourced.  The name if this file is
  something like "$VIM/menu.vim".  You can check this with ":version".  Also
  see |$VIM|.
- If the system gvimrc exists, it is sourced.  The name if this file is
  something like "$VIM/gvimrc".  You can check this with ":version".  Also see
  |$VIM|.
- If the GVIMINIT environment variable exists and is not empty, it is
  executed as an Ex command.  Otherwise, if the user gvimrc file exists, it
  is sourced.  The name of this file is something like "$HOME/.gvimrc".  You
  can check this with ":version".
- If the 'exrc' option is set (which is NOT the default) the file ./.gvimrc
  is sourced, if it exist and isn't the same file as the system or user
  gvimrc file.  If this file is not owned by you, some security restrictions
  apply.

NOTE: All but the first one are not carried out if Vim was started with "-u
NONE".

When starting "gvim", all this happens AFTER the normal Vim initializations,
like reading your .vimrc file.  See |initialization|.

You can use the gvimrc files to set up your own customised menus (see |:menu|)
and initialise other things that you may want to set up differently from the
terminal version.

There are a number of options which only have meaning in the GUI version of
Vim.  These are 'guicursor', 'guifont', 'guipty' and 'guioptions'.  They are
documented in |options.txt| with all the other options.

==============================================================================
2. GUI Resources					*gui_resources*

If using the Motif or Athena version of the GUI (not for the Win32 version), a
number of X resources are available.  You should use Vim's class "Vim" when
setting these.  They are as follows:

    Resource name	Meaning

    background		Color of background.
    foreground		Color of normal text.
    font		Name of font used for normal text.
    boldFont		Name of font used for bold text.
    italicFont		Name of font used for italic text.
    boldItalicFont	Name of font used for bold, italic text.
    geometry		Initial geometry to use for gvim's window (default
			is same size as terminal that started it).
    scrollbarWidth	Thickness of scrollbars.
    menuHeight		Height of the menu bar.
    borderWidth		Thickness of border around text area.
    reverseVideo	Boolean: should reverse video be used?
    menuBackground	Color of menu backgrounds.
    menuForeground	Color of menu foregrounds.
    scrollBackground	Color of trough portion of scrollbars.
    scrollForeground	Color of slider and arrow portions of scrollbars.

A special font for italic, bold, and italic-bold text will only be used if
the user has specified one via a resource.  No attempt is made to guess what
fonts should be used for these based on the normal text font at the moment.

Note: All fonts must be of the same size!!!  If you don't do this, text will
disappear.  Vim does not check the font sizes.

If any of these things are also set with Vim commands, eg with
":set guifont=Screen15", then this will override the X resources (currently
'guifont' is the only option that is supported).

Here is an example of what you might put in your ~/.Xdefaults file:

Vim*useSchemes:			all
Vim*sgiMode:			true
Vim*useEnhancedFSB:		true
Vim.foreground:			Black
Vim.background:			Wheat
Vim*menuBar*font:		7x13

The first three of these are standard resources on Silicon Graphics machines
which make Motif applications look even better, highly recommended!

Don't use "Vim*geometry" in the defaults.  This will break the menus.  Use
"Vim.geometry" instead.

If you get an error message "Cannot allocate colormap entry for "gray60",
try adding this to your Vim resources (change the colors to your liking):

Vim*scrollBackground:		Black
Vim*scrollForeground:		Blue

The resources can also be set with arguments to vim:

    argument		meaning				*-gui*

   -display <display>	Run vim on <display>		*-display*
   -iconic		Start vim iconified		*-iconic*
   -background <color>	Use <color> for the background	*-background*
   -bg <color>		idem				*-bg*
   -foreground <color>	Use <color> for normal text	*-foreground*
   -fg <color>		idem				*-fg*
   -ul <color>		idem				*-ul*
   -font <font>		Use <font> for normal text	*-font*
   -fn <font>		idem				*-fn*
   -boldfont <font>	Use <font> for bold text	*-boldfont*
   -italicfont <font>	Use <font> for italic text	*-italicfont*
   -geometry <geom>	Use <geom> for initial geometry	*-geometry*
   -geom <geom>		idem				*-geom*
   -borderwidth <width>	Use a border width of <width>	*-borderwidth*
   -bw <width>		idem				*-bw*
   							*-scrollbarwidth*
   -scrollbarwidth <width>	Use a scrollbar width of <width>
   -sw <width>		idem				*-sw*
   -menuheight <height>	Use a menu bar height of <height> *-menuheight*
   -mh <height>		idem				*-mh*
   -reverse		Use reverse video		*-reverse*
   -rv			idem				*-rv*
   +reverse		Don't use reverse video		*-+reverse*
   +rv			idem				*-+rv*
   -xrm <resource>	Set the specified resource	*-xrm*


Another way to set the colors for different occasions is with highlight
groups.  The "Normal" group is used to set the background and foreground
colors.  Example (which looks nice):

	:highlight Normal guibg=grey90

The "guibg" and "guifg" settings ovverride the normal background and
foreground settings.  The other settings for the Normal highlight group are
not used.  Use the 'guifont' option to set the font.

Also check out the 'guicursor' option, to set the colors for the cursor in
various modes.

==============================================================================
3. Scrollbars						*gui_scrollbars*

There are vertical scrollbars and a horizontal scrollbars.  You may
configure which ones appear with the 'guioptions' option.

The interface looks like this (with ":set guioptions=mlrb"):

		       +------------------------------+
		       | File  Edit              Help | <- Menu bar (m)
		       +-+--------------------------+-+
		       |^|                          |^|
		       |#| Text area.               |#|
		       | |                          | |
		       |v|__________________________|v|
 Normal status line -> |-+ File.c              5,2  +-|
 between Vim windows   |^|""""""""""""""""""""""""""|^|
		       | |                          | |
		       | | Another file buffer.     | |
		       | |                          | |
		       |#|                          |#|
 Left scrollbar (l) -> |#|                          |#| <- Right
		       |#|                          |#|    scrollbar (r)
		       | |                          | |
		       |v|                          |v|
		       +-+--------------------------+-+
		       | |< ####                   >| | <- Bottom
		       +-+--------------------------+-+    scrollbar (b)

Any of the scrollbar or menu components may be turned off by not putting the
appropriate letter in the 'guioptions' string.  The bottom scrollbar is
only useful when 'nowrap' is set.


Vertical Scrollbars					*gui_vert_scroll*

Each Vim window has a scrollbar next to it which may be scrolled up and down
to move through the text in that buffer.  The size of the scrollbar-thumb
indicates the fraction of the buffer which can be seen in the window.
When the scrollbar is dragged all the way down, the last line of the file
will appear in the top of the window.


Horizontal Scrollbars					*gui_horiz_scroll*

The horizontal scrollbar (at the bottom of the Vim GUI) may be used to
scroll text sideways when the 'wrap' option is turned off.  The
scrollbar-thumb size is such that the text of the current cursor line may be
scrolled as far as possible left and right.

==============================================================================
4. Mouse Control					*gui_mouse*

The mouse only works if the appropriate flag in the 'mouse' option is set.
When the GUI is switched on the 'mouse' option is set to "a", enabling
it for all modes except for the "hit return to continue" message. This can
be changed from the "gvimrc" file.


4.1 Moving Cursor with Mouse				*gui_mouse_move*

Click the left mouse button where you want the cursor to go, and it does!
This works in Normal mode (if 'mouse' contains 'n' or 'a'), Visual mode (if
'mouse' contains 'v' or 'a') and Insert mode (if 'mouse' contains 'i' or
'a'), if you click the mouse somewhere in a text buffer. You may use this
with an operator such as 'd' to delete text from the current cursor position
to the position you point to with the mouse.  That is, you hit 'd' and then
click the mouse somewhere.  If you are on the ':' line (or '/' or '?'), then
clicking the left or right mouse button will position the cursor on the ':'
line (if 'mouse' contains 'c' or 'a').  In any situation the middle mouse
button may be clicked to paste the current selection.


4.2 Visual Selection with Mouse				*gui_mouse_select*

The right mouse button may be clicked somewhere to extend the visual
selection to the position pointed to with the mouse.  If already in Visual
mode then the closest end will be extended, otherwise Visual mode is started
and extends from the old cursor position to the new one.

Double clicking may be done to make the selection word-wise, triple clicking
makes it line-wise, and quadruple clicking makes it rectangular block-wise.

Visual selection, however it is invoked, makes Vim the owner of the
windowing system's primary selection, so that the highlighted text may be
pasted into other windows.  Similarly, selected text from other windows may
be pasted into Vim in Normal mode, Insert mode, or on the ':' line by
clicking the middle mouse button.


4.3 Other Text Selection with Mouse		*gui_mouse_xterm_like*

When in Command-line mode, at the hit-return prompt or whenever the current
mode is not in the 'mouse' option, a different kind of selection is used.
It is more like what happens in an xterm.  Let's call this xterm-like
selection.  Any text in the Vim window can be selected.  Select the text by
pressing the left mouse button at the start, drag to the end and release.
Right mouse button extends the selection.  Middle mouse button pasts the
text.


4.4 Using Mouse on Status Lines				*gui_mouse_status*

Clicking the left or right mouse button on the status line below a Vim
window makes that window the current window.  The mouse may then be dragged
up and down to move the status line, thus resizing the windows above and
below it.


4.5 Various Mouse Clicks				*gui_mouse_various*

    <S-LeftMouse>	Search forward for the word under the mouse click.
    <S-RightMouse>	Search backward for the word under the mouse click.
    <C-LeftMouse>	Jump to the tag name under the mouse click.
    <C-RightMouse>	Jump back to position before the previous tag jump
			(same as "CTRL-T")


4.6 Mouse Mappings					*gui_mouse_mapping*

The mouse events, complete with modifiers, may be mapped.  Eg:
    :map <S-LeftMouse>     <RightMouse>
    :map <S-LeftDrag>      <RightDrag>
    :map <S-LeftRelease>   <RightRelease>
    :map <2-S-LeftMouse>   <2-RightMouse>
    :map <2-S-LeftDrag>    <2-RightDrag>
    :map <2-S-LeftRelease> <2-RightRelease>
    :map <3-S-LeftMouse>   <3-RightMouse>
    :map <3-S-LeftDrag>    <3-RightDrag>
    :map <3-S-LeftRelease> <3-RightRelease>
    :map <4-S-LeftMouse>   <4-RightMouse>
    :map <4-S-LeftDrag>    <4-RightDrag>
    :map <4-S-LeftRelease> <4-RightRelease>
These mappings make selection work the way it probably should in a Motif
application, with shift-left mouse allowing for extending the visual area
rather than the right mouse button.

Mouse mapping with modifiers does not work for xterm-like selection.

==============================================================================
5. Making GUI Selections				*gui_selections*

You may make selections with the mouse (see |gui_mouse_select|), or by using
Vim's visual mode (see |v|).  If 'a' is present in 'guioptions', then
whenever visual mode is invoked, or when the cursor moves while in visual
mode, Vim becomes the owner of the windowing system's primary selection.
There is a special register for storing this selection, it is the <"*>
register.  Nothing is put in here unless the information about what text is
selected is about to change (eg with a left mouse click somewhere), or when
another application wants to paste the selected text.  Then the text is put
in the <"*> register.  Similarly, when we want to paste a selection from
another application, eg by clicking the middle mouse button, the selection
is put in the <"*> register first, and then 'put' like any other register.

Note that when pasting text from one Vim into another separate Vim, the type
of selection (character, line, or block) will also be copied.

==============================================================================
6. Menus						*gui_menus*

6.1 Using Menus						*gui_using_menus*

The default menus are quite simple at the moment.  Power Vim users won't use
them much.  But the power is in adding your own menus and menu items.  They
are most useful for things that you can't remember what the key sequence
was.

Eventually I would like to expand the set of default menus to use pop up and
other windows for confirmation, file selection etc.  Maybe have a dialogue
box for browsing and choosing buffers, etc.

Motif supports Tear-off menus.  These are sort of sticky menus or pop-up
menus that are present all the time.  If the resizing does not work
correctly, this may be caused by using something like "Vim*geometry" in de
defaults.  Use "Vim.geometry" instead.

The default menus are read from the file "$VIM/menu.vim".  See |$VIM| for
where the path comes from.  You can set up your own menus.  Starting off with
the default set is a good idea.  You can add more items, or, if you don't like
the defaults at all, start with removing all menus |:unmenu-all|.


6.2 Creating New Menus					*gui_creating_menus*

					*:me* *:menu* *:noremenu*
					    *:nmenu* *:nnoremenu*
					    *:vmenu* *:vnoremenu*
					    *:imenu* *:inoremenu*
					    *:cmenu* *:cnoremenu*
To create a new menu item, use the ":menu" commands.  They are exactly like
the ":map" set of commands but the first argument is a menu item name, given
as a path of menus and submenus with a '.' between them. eg:
    :menu File.Save  :w^M
    :inoremenu File.Save  ^O:w^M
    :menu Edit.Big\ Changes.Delete\ All\ Spaces  :%s/[ ^I]//g^M

This last one will create a new item in the menu bar called "Edit", holding
the mouse button down on this will pop up a menu containing the item
"Big Changes", which is a sub-menu containing the item "Delete All Spaces",
which when selected, performs the operation.

Note that the '<' and 'k' flags in 'cpoptions' also apply here (when
included they make the <> form and raw key codes not being recognized).

							*menu-priority*
You can give a priority to a menu.  Menus with a higher priority go more to
the right.  The priority is given as a number before the ":menu" command.
Example:
    :70menu Buffer.next :bn<CR>

The default menus have these priorities:
	File	10
	Edit	20
	Syntax	50
	Help	9999

When no priority is given, 500 is used.

You can use a priority higher than 9999, to make it go after the Help menu,
but that is non-standard and is discouraged.  The highest possible priority is
about 32000.

Currently, you can only give a priority for the location of the menu in the
menu bar, not for the location of a menu item in a menu.


6.3 Showing What Menus Are Mapped To			*gui_showing_menus*

To see what an existing menu is mapped to, use just one argument after the
menu commands (just like you would with the ":map" commands).  If the menu
specified is a submenu, then all menus under that hierarchy will be shown.
If no argument is given after :menu at all, then ALL menu items are shown
for the appropriate mode (eg, Command-line mode for :cmenu).

Note that hitting <Tab> while entering a menu name after a menu command may
be used to complete the name of the menu item.


6.4 Deleting Menus					*gui_delete_menus*

			*:unmenu* *:nunmenu* *:vunmenu* *:iunmenu* *:cunmenu*
			*:unme*   *:nunme*   *:vunme*   *:iunme*   *:cunme*
To delete a menu item or a whole submenu, use the unmenu commands, which are
analogous to the unmap commands.  Eg:
    :unmenu! Edit.Paste

This will remove the Paste item from the Edit menu for Insert and
Command-line modes.

Note that hitting <Tab> while entering a menu name after an umenu command
may be used to complete the name of the menu item for the appropriate mode.

To remove all menus use:			*:unmenu-all*
	:unmenu *	" remove all menus in Normal and visual mode
	:unmenu! *	" remove all menus in Insert and Command-line mode


6.5 Examples for Menus

Here is an example on how to add menu items with menu's!  You can add a menu
item for the keyword under the cursor.  The register "z" is used.

:nmenu Words.Add\ Var	  wb"zye:menu! Words.<C-R>z <C-R>z<CR>
:nmenu Words.Remove\ Var  wb"zye:unmenu! Words.<C-R>z<CR>
:vmenu Words.Add\ Var	  "zy:menu! Words.<C-R>z <C-R>z <CR>
:vmenu Words.Remove\ Var  "zy:unmenu! Words.<C-R>z<CR>
:imenu Words.Add\ Var	  <Esc>wb"zye:menu! Words.<C-R>z <C-R>z<CR>a
:imenu Words.Remove\ Var  <Esc>wb"zye:unmenu! Words.<C-R>z<CR>a

(the rhs is in <> notation, you can copy/paste this text to try out the
mappings, or put these lines in your gvimrc; "<C-R>" is CTRL-R, "<CR>" is
the <CR> key.  |<>|)

==============================================================================
7. Extras						*gui_extras*

This section describes other features which are related to the GUI.

    - With the GUI, there is no wait for one second after hitting escape,
      because the key codes don't start with <Esc>.

    - Typing ^V followed by a special key in the GUI will insert "<Key>",
      since the internal string used is meaningless.
      Modifiers may also be held down to get "<Modifiers-Key>".

    - In the GUI, the modifiers SHIFT, CTRL, and ALT (or META) may be used
      within mappings of special keys and mouse events.  eg:
	    :map <M-LeftDrag> <LeftDrag>

    - In the GUI, several normal keys may have modifiers in mappings etc,
      these are <Space>, <Tab>, <NL>, <CR>, <Esc>.

==============================================================================
8. Shell Commands					*gui_pty*

WARNING: Executing an external command from the GUI will not always work.
"normal" commands like "ls", "grep" and "make" mostly work fine.  Commands
that require an intelligent terminal like "less" and "ispell" won't work.
Some may even hang and need to be killed from another terminal.  So be
careful!

There are two ways to do the I/O with a shell command: Pipes and a pseudo-tty.
The default is to use a pseudo-tty.  This should work best on most systems.

Unfortunately, the implementation of the pseudo-tty is different on every Unix
system.  And some systems require root permission.  To avoid running into
problems with a pseudo-tty when you least expect it, test it when not editing
a file.  Be prepared to "kill" the started command or Vim.  Commands like
":r !cat" may hang!

If using a pseudo-tty does not work for you, reset the 'guipty' option:

	:set noguipty

Using a pipe should work on any Unix system, but there are disadvantages:
- Some shell commands will notice that a pipe is being used and behave
  differently.
- ":!ls" will list the files in one column.
- The ":sh" command won't show a prompt, although it will sort of work.
- When using ":make" it's not possible to interrupt with a CTRL-C.

Typehead while the external command is running is often lost.  This happens
both with a pipe and a pseudo-tty.  This is a known problem, but it seems it
can't be fixed (or at least, it's very difficult).

==============================================================================
9. Compiling						*gui_compiling*

You need at least Motif version 1.2 and/or X11R5.  Motif 2.0 and X11R6 are OK.
Motif 1.1 and X11R4 might work, no guarantee (there may be a few problems, but
you might make it compile and run with a bit of work, please send me the
patches if you do).  The newest releases of Lesstif have been reported to
mostly work (e.g., tear-off menus don't work).

By default the Makefile tries to compile Vim with the GUI.  When the Motif
files cannot be found the Athena files will be searched for.  When both of
them cannot be found, the GUI will be disabled.  When you have the Motif or
Athena files in a directory where configure doesn't look, edit the Makefile
to enter the names of the directories.  Search for "GUI_INC_LOC" for an
example to set the Motif directories, "CONF_OPT_X" for Athena.

Don't try to mix files from different Motif, Athena and X11 versions.  This
will cause problems.  For example, using header files for X11R5 with a
library for X11R6 probably doesn't work (although the linking won't give an
error message, Vim will crash later).

The Athena version uses the Xaw widget set by default.  If you have the 3D
version, you might want to link with Xaw3d instead.  This will make the
menus look a bit better.  Edit the Makefile and look for "XAW_LIB".  The
scrollbars will remain the same, because Vim has its own, which are already
3D (in fact, they look more like Motif).

 vim:tw=78:ts=8:sw=4