分享

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

 岁月如风99 2015-10-22

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/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.

Mac下vi/vim开启语法高亮着色丨Enable vi/vim syntax highlighting on Mac - Bob.Z - 断尘居
 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多