*vim_gui.txt*   For Vim version 4.5.  Last modification: 1996 Oct 12


		       Vim's Graphical User Interface


	1. Introduction				*gui_intro* *gui* *gvim*

1.1 How to Start the GUI Version of Vim			*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.  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 gvimrc exists, it is sourced.  The name if this file is
  something like "/usr/local/share/vim/gvimrc".  You can check this with
  ":version".
- 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.

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 'guifont', 'guipty' and 'guioptions'.  They are documented
in |vim_ref.txt| with all the other options.


1.2 GUI Resources					*gui_resources*

If using the Motif or Athena version of the GUI (which are the only versions
available at the moment), 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.
    boldColor		Color of bold text.
    italicColor		Color of italic text.
    underlineColor	Color of underlined text.
    cursorColor		Color of the cursor.
    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.boldColor:			Blue
Vim.italicColor:		Magenta
Vim.underlineColor:		Brown
Vim.cursorColor:		DarkGreen
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*
   -bold <color>	Use <color> for bold text	*-bold*
   -italic <color>	Use <color> for italic text	*-italic*
   -underline <color>	Use <color> for underlined text	*-underline*
   -ul <color>		idem				*-ul*
   -cursor <color>	Use <color> for cursor		*-cursor*
   -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*


	2. 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.


2.1 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.


2.2 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.


	3. 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.


3.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.


3.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.


3.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.


3.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.


3.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")


3.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.


	4. 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.


	5. Menus					*gui_menus*

5.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.

To help you set up your own menus, you can start off with the default set.
See |vim_menu.txt| for a set of menu commands that recreates the default
menus.  You can insert this in your .gvimrc file and change it to your
liking.

5.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).


5.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.


5.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 *	" remove all menus in Normal and visual mode
	:unmenu! *	" remove all menus in Insert and Command-line mode


5.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.  |<>|)


	6. 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>.


	7. Shell Commands				*gui_pty*

WARNING: Executing an external command from the GUI will not always work.
"normal" commands like "ls", "grep" and "make" 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 pipes.  This should work on any Unix
system.  The disadvantage is that some shell commands will notice that a
pipe is being used and behave differently.  The ":sh" command won't show a
prompt, although it will sort of work.  ":!ls" will list the files in one
column.

Alternatively a pseudo-tty can be used.  Unfortunately, the implementation of
this is different on every Unix system.  And many systems require root
permission.  Still this might work better than pipes on some systems.  To
see if this works better for you set the 'guipty' option on.  Be prepared to
"kill" the started command or Vim, commands like ":r !cat" may hang!


	8. 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 don't work properly (but you might make it work
with a bit of 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).


	9. To Do List					*gui_todo*

    - Flashes really badly in certain cases when running remotely from a
      Sun.

    - When taking the geometry of the window where gvim was started, check
      that the GUI window will fit on the screen.

    - Window should be redrawn when resizing at the hit-return prompt.

    - Use different cursor and mouse shapes/colors for different modes.

    - Scrollbars with Motif 1.1 are ordered upside down!  Do we care?

    - Motif steals <F10> from us, to pop up menus with the keyboard.  How do
      we get it back if we want it?

    - Paste in Insert mode should not do autowrap etc.

    - Option/resource to use pointer focus from the mouse to select the
      current Vim window.

    - Add a new command :highlight for specifying how various things should
      be highlighted, allowing colors to be given.  Currently it's all hard
      coded, the text color, bg color etc.

    - We need a nice little picture to go on the icon :-)  But how do we do
      that?

    - ":menu" should take count for where the menu is inserted (for first
      menu item that doesn't exist yet)

    - Would be nice if menu items can be specified for several modes at
      once.

    - Make better default menus!

    - Add "Buffers" menu, list of (hidden) buffers.

    - Add menu item to "Keep Insert mode". More generally: Include a nice
      way to change options.

    - When using a pseudo-tty Vim should behave like some terminal. Terminal
      codes to/from shell should be translated.

    - Make it easy to specify a shorcut (key) for a menu item.

    - :mkgvimrc command, that includes menus.

    - Would it be useful to be able to quit the GUI and go back to the
      terminal where it was started from?

    - Finish off the todo list!


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