打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Mac下vi/vim开启语法高亮&着色丨Enable vi/vim syntax highlighting on Mac

Mac下vi/vim开启语法高亮&着色丨Enable vi/vim syntax highlighting on Mac  

 # 软件环境丨Software Environments

OS:Mac OS X10.9.4

 # 问题描述丨Problem Description

Mac OS并不像大多数Linux发行版vi/vim默认自带语法着色高亮显示(通常Linux可通过编辑/etc/vimrc进行全局设置或~/vimrc进行单用户设置),使用vi/vim编辑文件时很不方便,如何解决 ?

Mac OS isn't like other most Linux distributions syntax highlighting is enabled by default(generally, edit /etc/vimrc to set global configuration or edit ~/vimrc for personal), this makes quite uncomfortable for using, but how to solve this case?

 # 解决方案丨The Solution

Step 1,编辑文件/usr/share/vim/vimrc 丨  Edit file /usr/share/vim/vimrc
BobZhao@mac:~ > sudo vim /usr/share/vim/vimrcPassword:" 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" Don't write backup file if vim is being called by "chpass"au BufWrite /private/etc/pw.* set nowritebackup

Step 2,  在set backspace=2下插入如下配置 | configure the following chars under the line of 'set backspace=2'
set ai                  " auto indentingset history=100         " keep 100 lines of historyset ruler               " show the cursor positionsyntax on               " syntax highlightingset hlsearch            " highlight the last searched termfiletype plugin on      " use the file type plugins" When editing a file, always jump to the last cursor positionautocmd BufReadPost *\ if ! exists("g:leave_my_cursor_position_alone") |\ if line("'\"") > 0 && line ("'\"") <= line("$") |\ exe "normal g'\"" |\ endif |\ endif

Step 3,再次打开该文件(实际上任意文件都可以)会发现已自动着色,见下图。 | reopen the file(any file in fact) and you'll find the syntax highlighted automatically,  see the following image.

 
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Linux 下 Vi 配置文件 .vimrc 文件
Mac下vim编辑器最简单配置方法(开启语法高亮)
Linux Vi编辑器使用
解决fedora6下vim不能语法着色问题 - 一江春水向东流 - BlogJava
谁说 Vim 不好用?送你一个五彩斑斓的编辑器!
vim开发环境配置
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服