This gist demonstrates/explains how I customised my Windows gvim toolbar.
-
I have to use Windows for my work device and I am not against using a mouse sometimes. That is, I am not an anti-mouse zealot ― if it makes sense, use it, though I have very long period of mouseless goodness on my Planck 40% keyboard-only. (That’s great too!)
-
I prefer gvim in general. There are all sorts of benefits, from being able to toggle character 'renderoptions', having a toolbar for the few things I like it for (e.g., toggling the menu and spell checking, which is one of the few things I feel is better with a mouse), and more. Also, I use my own statusline, vim-tene, which requires a built-in function not available in one increasingly popular fork of Vim.
Calling it for what it is, the default toolbar looks (IMO) unattractive and dated. It also has heaps of buttons I am not interested in using:
Having not seen any other gvim toolbar customisations, I thought it was worth turning what I did with mine into a gist. This is what my gvim toolbar looks like:
Key differences:
-
The “1990s” buttons are out; use simple greyscale-like ones.
-
Pointless (IMO) buttons like Find, Vim Help, and Search Vim are removed.
-
Useful things (again, IMO) like a spell check toggle, next misspelled word, and menu toggle buttons are added.
|
ℹ️
|
The last point is worth explaining. Although I rarely use the menu, having it easily accessible with a toggle is handy. There are some commands that are harder to remember, yet are quickly found in the default menu. Easy. The purists will disagree, but that is okay ― everyone for their own. 😁️ |
-
Added code to my
~\_gvimrc, which entirely removes the default toolbar and replaces it with mine. -
Created 18 x 18 pixel images for replacement (and my new) toolbar buttons.
-
Added the images to where they need to be when gvim starts.
These points are explained below.
I added the following to my
~\_gvimrc:
if has("toolbar")
if len(split(execute('amenu ToolBar'), '\n')) > 0
aunmenu ToolBar
endif
anoremenu 1.10 ToolBar.Open :browse confirm e<CR>
tmenu ToolBar.Open Open file
anoremenu 1.20 ToolBar.Mks :execute "browse mksession! " .. strftime("%Y-%m-%d")<CR>
tmenu ToolBar.Mks Save current session
anoremenu 1.30 ToolBar.Run :browse source<CR>
tmenu ToolBar.Run Run a Vim Script / Load a session
if has("printer") && !has("unix")
anoremenu 1.40 ToolBar.Print :hardcopy<CR>
vnoremenu ToolBar.Print :hardcopy<CR>
elseif has("unix")
anoremenu 1.40 ToolBar.Print :w !lpr<CR>
vnoremenu ToolBar.Print :w !lpr<CR>
endif
tmenu ToolBar.Print Print
anoremenu 1.45 ToolBar.-sep1- <Nop>
anoremenu 1.50 ToolBar.Undo u
tmenu ToolBar.Undo Undo
anoremenu 1.60 ToolBar.Redo <C-R>
tmenu ToolBar.Redo Redo
anoremenu 1.65 ToolBar.-sep2- <Nop>
vnoremenu 1.70 ToolBar.Cut "+x
tmenu ToolBar.Cut Cut to clipboard
vnoremenu 1.80 ToolBar.Copy "+y
cnoremenu 1.80 ToolBar.Copy <C-Y>
tmenu ToolBar.Copy Copy to clipboard
nnoremenu 1.90 ToolBar.Paste "+gP
cnoremenu 1.90 ToolBar.Paste <C-R>+
exe 'vnoremenu <script> ToolBar.Paste ' .. paste#paste_cmd['v']
exe 'inoremenu <script> ToolBar.Paste ' .. paste#paste_cmd['i']
tmenu ToolBar.Paste Paste from Clipboard
anoremenu 1.95 ToolBar.-sep3- <Nop>
anoremenu <silent> 1.100 ToolBar.Spell :let &spell = &spell==0 ? 1 : 0<CR>
tmenu ToolBar.Spell Toggle spell checking
anoremenu <silent> 1.110 ToolBar.SpellNext ]s
tmenu ToolBar.SpellNext Next misspelled word
anoremenu 1.115 ToolBar.-sep4- <Nop>
anoremenu 1.120 ToolBar.Menu :execute "if &guioptions=~'m' \| set guioptions-=m \| else \| set guioptions+=m \| endif"<CR>
tmenu ToolBar.Menu Toggle menu
endifThis completely replaces the default toolbar (aunmenu ToolBar).
The rest sequentially adds my ToolBar items
(anoremenu) and
tooltips (tmenu).
This works equally well with Linux (I also use gvim in Debian 12 as well as WSL Debian 12).
The replacement images are 18 x 18 pixel bitmaps, which is what the Vim help at gui-toolbar says works best.
In order of appearance on my toolbar, they are:
― Open.bmp ― Mks.bmp ― Run.bmp ― Print.bmp ― Undo.bmp ― Redo.bmp ― Cut.bmp ― Copy.bmp ― Paste.bmp ― Spell.bmp ― SpellNext.bmp ― Menu.bmp
They are available in _gvim-toolbar-bmps.zip.
|
ℹ️
|
Creating the bitmaps
I created them using a mix of very downsized icon images and building them myself using the very low-tech Microsoft Paint, believe it or not. There are also Linux gvim-compatible .xpm versions, which are explained below. |
As the gui-toolbar help says,
when put into ~\vimfiles\bitmaps the images will override the defaults
(where applicable) or otherwise be used where the
anoremenu
command matches the .bmp name,
e.g., anoremenu 1.120 ToolBar.Menu … will use
~\vimfiles\bitmaps\Menu.bmp.
I’ve done something similar with my Debian Linux gvim toolbar. There is no difference to the ~\_gvimrc code (though it is in a .gvimrc, of course).
The $HOME/.vim/bitmaps directory should be used for the images, which, as vim’s help outlines, is still called “bitmaps” even though the files are xpm files. A .tar of those .xpm files: _gvim-toolbar-xpms.tar.





