Mac下vi/vim开启语法高亮&着色丨Enable vi/vim syntax highlighting on Mac
# 软件环境丨Software Environments OS:Mac OS X10.9.4 # 问题描述丨Problem DescriptionMac 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?
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.
|