Vim Tips Wiki
(Change <tt> to <code>, perhaps also minor tweak.)
(Change <tt> to <code>, perhaps also minor tweak.)
Line 14: Line 14:
   
 
==Settings==
 
==Settings==
The <code>'errorbells'</code> (abbreviated as <code>'eb'</code>) option is off by default. If it is on (that is, if {{tt|:set errorbells}} is used), Vim will either beep or flash its screen when an error message is displayed. For example, the command {{tt|:set xyz}} displays an error message because <code>'xyz'</code> is not a valid option. If <code>'errorbells'</code> is on, the error message will attempt to either sound a beep or flash Vim's screen.
+
The <code>'errorbells'</code> (abbreviated as <code>'eb'</code>) option is off by default. If it is on (that is, if <code>:set errorbells</code> is used), Vim will either beep or flash its screen when an error message is displayed. For example, the command <code>:set xyz</code> displays an error message because <code>'xyz'</code> is not a valid option. If <code>'errorbells'</code> is on, the error message will attempt to either sound a beep or flash Vim's screen.
   
 
The <code>'errorbells'</code> 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).
 
The <code>'errorbells'</code> 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).
   
 
The <code>'visualbell'</code> (abbreviated as <code>'vb'</code>) option is off by default.
 
The <code>'visualbell'</code> (abbreviated as <code>'vb'</code>) option is off by default.
If it is on (that is, if {{tt|: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).
+
If it is on (that is, if <code>:set visualbell</code> 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).
   
 
The <code>'t_vb'</code> 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 <code>'t_vb'</code> to its default value. If <code>'t_vb'</code> is cleared, Vim will never flash the screen—however, it has to be cleared ''after'' the GUI has started.
 
The <code>'t_vb'</code> 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 <code>'t_vb'</code> to its default value. If <code>'t_vb'</code> is cleared, Vim will never flash the screen—however, it has to be cleared ''after'' the GUI has started.
   
If <code>'t_vb'</code> is cleared and <code>'visualbell'</code> is set, no beep and no flash will ever occur. That is achieved by entering the command {{tt|1=:set vb t_vb=}} after the GUI has started—see [[#Disable beep and flash with an autocmd|method 1]] or [[#Disable beep and flash with gvimrc|method 2]] below.
+
If <code>'t_vb'</code> is cleared and <code>'visualbell'</code> is set, no beep and no flash will ever occur. That is achieved by entering the command <code>:set vb t_vb=</code> after the GUI has started—see [[#Disable beep and flash with an autocmd|method 1]] or [[#Disable beep and flash with gvimrc|method 2]] below.
   
 
==Demonstration==
 
==Demonstration==
Line 31: Line 31:
 
</pre>
 
</pre>
   
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 {{tt|:set xyz}} and observe that an error message is displayed, but no beep occurs. Display the default settings by entering:
+
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 <code>:set xyz</code> and observe that an error message is displayed, but no beep occurs. Display the default settings by entering:
 
<pre>
 
<pre>
 
:set eb? vb? t_vb?
 
:set eb? vb? t_vb?
Line 45: Line 45:
 
Due to <code>noerrorbells</code>, no beep occurs when an error message is displayed. However, other "errors" such as pressing Esc when in normal mode will cause a beep.
 
Due to <code>noerrorbells</code>, 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 {{tt|:set vb}} to set <code>visualbell</code>. Entering {{tt|:set xyz}} will give the same result as before. However, pressing Esc should flash Vim's screen (a "visual bell").
+
Enter the command <code>:set vb</code> to set <code>visualbell</code>. Entering <code>:set xyz</code> will give the same result as before. However, pressing Esc should flash Vim's screen (a "visual bell").
   
Enter the command {{tt|1=:set t_vb=}} to clear the <code>t_vb</code> option (so it will do nothing). Entering {{tt|: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 <code>t_vb</code> 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.
+
Enter the command <code>:set t_vb=</code> to clear the <code>t_vb</code> option (so it will do nothing). Entering <code>:set xyz</code> 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 <code>t_vb</code> 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.
   
 
==Disable beep and flash with an autocmd==
 
==Disable beep and flash with an autocmd==

Revision as of 12:31, 15 July 2012

Tip 418 Printable Monobook Previous Next

created 2003 · complexity basic · version 6.0


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.

Settings

The '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.

The '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).

The '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).

The '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.

If 't_vb' is cleared and 'visualbell' is set, no beep and no flash will ever occur. That is achieved by entering the command :set vb t_vb= after the GUI has started—see method 1 or method 2 below.

Demonstration

A demonstration is useful to show how the options work. Start Vim with no initializations from vimrc or gvimrc, but using 'nocompatible' mode:

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=^[...

Due to 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 visualbell. Entering :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.

Disable beep and flash with an autocmd

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

Disable beep and flash with gvimrc

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.

Comments

Superb. Worked well for me.


Thanks so much. Very clear and helpful. But why am I unable to do a cut and paste from this wiki? What is the point of making people type up the commentary? --March 3, 2012

You should be able to copy text from the wiki! I just tried it (again) in both Firefox 10 and Internet Explorer 8 and they worked fine. At some time it was hard to see that text had been selected because the "text selected" colour was almost exactly the same as the normal colour. However, when I tried it now, the selected text was very easy to see, and Ctrl-C copied the selection. If you still have a problem, please reply here with details of what browser you are using, and what you did. JohnBeckett 00:48, March 4, 2012 (UTC)