轉載請註明連結與作者huihui1988
用了一段時間的vim,喜歡上了這種簡潔高效的編輯器。恰逢正在學習QT中,於是將vim變成了開發QT的工具。以下是具體配置。
一、文法高亮支援:1、開啟VIMDIR/vim72/syntax/cpp.vim,加入
syn keyword cppStatement SLOT,SIGNAL
syn keyword cppAccess slots,signals
2、增加QT的類型名:syn keyword cType ActiveQt Q3Accel Q3Action Q3ActionGroup Q3AsciiBucket Q3AsciiCache Q3AsciiCacheIterator Q3AsciiDict Q3AsciiDictIterator Q3BaseBucket Q3BoxLayout Q3Button Q3ButtonGroup Q3CString Q3Cache Q3CacheIterator Q3Canvas Q3CanvasEllipse Q3CanvasItem Q3CanvasItemList Q3CanvasLine Q3CanvasPixmap Q3CanvasPixmapArray Q3CanvasPolygon Q3CanvasPolygonalItem Q3CanvasRectangle Q3CanvasSpline Q3CanvasSprite Q3CanvasText Q3CanvasView Q3CheckListItem Q3CheckTableItem Q3CleanupHandler Q3ColorDrag Q3ComboBox Q3ComboTableItem Q3DataBrowser Q3DataTable Q3DataView Q3DateEdit Q3DateTimeEdit Q3DateTimeEditBase Q3DeepCopy Q3Dict Q3DictIterator Q3Dns Q3DnsSocket Q3DockArea Q3DockAreaLayout Q3DockWindow Q3DragObject Q3DropSite Q3EditorFactory Q3FileDialog Q3FileIconProvider Q3FilePreview Q3Frame Q3Ftp Q3GArray Q3GCache Q3GCacheIterator Q3GDict Q3GDictIterator Q3GList Q3GListIterator Q3GListStdIterator Q3GVector Q3Grid Q3GridLayout Q3GridView Q3GroupBox Q3HBox Q3HBoxLayout Q3HButtonGroup Q3HGroupBox Q3Header Q3Http Q3HttpHeader Q3HttpRequestHeader Q3HttpResponseHeader Q3IconDrag Q3IconDragItem Q3IconView Q3IconViewItem Q3ImageDrag Q3IntBucket Q3IntCache Q3IntCacheIterator Q3IntDict Q3IntDictIterator Q3LNode Q3ListBox Q3ListBoxItem Q3ListBoxPixmap Q3ListBoxText Q3ListView Q3ListViewItem Q3ListViewItemIterator Q3LocalFs Q3MainWindow Q3MemArray Q3MimeSourceFactory Q3MultiLineEdit Q3NetworkOperation Q3NetworkProtocol Q3NetworkProtocolDict Q3NetworkProtocolFactory Q3NetworkProtocolFactoryBase Q3ObjectDictionary Q3PaintDeviceMetrics Q3Painter Q3Picture Q3PointArray Q3PolygonScanner Q3PopupMenu Q3Process Q3ProgressBar Q3ProgressDialog Q3PtrBucket Q3PtrCollection Q3PtrDict Q3PtrDictIterator Q3PtrList Q3PtrListIterator Q3PtrListStdIterator Q3PtrQueue Q3PtrStack Q3PtrVector Q3RangeControl Q3ScrollView Q3Semaphore Q3ServerSocket Q3Shared Q3Signal Q3SimpleRichText Q3SingleCleanupHandler Q3Socket Q3SocketDevice Q3SortedList Q3SpinWidget Q3SqlCursor Q3SqlEditorFactory Q3SqlFieldInfo Q3SqlFieldInfoList Q3SqlForm Q3SqlPropertyMap Q3SqlRecordInfo Q3SqlSelectCursor Q3StoredDrag Q3StrIList Q3StrIVec Q3StrList Q3StrListIterator Q3StrVec Q3StringBucket Q3StyleSheet Q3StyleSheetItem Q3SyntaxHighlighter Q3TSFUNC Q3TabDialog Q3Table Q3TableItem Q3TableSelection Q3TextBrowser Q3TextDrag Q3TextEdit Q3TextEditOptimPrivate Q3TextStream Q3TextView Q3TimeEdit Q3ToolBar Q3UriDrag Q3Url Q3UrlOperator Q3VBox Q3VBoxLayout Q3VButtonGroup Q3VGroupBox Q3ValueList Q3ValueListConstIterator Q3ValueListIterator Q3ValueStack Q3ValueVector Q3WhatsThis Q3WidgetStack Q3Wizard QAssistantClient QAbstractEventDispatcher QAbstractFileEngine QAbstractFileEngineHandler QAbstractItemModel QAbstractListModel QAbstractTableModel QArgument QAtomic QAtomicPointer QBasicAtomic QBasicAtomicPointer QBasicTimer QBitArray QBitRef QBool QBuffer QByteArray QByteArrayMatcher QByteRef QCOORD QCache QChar QCharRef QChildEvent QConstString QCoreApplication QCustomEvent QDataStream QDate QDateTime QDebug QDir QEvent QEventLoop QFSFileEngine QFactoryInterface QFile QFileInfo QFileInfoList QFileInfoListIterator QFileSystemWatcher QFlag QFlags QForeachContainer QForeachContainerBase QGenericArgument QGenericReturnArgument QGlobalStatic QHash QHashData QHashDummyNode QHashDummyValue QHashIterator QHashNode QIODevice QIntForSize QIntForType QInternal QLatin1Char QLatin1String QLibrary QLibraryInfo QLine QLineF QLinkedList QLinkedListData QLinkedListIterator QLinkedListNode QList QListData QListIterator QLocale QMap QMapData QMapIterator QMetaClassInfo QMetaEnum QMetaMethod QMetaObject QMetaProperty QMetaType QMetaTypeId QMimeData QModelIndex QModelIndexList QMultiHash QMultiMap QMutableHashIterator QMutableLinkedListIterator QMutableListIterator QMutableMapIterator QMutableSetIterator QMutableStringListIterator QMutableVectorIterator QMutex QMutexLocker QNoDebug QNoImplicitBoolCast QObject QObjectCleanupHandler QObjectData QObjectList QObjectUserData QPair QPersistentModelIndex QPluginLoader QPoint QPointF QPointer QProcess QQueue QReadLocker QReadWriteLock QRect QRectF QRegExp QResource QReturnArgument QSemaphore QSet QSetIterator QSettings QSharedData QSharedDataPointer QSignalMapper QSize QSizeF QSocketNotifier QStack QStdWString QString QStringList QStringListIterator QStringMatcher QSysInfo QSystemLocale QTS QTemporaryFile QTextCodec QTextCodecFactoryInterface QTextCodecPlugin QTextDecoder QTextEncoder QTextIStream QTextOStream QTextStream QTextStreamFunction QTextStreamManipulator QThread QThreadStorage QThreadStorageData QTime QTimeLine QTimer QTimerEvent QTranslator QTypeInfo QUintForSize QUintForType QUrl QUuid QVarLengthArray QVariant QVariantComparisonHelper QVariantList QVariantMap QVector QVectorData QVectorIterator QVectorTypedData QWaitCondition QWriteLocker Q_INT16 Q_INT32 Q_INT64 Q_INT8 Q_LLONG Q_LONG Q_PID Q_UINT16 Q_UINT32 Q_UINT64 Q_UINT8 Q_ULLONG Q_ULONG QDBusAbstractAdaptor QDBusAbstractInterface QDBusArgument QDBusConnection QDBusConnectionInterface QDBusError QDBusInterface QDBusMessage QDBusMetaType QDBusObjectPath QDBusReply QDBusServer QDBusSignature QDBusVariant QAbstractExtensionFactory QAbstractExtensionManager QAbstractFormBuilder QDesignerActionEditorInterface QDesignerBrushManagerInterface QDesignerComponents QDesignerContainerExtension QDesignerCustomWidgetCollectionInterface QDesignerCustomWidgetInterface QDesignerDnDItemInterface QDesignerExportWidget QDesignerExtraInfoExtension QDesignerFormEditorInterface QDesignerFormEditorPluginInterface QDesignerFormWindowCursorInterface QDesignerFormWindowInterface QDesignerFormWindowManagerInterface QDesignerFormWindowToolInterface QDesignerIconCacheInterface QDesignerLayoutDecorationExtension QDesignerMemberSheetExtension QDesignerMetaDataBaseInterface QDesignerMetaDataBaseItemInterface QDesignerObjectInspectorInterface QDesignerPropertyEditorInterface QDesignerPropertySheetExtension QDesignerTaskMenuExtension QDesignerWidgetBoxInterface QDesignerWidgetDataBaseInterface QDesignerWidgetDataBaseItemInterface QDesignerWidgetFactoryInterface QExtensionFactory QExtensionManager QFormBuilder QAbstractButton QAbstractGraphicsShapeItem QAbstractItemDelegate QAbstractItemView QAbstractPageSetupDialog QAbstractPrintDialog QAbstractProxyModel QAbstractScrollArea QAbstractSlider QAbstractSpinBox QAbstractTextDocumentLayout QAbstractUndoItem QAccessible QAccessibleApplication QAccessibleBridge QAccessibleBridgeFactoryInterface QAccessibleBridgePlugin QAccessibleEvent QAccessibleFactoryInterface QAccessibleInterface QAccessibleObject QAccessiblePlugin QAccessibleWidget QAction QActionEvent QActionGroup QApplication QBitmap QBoxLayout QBrush QBrushData QButtonGroup QCDEStyle QCalendarWidget QCheckBox QCleanlooksStyle QClipboard QClipboardEvent QCloseEvent QColor QColorDialog QColorGroup QColormap QComboBox QCommonStyle QCompleter QConicalGradient QContextMenuEvent QCursor QCursorShape QDataWidgetMapper QDateEdit QDateTimeEdit QDesktopServices QDesktopWidget QDial QDialog QDialogButtonBox QDirModel QDockWidget QDoubleSpinBox QDoubleValidator QDrag QDragEnterEvent QDragLeaveEvent QDragMoveEvent QDragResponseEvent QDropEvent QErrorMessage QFileDialog QFileIconProvider QFileOpenEvent QFocusEvent QFocusFrame QFont QFontComboBox QFontDatabase QFontDialog QFontInfo QFontMetrics QFontMetricsF QFrame QGradient QGradientStop QGradientStops QGraphicsEllipseItem QGraphicsItem QGraphicsItemAnimation QGraphicsItemGroup QGraphicsLineItem QGraphicsPathItem QGraphicsPixmapItem QGraphicsPolygonItem QGraphicsRectItem QGraphicsScene QGraphicsSceneContextMenuEvent QGraphicsSceneDragDropEvent QGraphicsSceneEvent QGraphicsSceneHelpEvent QGraphicsSceneHoverEvent QGraphicsSceneMouseEvent QGraphicsSceneWheelEvent QGraphicsSimpleTextItem QGraphicsTextItem QGraphicsView QGridLayout QGroupBox QHBoxLayout QHeaderView QHelpEvent QHideEvent QHoverEvent QIcon QIconDragEvent QIconEngine QIconEngineFactoryInterface QIconEnginePlugin QIconSet QImage QImageIOHandler QImageIOHandlerFactoryInterface QImageIOPlugin QImageReader QImageTextKeyLang QImageWriter QInputContext QInputContextFactory QInputContextFactoryInterface QInputContextPlugin QInputDialog QInputEvent QInputMethodEvent QIntValidator QItemDelegate QItemEditorCreator QItemEditorCreatorBase QItemEditorFactory QItemSelection QItemSelectionModel QItemSelectionRange QKeyEvent QKeySequence QLCDNumber QLabel QLayout QLayoutItem QLayoutIterator QLineEdit QLinearGradient QListView QListWidget QListWidgetItem QMacMime QMacPasteBoardMime QMainWindow QMatrix QMenu QMenuBar QMenuItem QMenubarUpdatedEvent QMessageBox QMessageBoxEx QMimeSource QMotifStyle QMouseEvent QMoveEvent QMovie QPageSetupDialog QPaintDevice QPaintEngine QPaintEngineState QPaintEvent QPainter QPainterPath QPainterPathPrivate QPainterPathStroker QPalette QPen QPicture QPictureFormatInterface QPictureFormatPlugin QPictureIO QPixmap QPixmapCache QPlastiqueStyle QPolygon QPolygonF QPrintDialog QPrintEngine QPrinter QProgressBar QProgressDialog QProxyModel QPushButton QRadialGradient QRadioButton QRegExpValidator QRegion QResizeEvent QRgb QRubberBand QScrollArea QScrollBar QSessionManager QShortcut QShortcutEvent QShowEvent QSizeGrip QSizePolicy QSlider QSortFilterProxyModel QSound QSpacerItem QSpinBox QSplashScreen QSplitter QSplitterHandle QStackedLayout QStackedWidget QStandardItem QStandardItemEditorCreator QStandardItemModel QStatusBar QStatusTipEvent QStringListModel QStyle QStyleFactory QStyleFactoryInterface QStyleHintReturn QStyleHintReturnMask QStyleOption QStyleOptionButton QStyleOptionComboBox QStyleOptionComplex QStyleOptionDockWidget QStyleOptionFocusRect QStyleOptionFrame QStyleOptionFrameV2 QStyleOptionGraphicsItem QStyleOptionGroupBox QStyleOptionHeader QStyleOptionMenuItem QStyleOptionProgressBar QStyleOptionProgressBarV2 QStyleOptionQ3DockWindow QStyleOptionQ3ListView QStyleOptionQ3ListViewItem QStyleOptionRubberBand QStyleOptionSizeGrip QStyleOptionSlider QStyleOptionSpinBox QStyleOptionTab QStyleOptionTabBarBase QStyleOptionTabV2 QStyleOptionTabWidgetFrame QStyleOptionTitleBar QStyleOptionToolBar QStyleOptionToolBox QStyleOptionToolButton QStyleOptionViewItem QStylePainter QStylePlugin QSyntaxHighlighter QSystemTrayIcon QTabBar QTabWidget QTableView QTableWidget QTableWidgetItem QTableWidgetSelectionRange QTabletEvent QTextBlock QTextBlockFormat QTextBlockGroup QTextBlockUserData QTextBrowser QTextCharFormat QTextCursor QTextDocument QTextDocumentFragment QTextEdit QTextFormat QTextFragment QTextFrame QTextFrameFormat QTextFrameLayoutData QTextImageFormat QTextInlineObject QTextItem QTextLayout QTextLength QTextLine QTextList QTextListFormat QTextObject QTextObjectInterface QTextOption QTextTable QTextTableCell QTextTableFormat QTimeEdit QToolBar QToolBarChangeEvent QToolBox QToolButton QToolTip QTreeView QTreeWidget QTreeWidgetItem QTreeWidgetItemIterator QUndoCommand QUndoGroup QUndoStack QUndoView QUpdateLaterEvent QVBoxLayout QValidator QWMatrix QWhatsThis QWhatsThisClickedEvent QWheelEvent QWidget QWidgetAction QWidgetData QWidgetItem QWidgetList QWidgetMapper QWindowStateChangeEvent QWindowsMime QWindowsStyle QWindowsXPStyle QWorkspace QAbstractSocket QFtp QHostAddress QHostInfo QHttp QHttpHeader QHttpRequestHeader QHttpResponseHeader QIPv6Address QNetworkAddressEntry QNetworkInterface QNetworkProxy QTcpServer QTcpSocket QUdpSocket QUrlInfo Q_IPV6ADDR QGLColormap QGLContext QGLFormat QGLFramebufferObject QGLPixelBuffer QGLWidget QIBaseDriver QIBaseResult QMYSQLDriver QMYSQLResult QODBCDriver QODBCResult QPSQLDriver QPSQLResult QSQLite2Driver QSQLite2Result QSQLiteDriver QSQLiteResult QSqlDatabase QSqlDriver QSqlDriverCreator QSqlDriverCreatorBase QSqlDriverFactoryInterface QSqlDriverPlugin QSqlError QSqlField QSqlIndex QSqlQuery QSqlQueryModel QSqlRecord QSqlRelation QSqlRelationalDelegate QSqlRelationalTableModel QSqlResult QSqlTableModel QSvgRenderer QSvgWidget QEventSizeOfChecker QSignalSpy QSpontaneKeyEvent QTestAccessibility QTestAccessibilityEvent QTestData QTestDelayEvent QTestEvent QTestEventList QTestEventLoop QTestKeyClicksEvent QTestKeyEvent QTestMouseEvent QUiLoader QDomAttr QDomCDATASection QDomCharacterData QDomComment QDomDocument QDomDocumentFragment QDomDocumentType QDomElement QDomEntity QDomEntityReference QDomImplementation QDomNamedNodeMap QDomNode QDomNodeList QDomNotation QDomProcessingInstruction QDomText QXmlAttributes QXmlContentHandler QXmlDTDHandler QXmlDeclHandler QXmlDefaultHandler QXmlEntityResolver QXmlErrorHandler QXmlInputSource QXmlLexicalHandler QXmlLocator QXmlNamespaceSupport QXmlParseException QXmlReader QXmlSimpleReader二、智能補全1、安裝omnicppcomplete,從http://www.vim.org/scripts/script.php?script_id=1520上下載omnicppcomplete,直接解壓到vim的安裝目錄下(window下為vimfiles)2、安裝ctags,http://ctags.sourceforge.net/,並將其加入環境變數中,到qt的include目錄和src目錄下分別執行
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q
隨後在兩目錄下分別產生了tags的檔案。編輯_vimrc,加入
set nocp
filetype plugin indent on
set tags+=QTDIR/include/tags
set tags+=DQTDIR/src/tags3、設定tab自動補全,http://www.vim.org/scripts/script.php?script_id=1643,將supertab.vim拷貝到plugin目錄下,並在_vimrc中加入
set completeopt=longest,menu
let g:SuperTabRetainCompletionType = 2
let g:SuperTabDefaultCompletionType = "<C-X><C-O>"
關於補全的詳細內容,參見:http://easwy.com/blog/archives/advanced-vim-skills-omin-complete/
開啟文法高亮支援:
syntax enable
三、windows下使用vim來編輯並編譯QT建立一個文字檔,命名為qt_vim.bat,找到qt目錄下的qtenv.bat,做相應修改,以下是本人的內容,供參考
@echo off<br />rem<br />rem This file is generated<br />rem<br />echo Setting up a MinGW/Qt only environment...<br />echo -- QTDIR set to D:/Qt/4.6.0/qt<br />echo -- PATH set to D:/Qt/4.6.0/qt/bin<br />echo -- Adding D:/Qt/4.6.0/bin to PATH<br />echo -- Adding %SystemRoot%/System32 to PATH<br />echo -- QMAKESPEC set to win32-g++<br />set QTDIR=D:/Qt/4.6.0/qt<br />set PATH=D:/Qt/4.6.0/qt/bin<br />set PATH=%PATH%;D:/Qt/4.6.0/bin;D:/Qt/4.6.0/mingw/bin;D:/Program Files/Vim/vim72 //記得加上vim的路徑<br />set PATH=%PATH%;%SystemRoot%/System32<br />set QMAKESPEC=win32-g++<br />cd "F:/code/qt" //進入工作目錄<br />start "" gvim -O2 "F:/code/qt" //設定qt工作目錄<br />exit //退出cmd,保留gvim視窗 最後再在工程目錄下運行 ctags -R --c++-kinds=+p --fields=+iaS --extra=+q開啟一個cpp檔案做下測試吧