diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index a6dc3114378ef00c897ee2b65b8612704fa9fc80..5589fe567fc1b4f4191057067e0d932820c81ac8 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -217,6 +217,7 @@ struct EditorManagerPrivate {
     QString m_externalEditor;
 
     IFile::ReloadSetting m_reloadSetting;
+    IFile::Utf8BomSetting m_utf8BomSetting;
 };
 }
 
@@ -237,7 +238,8 @@ EditorManagerPrivate::EditorManagerPrivate(ICore *core, QWidget *parent) :
     m_openInExternalEditorAction(new QAction(EditorManager::tr("Open in External Editor"), parent)),
     m_windowPopup(0),
     m_coreListener(0),
-    m_reloadSetting(IFile::AlwaysAsk)
+    m_reloadSetting(IFile::AlwaysAsk),
+    m_utf8BomSetting(IFile::OnlyKeep)
 {
     m_editorModel = new OpenEditorsModel(parent);
 }
@@ -1792,6 +1794,7 @@ bool EditorManager::restoreState(const QByteArray &state)
 static const char * const documentStatesKey = "EditorManager/DocumentStates";
 static const char * const externalEditorKey = "EditorManager/ExternalEditorCommand";
 static const char * const reloadBehaviorKey = "EditorManager/ReloadBehavior";
+static const char * const utf8BomBehaviorKey = "EditorManager/Utf8BomBehavior";
 
 void EditorManager::saveSettings()
 {
@@ -1799,6 +1802,7 @@ void EditorManager::saveSettings()
     settings->setValue(QLatin1String(documentStatesKey), m_d->m_editorStates);
     settings->setValue(QLatin1String(externalEditorKey), m_d->m_externalEditor);
     settings->setValue(QLatin1String(reloadBehaviorKey), m_d->m_reloadSetting);
+    settings->setValue(QLatin1String(utf8BomBehaviorKey), m_d->m_utf8BomSetting);
 }
 
 void EditorManager::readSettings()
@@ -1824,6 +1828,9 @@ void EditorManager::readSettings()
 
     if (settings->contains(QLatin1String(reloadBehaviorKey)))
         m_d->m_reloadSetting = (IFile::ReloadSetting)settings->value(QLatin1String(reloadBehaviorKey)).toInt();
+
+    if (settings->contains(QLatin1String(utf8BomBehaviorKey)))
+        m_d->m_utf8BomSetting = (IFile::Utf8BomSetting)settings->value(QLatin1String(utf8BomBehaviorKey)).toInt();
 }
 
 
@@ -1991,6 +1998,16 @@ IFile::ReloadSetting EditorManager::reloadSetting() const
     return m_d->m_reloadSetting;
 }
 
+void EditorManager::setUtf8BomSetting(IFile::Utf8BomSetting behavior)
+{
+    m_d->m_utf8BomSetting = behavior;
+}
+
+IFile::Utf8BomSetting EditorManager::utf8BomSetting() const
+{
+    return m_d->m_utf8BomSetting;
+}
+
 QTextCodec *EditorManager::defaultTextEncoding() const
 {
     QSettings *settings = Core::ICore::instance()->settings();
diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h
index caab7f0f6cd165f995f47e823a72080c46a3827d..6b55561dc68d89e24a5d39380a33be52e97b0822 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.h
+++ b/src/plugins/coreplugin/editormanager/editormanager.h
@@ -192,6 +192,9 @@ public:
     void setReloadSetting(IFile::ReloadSetting behavior);
     IFile::ReloadSetting reloadSetting() const;
 
+    void setUtf8BomSetting(IFile::Utf8BomSetting behavior);
+    IFile::Utf8BomSetting utf8BomSetting() const;
+
     QTextCodec *defaultTextEncoding() const;
 
     // Helper to display a message dialog when encountering a read-only
diff --git a/src/plugins/coreplugin/generalsettings.ui b/src/plugins/coreplugin/generalsettings.ui
index 6e4f9f9384a2b8195311335ce105da418d449c70..a44dfdef5a30a15acd1aa5738e8a47ef18bfc121 100644
--- a/src/plugins/coreplugin/generalsettings.ui
+++ b/src/plugins/coreplugin/generalsettings.ui
@@ -104,6 +104,46 @@
         </item>
        </layout>
       </item>
+      <item row="3" column="0">
+       <widget class="QLabel" name="encodingLabel">
+        <property name="text">
+         <string>Default file encoding: </string>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="1">
+       <layout class="QHBoxLayout" name="horizontalLayout_6">
+        <item>
+         <widget class="QComboBox" name="encodingBox">
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
+          </property>
+          <property name="sizeAdjustPolicy">
+           <enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
+          </property>
+          <property name="minimumContentsLength">
+           <number>20</number>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer name="horizontalSpacer_6">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>285</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+       </layout>
+      </item>
       <item row="2" column="0">
        <widget class="QLabel" name="languageLabel">
         <property name="text">
diff --git a/src/plugins/coreplugin/ifile.h b/src/plugins/coreplugin/ifile.h
index 6042ee51994d0430f638ca2286e975c747aaa3a1..7bb2924ede77c3d26897655ef5c1918cc1826b11 100644
--- a/src/plugins/coreplugin/ifile.h
+++ b/src/plugins/coreplugin/ifile.h
@@ -50,6 +50,12 @@ public:
         IgnoreAll = 2
     };
 
+    enum Utf8BomSetting {
+        AlwaysAdd = 0,
+        OnlyKeep = 1,
+        AlwaysDelete = 2
+    };
+
     enum ChangeTrigger {
         TriggerInternal,
         TriggerExternal
diff --git a/src/plugins/texteditor/basetextdocument.cpp b/src/plugins/texteditor/basetextdocument.cpp
index e52a38899c038335e8964aca2f0c264e693b0560..f8463fef7ef301bb9e372459d26a7e6ed10e54e9 100644
--- a/src/plugins/texteditor/basetextdocument.cpp
+++ b/src/plugins/texteditor/basetextdocument.cpp
@@ -133,6 +133,7 @@ BaseTextDocument::BaseTextDocument()
     m_fileIsReadOnly = false;
     m_isBinaryData = false;
     m_codec = Core::EditorManager::instance()->defaultTextEncoding();
+    m_fileHasUtf8Bom = false;
     m_hasDecodingError = false;
 }
 
@@ -187,6 +188,12 @@ bool BaseTextDocument::save(const QString &fileName)
     if (m_lineTerminatorMode == CRLFLineTerminator)
         plainText.replace(QLatin1Char('\n'), QLatin1String("\r\n"));
 
+    Core::IFile::Utf8BomSetting utf8bomSetting = Core::EditorManager::instance()->utf8BomSetting();
+    if (m_codec->name() == "UTF-8" &&
+        (utf8bomSetting == Core::IFile::AlwaysAdd || (utf8bomSetting == Core::IFile::OnlyKeep && m_fileHasUtf8Bom))) {
+        file.write("\xef\xbb\xbf", 3);
+    }
+
     file.write(m_codec->fromUnicode(plainText));
     if (!file.flush())
         return false;
@@ -259,6 +266,7 @@ bool BaseTextDocument::open(const QString &fileName)
         int bytesRead = buf.size();
 
         QTextCodec *codec = m_codec;
+        m_fileHasUtf8Bom = false;
 
         // code taken from qtextstream
         if (bytesRead >= 4 && ((uchar(buf[0]) == 0xff && uchar(buf[1]) == 0xfe && uchar(buf[2]) == 0 && uchar(buf[3]) == 0)
@@ -267,6 +275,9 @@ bool BaseTextDocument::open(const QString &fileName)
         } else if (bytesRead >= 2 && ((uchar(buf[0]) == 0xff && uchar(buf[1]) == 0xfe)
                                       || (uchar(buf[0]) == 0xfe && uchar(buf[1]) == 0xff))) {
             codec = QTextCodec::codecForName("UTF-16");
+        } else if (bytesRead >= 3 && ((uchar(buf[0]) == 0xef && uchar(buf[1]) == 0xbb) && uchar(buf[2]) == 0xbf)) {
+            codec = QTextCodec::codecForName("UTF-8");
+            m_fileHasUtf8Bom = true;
         } else if (!codec) {
             codec = QTextCodec::codecForLocale();
         }
diff --git a/src/plugins/texteditor/basetextdocument.h b/src/plugins/texteditor/basetextdocument.h
index cd503276b333291e32d8d967b895e60cc05fdcd9..dd9f93f5233a614228ba25097451191942444517 100644
--- a/src/plugins/texteditor/basetextdocument.h
+++ b/src/plugins/texteditor/basetextdocument.h
@@ -142,6 +142,7 @@ private:
     };
     LineTerminatorMode m_lineTerminatorMode;
     QTextCodec *m_codec;
+    bool m_fileHasUtf8Bom;
 
     bool m_fileIsReadOnly;
     bool m_isBinaryData;
diff --git a/src/plugins/texteditor/behaviorsettingspage.cpp b/src/plugins/texteditor/behaviorsettingspage.cpp
index fdf5c8e2eebbedb2f33302edda7acf04231c1442..2176dc6dba5e389074fc86d42faa0ea1d196a611 100644
--- a/src/plugins/texteditor/behaviorsettingspage.cpp
+++ b/src/plugins/texteditor/behaviorsettingspage.cpp
@@ -36,6 +36,7 @@
 
 #include <coreplugin/icore.h>
 #include <coreplugin/coreconstants.h>
+#include <coreplugin/editormanager/editormanager.h>
 
 #include <QtCore/QSettings>
 #include <QtCore/QTextCodec>
@@ -135,6 +136,8 @@ QWidget *BehaviorSettingsPage::createPage(QWidget *parent)
             m_d->m_page.encodingBox->setCurrentIndex(i);
     }
 
+    m_d->m_page.utf8BomBox->setCurrentIndex(Core::EditorManager::instance()->utf8BomSetting());
+
     return w;
 }
 
@@ -177,6 +180,8 @@ void BehaviorSettingsPage::apply()
     settings->setValue(QLatin1String(Core::Constants::SETTINGS_DEFAULTTEXTENCODING),
                        m_codecs.at(m_d->m_page.encodingBox->currentIndex())->name());
 
+    Core::EditorManager::instance()->setUtf8BomSetting(
+                Core::IFile::Utf8BomSetting(m_d->m_page.utf8BomBox->currentIndex()));
 }
 
 void BehaviorSettingsPage::settingsFromUI(TabSettings &tabSettings,
diff --git a/src/plugins/texteditor/behaviorsettingspage.ui b/src/plugins/texteditor/behaviorsettingspage.ui
index 4aa89f81d6e59d1e42c126078bc0969d277a6de7..f0a21f0e406011699c7826e264b0065c7b771a4c 100644
--- a/src/plugins/texteditor/behaviorsettingspage.ui
+++ b/src/plugins/texteditor/behaviorsettingspage.ui
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>576</width>
+    <width>662</width>
     <height>538</height>
    </rect>
   </property>
@@ -442,6 +442,13 @@ Influences the indentation of continuation lines.
       <string>File Encodings</string>
      </property>
      <layout class="QGridLayout" name="gridLayout_4">
+      <item row="0" column="0">
+       <widget class="QLabel" name="encodingLabel">
+        <property name="text">
+         <string>Default encoding: </string>
+        </property>
+       </widget>
+      </item>
       <item row="0" column="1">
        <layout class="QHBoxLayout" name="horizontalLayout_6">
         <item>
@@ -475,14 +482,63 @@ Influences the indentation of continuation lines.
         </item>
        </layout>
       </item>
-      <item row="0" column="0">
-       <widget class="QLabel" name="encodingLabel">
+      <item row="1" column="0">
+       <widget class="QLabel" name="utf8BomLabel">
         <property name="text">
-         <string>Default encoding: </string>
+         <string>UTF-8 BOM:</string>
         </property>
        </widget>
       </item>
-      <item row="1" column="0" colspan="2">
+      <item row="1" column="1">
+       <layout class="QHBoxLayout" name="horizontalLayout_4">
+        <item>
+         <widget class="QComboBox" name="utf8BomBox">
+          <property name="toolTip">
+           <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
+&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
+p, li { white-space: pre-wrap; }
+&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
+&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;How text editors should deal with UTF-8 Byte Order Marks. The options are:&lt;/p&gt;
+&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;Add If Encoding Is UTF-8:&lt;/span&gt; always add a BOM when saving a file in UTF-8 encoding. Note that this will not work if the encoding is &lt;span style=&quot; font-style:italic;&quot;&gt;System&lt;/span&gt;, as Qt Creator does not know what it actually is.&lt;/li&gt;
+&lt;li style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;Keep If Already Present: &lt;/span&gt;save the file with a BOM if it already had one when it was loaded.&lt;/li&gt;
+&lt;li style=&quot; margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;Always Delete:&lt;/span&gt; never write an UTF-8 BOM, possibly deleting a pre-existing one.&lt;/li&gt;&lt;/ul&gt;
+&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Note that UTF-8 BOMs are uncommon and treated incorrectly by some editors, so it usually makes little sense to add any.&lt;/p&gt;
+&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;This setting does &lt;span style=&quot; font-weight:600;&quot;&gt;not&lt;/span&gt; influence the use of UTF-16 and UTF-32 BOMs.&lt;/p&gt;
+&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+          </property>
+          <item>
+           <property name="text">
+            <string>Add If Encoding Is UTF-8</string>
+           </property>
+          </item>
+          <item>
+           <property name="text">
+            <string>Keep If Already Present</string>
+           </property>
+          </item>
+          <item>
+           <property name="text">
+            <string>Always Delete</string>
+           </property>
+          </item>
+         </widget>
+        </item>
+        <item>
+         <spacer name="horizontalSpacer_4">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+       </layout>
+      </item>
+      <item row="2" column="0" colspan="2">
        <spacer name="verticalSpacer_2">
         <property name="orientation">
          <enum>Qt::Vertical</enum>