How do I customize the gvim toolbar?

I'd like to remove some of the default icons and maybe add one or two icons of my own. For example, it would be nice if there were icons for the NerdTree and the Taglist.


Ludwig's answer got me started, but it was not really the kind of answer I hoped for. So I made the question community-wiki and leave this answer with what I found out. The answer will be improved as I go along.

Find out what the toolbar currently consists of

:tmenu ToolBar

This will give you a listing of the commands currently on your toolbar. It will list the position, name and tooltip for each entry.

Delete something from the default toolbar

You can use your .gvimrc to delete entries from your default toolbar. For example, to get rid of the make command:

:aunmenu ToolBar.Make

You need to specify the menu ("ToolBar") and the name of the command ("Make").

Add a new entry to your toolbar

To add a new command to the toolbar, use the tmenu and amenu command. For example, the following commands will add an icon that will toggle the display of the taglist (of course, you need to install the taglist plugin first):

:tmenu ToolBar.taglist Toggle display of the Taglist
:amenu ToolBar.taglist :TlistToggle<CR>

Again, you need to specify the name of the menu ("ToolBar") and the name of your new menu entry ("taglist"). The name of the new entry will also be used to search for an icon. You can place the icon in your ~/.vim/bitmaps/ directory (simply create it if it doesn't exist yet). Supposedly, you need a .bmp on Windows and a .xpm everywhere else. The icon's size needs to be 18 x 18 pixels.

tmenu is responsible for the tooltip displayed when hovering the icon. Use amenu to decide what should happen when the icon is clicked.


I found this tutorial helpful. The most interesting part is quoted below:

:tmenu 1.190 ToolBar.b2u beta2unicode
:imenu ToolBar.b2u <Esc>:source ~/.vim/scripts/beta2unicode<CR>

In the first line 1.190 indicates a position on the toolbar. In ToolBar.b2u “b2u” is the name of the image (without the bmp extension). The last item on the first line is a short description of the action associated with the icon (or button, as you want to call it) on the toolbar.

In the second line, ToolBar.b2u follows the same logic as on in the first line. The last part,

:source ~/.vim/scripts/beta2unicode.vim

starts with a change of the Vim mode to the command line mode. The command is to “source” (to interpret and execute) the script. The VIMHOME here is ~/.vim/. The folder in the VIMHOME is scripts| and \verb|beta2unicode.vim is the name of the script. is the equivalent of pressing the Enter key.

It basically works like adding other menus. You can find the details in vim's help (:help menu).