Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.


Run SQL files using pgsql that were edited with gVim on Windows.


The BOM character causes syntax errors with pgsql. I would like to edit files using gVim and, when saved, no longer have a BOM character. If the file has the BOM character, then saving it keeps the BOM character, which is not desired.


Changed the settings (Edit » Startup Settings) as follows:

set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
au BufReadPre set nobomb
au BufReadPre setlocal nobomb
au BufReadPre setglobal nobomb
au BufReadPost set nobomb 
au BufReadPost setlocal nobomb 
au BufReadPost setglobal nobomb 
au BufWritePre set nobomb
au BufWritePre setlocal nobomb
au BufWritePre setglobal nobomb
au BufWritePost set nobomb
au BufWritePost setlocal nobomb
au BufWritePost setglobal nobomb
set encoding=utf-8 nobomb    " BOM often causes trouble
setlocal nobomb
setglobal nobomb

Didn't work. I still have to type :set nobomb to explicitly remove the BOM.


How do you configure gVim so that the BOM is stripped immediately upon loading the file, without having to remember to type :set nobomb every time? (I want to set it and forget it.)

Thank you!

share|improve this question

2 Answers 2

up vote 7 down vote accepted

Try this:

au BufWritePre set nobomb
share|improve this answer
au BufWritePre * setlocal nobomb, you need to honor the {pat} argument (which is 'set' in dennis' example)... – akira Dec 7 '10 at 18:09

Add this to your .vimrc:

au BufWritePre * setlocal nobomb
share|improve this answer
Copying an already posted solution isn't going to gain you any up-votes. Please do read the existing answers and their comments before posting. – zagrimsan Oct 7 at 5:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.