Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

up vote 5 down vote accepted

Try this:

au BufWritePre set nobomb
share|improve this answer
    
Makes sense. Thank you! –  Dave Jarvis Dec 7 '10 at 4:02
    
Doesn't work. After editing (and saving) several files, two of them still contained the BOM. Also, after specifically editing (and saving) one of the files to have a BOM, the BOM remained in the file. Updated the question with the new gVim configuration. –  Dave Jarvis Dec 7 '10 at 16:46
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

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.