Vim may beep or may flash its window if an error occurs. This tip explains the settings that control these functions, and shows how to disable beeping and flashing in both terminal Vim and GUI Vim (gvim). See below if you just want the solution.
'errorbells' (abbreviated as
'eb') option is off by default. If it is on (that is, if
:set errorbells is used), Vim will either beep or flash its screen when an error message is displayed. For example, the command
:set xyz displays an error message because
'xyz' is not a valid option. If
'errorbells' is on, the error message will attempt to either sound a beep or flash Vim's screen.
'errorbells' option has no effect on the beeps that Vim makes when an error message is not displayed (for example, on pressing Esc when in normal mode).
'visualbell' (abbreviated as
'vb') option is off by default.
If it is on (that is, if
:set visualbell is used), Vim will flash its screen instead of sounding a beep (that is, at times when a beep would have occurred, the screen will flash instead).
't_vb' option, by default, is set to a code that will cause the screen to flash. Starting the GUI (which occurs after vimrc is read) resets
't_vb' to its default value. If
't_vb' is cleared, Vim will never flash the screen—however, it has to be cleared after the GUI has started.
A demonstration is useful to show how the options work. Start Vim with no initializations from vimrc or gvimrc, but using
vim -N -u NONE
In Vim, press Esc. If your sound system is working, you should hear your system's version of a "bell" (often a beep). Enter the command
:set xyz and observe that an error message is displayed, but no beep occurs. Display the default settings by entering:
:set eb? vb? t_vb?
Vim will display something like (the
^[... depends on your system):
noerrorbells novisualbell t_vb=^[...
noerrorbells, no beep occurs when an error message is displayed. However, other "errors" such as pressing Esc when in normal mode will cause a beep.
Enter the command
:set vb to set
:set xyz will give the same result as before. However, pressing Esc should flash Vim's screen (a "visual bell").
Enter the command
:set t_vb= to clear the
t_vb option (so it will do nothing). Entering
:set xyz will give the same result as before (a message but no beep or flash). However, pressing Esc should also do nothing (no beep and no flash). The
t_vb option controls how Vim flashes the screen (on both Unix and Windows systems, for both terminal and gui Vim). If the option is empty, Vim does not flash the screen.
To disable beeping (aka "bell") and window flashing, put the following in your vimrc. This works on Unix and Windows systems for both terminal and GUI Vim.
set noerrorbells visualbell t_vb= autocmd GUIEnter * set visualbell t_vb=
The same commands can be entered using abbreviations:
set noeb vb t_vb= au GUIEnter * set vb t_vb=
The above will give an error message if run on a Vim which was not compiled with the
+autocmd feature. To avoid that possibility, use:
set noerrorbells visualbell t_vb= if has('autocmd') autocmd GUIEnter * set visualbell t_vb= endif
Another method to disable beeping and flashing is to put a command into your vimrc to handle terminal Vim, and another command into your gvimrc to handle gvim. This works on Unix and Windows systems.
Put the following in vimrc:
set noeb vb t_vb=
Put the following in gvimrc:
set vb t_vb=
The gvimrc file is in the same directory as vimrc; see vimrc for the proper file name.