mac下vi高亮

 # 问题描述丨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/vimrc
Password:
" Configuration file for vim
set modelines=0         " CVE-2007-2438

" Normally we use vim-extensions. If you want true vi-compatibility
" remove change the following statements
set nocompatible        " Use Vim defaults instead of 100% vi compatibility
set 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 indenting
set history=100         " keep 100 lines of history
set ruler               " show the cursor position
syntax on               " syntax highlighting
set hlsearch            " highlight the last searched term
filetype plugin on      " use the file type plugins

" When editing a file, always jump to the last cursor position
autocmd 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.
屏幕快照 2016-04-29 下午12.44.29

版权声明:
作者:xiaoniba
链接:https://blog.xiaoniba.com/2016/04/29/mac%e4%b8%8bvi%e9%ab%98%e4%ba%ae/
来源:小泥吧的博客
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>