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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Background

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

Problem

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.

Ideas

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.

Question

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
up vote 7 down vote accepted

Try this:

au BufWritePre set nobomb
share|improve this answer
1  
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
1  
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 '15 at 5:46
    
@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 at 16:52
    
@Hermer Ok, I see your point and I think that is valid. However, as it took so long for you to respond, my downvote on your answer is now locked and I can't change it unless you change your answer (perhaps by adding a note why the small difference is so crucial). – zagrimsan Jun 15 at 2:25

Your Answer

 
discard

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.