Search code examples
vim

Execute an autocommand only once


I have an issue with using GVim on Windows. I have set up the following in my .vimrc:

if has("gui_running")
  autocmd VIMEnter * :source C:/session.vim
endif

Unfortunately this creates a problem. If I'm a the top of the file and try to move up a line (k), the screen flashes. If I hold the key for just a second it will flash a few dozen times, it is really nasty too look at.

I've tried using GUIEnter instead but I got the same results. The docs mention that I can fire an autocommand only once, but I couldn't figure out the exact syntax. Care to help?


Solution

  • As frabjous mentioned, I had to turn off the visualbell. However, the documentation mentions that the visualbell is reset to its default when the GUI starts. Putting "set vb t_vb=" on the top of a .vimrc to disable the visualbell wouldn't work, because it is reset on entry to the GUI. Instead, the trick is to disable the visualbell with an autcommand:

    autocmd GUIEnter * :set vb t_vb=