配置Mac的vim,使代码高亮

来源:互联网 发布:09和冷冷的故事 知乎 编辑:程序博客网 时间:2024/06/02 03:59

工作中需要使用vim写c++程序,默认的vim不能使代码高亮,本文参考网上的配置文件(没有找到原文链接)自己改了改

将~/.vimrc文件修改成如下即可:

" Configuration file for vimset modelines=0" CVE-2007-2438" Normally we use vim-extensions. If you want true vi-compatibility" remove change the following statementsset nocompatible" Use Vim defaults instead of 100% vi compatibilityset backspace=2" more powerful backspacing" Don't write backup file if vim is being called by "crontab -e"au BufWrite /private/tmp/crontab.* set nowritebackup nobackup" Don't write backup file if vim is being called by "chpass"au BufWrite /private/etc/pw.* set nowritebackup nobackupsyntax oncolorscheme desert"打开文件类型检测功能filetype on "不同文件类型采用不同缩进filetype indent on "允许使用插件filetype plugin onfiletype plugin indent on "关闭vi模式set nocp "与windows共享剪贴板set clipboard+=unnamed "取消VI兼容,VI键盘模式不易用set nocompatible "显示行号, 或set numberset nu "历史命令保存行数set history=100 "当文件被外部改变时自动读取set autoread"允许使用鼠标点击定位set mouse=a "允许区域选择set selection=exclusiveset selectmode=mouse,key "高亮光标所在行set cursorline "取消光标闪烁set novisualbell "总是显示状态行set laststatus=2 "状态栏显示当前执行的命令set showcmd "标尺功能,显示当前光标所在行列号set ruler "设置命令行高度为3set cmdheight=3 "粘贴时保持格式set paste "高亮显示匹配的括号set showmatch "在搜索的时候忽略大小写set ignorecase "高亮被搜索的句子set hlsearch "在搜索时,输入的词句的逐字符高亮(类似firefox的搜索)set incsearch "继承前一行的缩进方式,特别适用于多行注释set autoindent "为C程序提供自动缩进set smartindent "使用C样式的缩进set cindent "制表符为4set tabstop=4set expandtab"%retab! "统一缩进为4set softtabstop=4set shiftwidth=4 "允许使用退格键,或set backspace=2set backspace=eol,start,indentset whichwrap+=<,>,h,l "取消换行set nowrap"在被分割的窗口间显示空白,便于阅读set fillchars=vert:\ ,stl:\ ,stlnc:\ "光标移动到buffer的顶部和底部时保持3行距离, 或set so=3set scrolloff=3 "设定默认解码set fenc=utf-8set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936 "设定字体set guifont=Courier_New:h11:cANSIset guifontwide=新宋体:h11:cGB2312 "设定编码set enc=utf-8set fileencodings=ucs-bom,utf-8,chineseset langmenu=zh_CN.UTF-8language message zh_CN.UTF-8source $VIMRUNTIME/delmenu.vimsource $VIMRUNTIME/menu.vim "自动补全filetype plugin indent onset completeopt=longest,menu "自动补全命令时候使用菜单式匹配列表set wildmenuautocmd FileType ruby,eruby set omnifunc=rubycomplete#Completeautocmd FileType python set omnifunc=pythoncomplete#Completeautocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJSautocmd FileType html set omnifunc=htmlcomplete#CompleteTagsautocmd FileType css set omnifunc=csscomplete#CompleteCSSautocmd FileType xml set omnifunc=xmlcomplete#CompleteTagsautocmd FileType java set omnifunc=javacomplete#Complet
效果如下: