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!

2 Answers 2


Try this:

au BufWritePre set nobomb
  • 1
    au BufWritePre * setlocal nobomb, you need to honor the {pat} argument (which is 'set' in dennis' example)...
    – akira
    Dec 7, 2010 at 18:09

Add this to your .vimrc:

au BufWritePre * setlocal nobomb

(Taken from a comment to another answer as this is actually a better solution.)

  • @zagrimsan The other solution is a bit different. An identical solution is posted as a comment rather as an answer. Personally, when I come to a thread, I would like to see a proper answer that I can use without having to read all the comments. This answer is just it. I guess you wanted to down-vote me, but instead you have down-voted the best answer in this thread.
    – Hermes
    Jun 14, 2016 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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