Vim's Graphical User Interface


1. Introduction

1.1 How to Start the GUI Version of Vim

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...]
:gvim [+cmd] [-f] [files...]

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" or use ":gui -f". If you want the GUI to run in the foreground always, include the 'f' flag in 'guioptions'.

When the GUI starts up, the file ~/.gvimrc is sourced if it exists, and then the file ./.gvimrc. This file may contain commands 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', 'quipty', and 'guioptions'. They are documented in vim_ref8.html with all the other options.

1.2 GUI Resources

If using the Motif or Athena version of the GUI (which is the only version 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).
scrollbarWidt Thickness of scrollbars.
menuHeight Height of the menu bar.
borderWidth Thickness of border around text area.
reverseVideo Boolean: should reverse video be used?
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.

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.italColor: Cyan
Vim.underlineColor: Brown
Vim.cursorColor: DarkGreen
The first three of these are standard resources on Silicon Graphics machines which make Motif applications look even better, highly recommended!

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

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

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

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

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

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 command mode, insert mode, or on the ':' line by clicking the middle mouse button.

When in Command line mode or at the hit-return prompt 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

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

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

3.6 Mouse Mappings

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

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

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

5.2 Creating New Menus

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.

5.3 Showing What Menus Are Mapped To

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 while entering a menu name after a menu command may be used to complete the name of the menu item.

5.4 Deleting Menus

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 while entering a menu name after an umenu command may be used to complete the name of the menu item for the appropriate 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

(<> notation: \\ is backslash, <C-R> is CTRL-R)

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

Executing a shell command in the GUI doesn't work very well (yet). 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. To Do List

  • Flashes really badly in certain cases when running remotely from a sun.
  • Use different cursor and mouse shapes/colours for different modes.
  • Scrollbars with Motif 1.1 are ordered upside down! Do we care?
  • Motif steals from us, to pop up menus with the keyboard. How do we get it back if we want it?
  • click above/below thumb of scrollbar moves only 10 lines. Should be window height - 2 * 'so'.
  • 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 colours to be given. Currently it's all hard coded, the text colour, bg colour etc.
  • We need a nice little picture to go on the icon :-)
  • 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.
  • Would be nice if menu items can be specified for several modes at ones.
  • 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!

Send feedback on this page to Rajesh Kallingal
For Vim version 3.24. Last modification: 1996 Apr 25