正在浏览 vim 里的文章

默认编译安装vim7.2后打开含有中文字符的文件会显示乱码,google了一圈,大多都是说在配置文件中添加下面的几行就可以解决问题:
set encoding=utf-8
set fileencoding=utf-8
但我设置了之后仍然没有解决问题,而且系统中有一个7.0版本的他们使用的是同一个配置文件,7.0版本的就没有问题,7.2版本死活认不了中文,因此怀疑是配置编译选项时肯定有哪些是选项时漏掉了,于是查看configure --help:
...
--enable-workshop       Include Sun Visual Workshop support.
--disable-netbeans      Disable NetBeans integration support.
--enable-sniff          Include Sniff interface.
--enable-multibyte      Include multibyte editing support.
--enable-hangulinput    Include Hangul input support.
--enable-xim            Include XIM input support.
--enable-fontset        Include X fontset output support.
...

选项有很多,只有一项引起了我的注意,看来就是他了,启用多字节编辑支持!重新配置编译选项
$./configure --enable-multibyte
$ make && sudo make install

查看安装后的版本信息
$ vim --version
VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Jun  3 2010 15:09:59)
Normal version without GUI.  Features included (+) or not (-):
... -mouse_sysmouse +mouse_xterm +multi_byte
+multi_lang -mzscheme -netbeans_intg -osfiletype +path_extr...
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
user exrc file: "$HOME/.exrc"
fall-back for $VIM: "/usr/local/share/vim"
可以清楚的看到,已经支持多字节。尝试打开含有中文的文件,一切正常。

另外介绍两个vim的命令:

1、设置光标行

:set cursorline

这条命令会在vim的光标所在行上标记为一条横线,如下

还可以修饰一下条横线:

:highlight CursorLine guibg=lightblue ctermbg=lightgray]

2、设置光标列

:set cursorcolumn


这样一来就不怕看错行了。呵呵

说明
1、这些命令都可以写在vim的配置文件中~/.vimrc 或/etc/vimrc(CentOS) /etc/vim/vimrc(Ubuntu)
2、只有在gnome或gvim环境下set cursorcolumn命令才会生效,终端模式无效。

分享一份Vim7.2用户手册中文版 点击下载

原创文章,转载请注明: 转自 http://salogs.com

Vim 插件 NERD tree 允许你在 Vim 编辑器中以树状方式浏览系统中的文件和目录,支持快捷键与鼠标操作,使用起来十分方便。NERD tree 能够以不同颜色高亮显示节点类型,并包含书签、过滤等实用功能。

image

要安装 NERD tree 插件,你只需将下载的 zip 包解压到 ~/.vim 目录即可。

你可以从 Vim 官方网站下载 NERD tree 插件

附加Readme文档:ReadMe

vimrc sample file

抢沙发
==================================================
" Stuff I have decided I don't like
==================================================
"set ignorecase -- turns out, I like case sensitivity
"set list " turns out, I don't like listchars -- show chars on end of line, whitespace, etc
"autocmd GUIEnter * :simalt ~x -- having it auto maximize the screen is annoying
"autocmd BufEnter * :lcd %:p:h -- switch to current dir (breaks some scripts)
==================================================
" General
==================================================
set nocompatible " get out of horrible vi-compatible mode
filetype on " detect the type of file
set history=1000 " How many lines of history to remember
set cf " enable error files and error jumping
set clipboard+=unnamed " turns out I do like is sharing windows clipboard
set ffs=dos,unix,mac " support all three, in this order
filetype plugin on " load filetype plugins
set viminfo+=! " make sure it can save viminfo
set isk+=_,$,@,%,#,- " none of these should be word dividers, so make them not be
==================================================
" Theme/Colors
==================================================
set background=dark " we are using a dark background
syntax on " syntax highlighting on
colorscheme metacosm " my theme
==================================================
" Files/Backups
==================================================
set backup " make backup file
set backupdir=$VIM\vimfiles\backup " where to put backup file
set directory=$VIM\vimfiles\temp " directory is the directory for temp file
set makeef=error.err " When using make, where should it dump the file
==================================================
" Vim UI
==================================================
set lsp=0 " space it out a little more (easier to read)
set wildmenu " turn on wild menu
set ruler " Always show current positions along the bottom
set cmdheight=2 " the command bar is 2 high
set number " turn on line numbers
set lz " do not redraw while running macros (much faster) (LazyRedraw)
set hid " you can change buffer without saving
set backspace=2 " make backspace work normal
set whichwrap+=<,>,h,l  " backspace and cursor keys wrap to
set mouse=a " use mouse everywhere
set shortmess=atI " shortens messages to avoid '
press a key' prompt
set report=0 " tell us when anything is changed via :...
set noerrorbells " don'
t make noise
" make the splitters between windows be blank
set fillchars=vert:\ ,stl:\ ,stlnc:\
==================================================
" Visual Cues
==================================================
set showmatch " show matching brackets
set mat=5 "
how many tenths of a second to blink matching brackets for
set nohlsearch " do not highlight searched for phrases
set incsearch "
BUT do highlight as you type you search phrase
set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$ " what to show when I hit :set list
set lines=80 "
80 lines tall
set columns=160 " 160 cols wide
set so=10 "
Keep 10 lines (top/bottom) for scope
set novisualbell " don't blink
set noerrorbells "
no noises
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
set laststatus=2 " always show the status line
==================================================
"
Text Formatting/Layout
==================================================
set fo=tcrqn " See Help (complex)
set ai "
autoindent
set si " smartindent
set cindent "
do c-style indenting
set tabstop=8 " tab spacing (settings below are just to unify it)
set softtabstop=8 "
unify
set shiftwidth=8 " unify
set noexpandtab "
real tabs please!
set nowrap " do not wrap lines
set smarttab "
use tabs at the start of a line, spaces elsewhere
==================================================
" Folding
"    Enable folding, but by default make it act like folding is off, because folding is annoying in anything but a few rare cases
==================================================
set foldenable " Turn on folding
set foldmethod=indent "
Make folding indent sensitive
set foldlevel=100 " Don't autofold anything (but I can still fold manually)
set foldopen-=search "
don't open folds when you search into them
set foldopen-=undo " don'
t open folds when you undo stuff
==================================================
" File Explorer
==================================================
let g:explVertical=1 " should I split verticially
let g:explWinSize=35 "
width of 35 pixels

==================================================
" Win Manager
==================================================
let g:winManagerWidth=35 " How wide should it be( pixels)
let g:winManagerWindowLayout = 'FileExplorer,TagsExplorer|BufExplorer' "
What windows should it

==================================================
" CTags
==================================================
let Tlist_Ctags_Cmd = $VIM.'\ctags.exe' " Location of ctags
let Tlist_Sort_Type = "
name" " order by
let Tlist_Use_Right_Window = 1 " split to the right side of the screen
let Tlist_Compart_Format = 1 "
show small meny
let Tlist_Exist_OnlyWindow = 1 " if you are the last, kill yourself
let Tlist_File_Fold_Auto_Close = 0 "
Do not close tags for other files
let Tlist_Enable_Fold_Column = 0 " Do not show folding tree

==================================================
"
Minibuf
==================================================
let g:miniBufExplTabWrap = 1 " make tabs show complete (no broken on two lines)
let g:miniBufExplModSelTarget = 1

==================================================
"
Matchit
==================================================
let b:match_ignorecase = 1

==================================================
" Perl
==================================================
let perl_extended_vars=1 " highlight advanced perl vars inside strings

==================================================
"
Custom Functions
==================================================
" Select range, then hit :SuperRetab($width) - by p0g and FallingCow
function! SuperRetab(width) range
silent! exe a:firstline . ',' . a:lastline . 's/\v%(^ *)@<= {'. a:width .'}/\t/g'
endfunction

==================================================
" Mappings
==================================================
map  :MBEbn " right arrow (normal mode) switches buffers  (excluding minibuf)
map  :MBEbp "
left arrow (normal mode) switches buffers (excluding minibuf)
map  :Sex " up arrow (normal mode) brings up a file list
map  :Tlist "
down arrow  (normal mode) brings up the tag list
map  i r " alt-i (normal mode) inserts a single char, and then switches back to normal
map  ggVG:call SuperRetab()
map  ggVGg? "
encypt the file (toggle)

==================================================
" Autocommands
==================================================
autocmd BufEnter * :syntax sync fromstart " ensure every file does syntax highlighting (full)
au BufNewFile,BufRead *.asp :set ft=aspjscript "
all my .asp files ARE jscript
au BufNewFile,BufRead *.tpl :set ft=html " all my .tpl files ARE html
au BufNewFile,BufRead *.hta :set ft=html "
all my .tpl files ARE html

==================================================
" Useful abbrevs
==================================================
iab xasp <
iab xdate =strftime("%d/%m/%y %H:%M:%S")

资源来源于网络,本站整理汇总 。

运行参数:

-d  比较两个文件的差异

-O/-o 打开多个文件时水平或垂直分割窗口显示

一般模式:移动光标的方法
h 或向左方向键() 光标向左移动一个字符
j 或向下方向键() 光标向下移动一个字符
k 或向上方向键() 光标向上移动一个字符
l 或向右方向键() 光标向右移动一个字符
如果想要进行多次移动的话,例如向下移动 30 行,可以使用 "30j" "30" 的组合按键,
亦即加上想要进行的次数(数字)后,按下动作即可!
[Ctrl] + [f] 屏幕『向下』移动一页,相当于 [Page Down]按键 (常用)
[Ctrl] + [b] 屏幕『向上』移动一页,相当于 [Page Up] 按键 (常用)
[Ctrl] + [d] 屏幕『向下』移动半页
[Ctrl] + [u] 屏幕『向上』移动半页
+ 光标移动到非空格符的下一列
- 光标移动到非空格符的上一列
n<space> 那个 n 表示『数字』,例如 20 。按下数字后再按空格键,光标会向右移动这一行的 n 个字符。例如 20<space> 则光标会向后面移动 20 个字符距离。
0/^ 这是数字『 0 』:移动到这一行的最前面字符处
(
常用)
$ 移动到这一行的最后面字符处(常用)
H 光标移动到这个屏幕的最上方那一行
M 光标移动到这个屏幕的中央那一行
L 光标移动到这个屏幕的最下方那一行
G 移动到这个档案的最后一行(常用)
nG n 为数字。移动到这个档案的第 n 行。例如 20G 则会移动到这个档案的第 20 (可配合 :set nu)
gg 移动到这个档案的第一行,相当于 1G 啊! (常用)
[[

向前跳到顶格的第一个"{"

[]

向前跳到顶格的第一个"}"

][

向后跳到顶格的第一个"{"

]]

向后跳到顶格的第一个"}"

[{

跳到本代码块(由{}界定)的开头

[}

跳到本代码块的结尾

% 跳到匹配的括号处("{ }""[]""()")
n<Enter> n 为数字。光标向下移动 n (常用)
fx

移动光标到当前行的下一个x处。很明显,x可以是任意一个字母,而且你可以使用;来重复你的上一个f命令。

tx

和上面的命令类似,但是是移动到x的左边一个位置。(这真的很有用)

Fx

和fx类似,不过是往回找。

一般模式:
搜索与替换
/word 向光标之下寻找一个字符串名称为 word 的字符串。例如要在档案内搜寻 vbird 这个字符串,就输入 /vbird 即可!
(
常用)
?word 向光标之上寻找一个字符串名称为 word 的字符串。
n 这个 n 是英文按键。代表『重复前一个搜寻的动作』的意思。举例来说,
如果刚刚我们执行 /vbird 去向下搜寻 vbird 这个字符串,则按下 n 后,会向下继续搜寻下一个名称为 vbird 的字符串。如果是执行 ?vbird 的话,那么按下 n 则会向上继续搜寻名称为 vbird 的字符串!
N 这个 N 是英文按键。与 n 刚好相反,为『反向』进行前一个搜寻动作。
例如 /vbird 后,按下 N 则表示『向上』搜寻 vbird
:n1,n2s/word1/word2/g n1 n2 为数字。在第 n1 n2 行之间寻找 word1 这个字符串,并将该字符串取代为 word2 !举例来说,在 100 200 行之间搜寻 vbird 并取代为 VBIRD 则:
:100,200s/vbird/VBIRD/g』。(常用)
:1,$s/word1/word2/g 从第一行到最后一行寻找 word1 字符串,并将该字符串取代为 word2 (常用)
:g/p1/s//p2/g 将文件中所有p1均用p2替换
:1,$s/word1/word2/gc 从第一行到最后一行寻找 word1 字符串,并将该字符串取代为 word2 !且在取代前显示提示字符给使用者确认 (confirm) 是否需要取代!(常用)
:s/p1/p2/g 将当前行中所有p1均用p2替代
一般模式:删除、复制与粘贴
x, X 在一行字当中,x 为向后删除一个字符 (相当于 [del] 按键) X 为向前删除一个字符(相当于 [backspace] 亦即是退格键) (常用)
nx n 为数字,连续向后删除 n 个字符。举例来说,我要连续删除 10 个字符,
10x』。
dd 删除游标所在的那一整列(常用)
ndd n 为数字。删除光标所在的向下 n 列,例如 20dd 则是删除 20 (常用)
d1G 删除光标所在到第一行的所有数据
dG 删除光标所在到最后一行的所有数据
d$ 删除游标所在处,到该行的最后一个字符
d0 那个是数字的 0 ,删除游标所在处,到该行的最前面一个字符
yy 复制游标所在的那一行(常用)
nyy n 为数字。复制光标所在的向下 n 列,例如 20yy 则是复制 20 (常用)
y1G 复制光标所在列到第一列的所有数据
yG 复制光标所在列到最后一列的所有数据
y0 复制光标所在的那个字符到该行行首的所有数据
y$ 复制光标所在的那个字符到该行行尾的所有数据
p, P p 为将已复制的数据在光标下一行贴上,P 则为贴在游标上一行!
举例来说,我目前光标在第 20 行,且已经复制了 10 行数据。则按下 p 后,
10 行数据会贴在原本的 20 行之后,亦即由 21 行开始贴。但如果是按下 P 呢?
那么原本的第 20 行会被推到变成 30 行。 (常用)
J 将光标所在列与下一列的数据结合成同一列
c 重复删除多个数据,例如向下删除 10 行,[ 10cj ]
u 复原前一个动作。(常用)
[Ctrl]+r 重做上一个动作。(常用)
这个 u [Ctrl]+r 是很常用的指令!一个是复原,另一个则是重做一次~
利用这两个功能按键,您的编辑,嘿嘿!很快乐的啦!
. 不要怀疑!这就是小数点!意思是重复前一个动作的意思。
如果您想要重复删除、重复贴上等等动作,按下小数点『.』就好了! (常用)
进入编辑模式
i, I 插入:在目前的光标所在处插入输入之文字,已存在的文字会向后退;
其中, i 为『从目前光标所在处插入』, I 为『在目前所在行的第一个非空格符处开始插入』。 (常用)
a, A a 为『从目前光标所在的下一个字符处开始插入』, A 为『从光标所在行的最后一个字符处开始插入』。(常用)
o, O 这是英文字母 o 的大小写。o 为『在目前光标所在的下一行处插入新的一行』; O 为在目前光标所在处的上一行插入新的一行!(常用)
r, R 取代:r 会取代光标所在的那一个字符;R会一直取代光标所在的文字,直到按下 ESC 为止;(常用)
上面这些按键中,在 vi 画面的左下角处会出现『--INSERT--』或『--REPLACE--』的字样。
由名称就知道该动作了吧!!特别注意的是,我们上面也提过了,你想要在档案里面输入字符时,
一定要在左下角处看到 INSERT/REPLACE 才能输入喔!
Esc 退出编辑模式,回到一般模式中(常用)
指令列命令模式
:w 将编辑的数据写入硬盘档案中(常用)
:w! 若档案属性为『只读』时,强制写入该档案。不过,到底能不能写入,
还是跟您对该档案的档案权限有关啊!
:q 离开 vi (常用)
:q! 若曾修改过档案,又不想储存,使用 ! 为强制离开不储存档案。
注意一下啊,那个惊叹号 (!) vi 当中,常常具有『强制』的意思~
:wq 储存后离开,若为 :wq! 则为强制储存后离开 (常用)
:e! 将档案还原到最原始的状态!
ZZ 若档案没有更动,则不储存离开,若档案已经经过更动,则储存后离开!
:w [filename] 将编辑的数据储存成另一个档案(类似另存新档)
:r [filename] 在编辑的数据中,读入另一个档案的数据。亦即将
filename
这个档案内容加到游标所在行后面
:r!command 将命令command的输出结果放到当前行
:n1,n2 w [filename] n1 n2 的内容储存成 filename 这个档案。
:n1,n2 m n3 n1行到n2行之间的内容移至到第n3行下
:n1,n2 co n3 n1行到n2行之间的内容拷贝到第n3行下
:x 保存当前文件并退出
n1,n2 d n1行到n2行之间的内容删除
:! command 暂时离开 vi 到指令列模式下执行 command 的显示结果!例如
:! ls /home』即可在 vi 当中察看 /home 底下以 ls 输出的档案信息!
:set nu 显示行号,设定之后,会在每一行的前缀显示该行的行号
:set nonu set nu 相反,为取消行号!
:noh 取消高亮
窗格划分(命令模式下)
:split/vsplit 分隔一个窗口
:new/vnew 创建一个新的窗口
:sf {filename} 在新窗口中打开filename
:close 关闭当前窗口
:only 关闭除当前窗口外所有窗口
:ctrl-w h 到左面的窗口
:ctrl-w j 到下面的窗口
:ctrl-w k 到上面的窗口
:ctrl-w l 到右面的窗口
:ctrl-w t 到顶部的窗口
:ctrl-w b 到底部的窗口
宏操作
q[a-z]

开始记录操作,记录到寄存器[a-z]中

q

停止记录操作

@[a-z]

执行寄存器中的操作

@@

执行最近寄存器中记录的操作

例子: 一个缓冲区有两行:
sys/types.h
stdio.h
-->要改为:
#include <sys/types.h>
#include <stdio.h>
操作如下:
qa #开始记录
^ #移动行首
i #进入insert模式
#include < #输入内容
$ #移动行尾
i #进入insert模式
> #输入内容
q #停止记录
移动另一行:
@a即可执行相同的操作
Visual Mode操作(块操作与选取操作)
ctrl+v

进入基于块的可视模式 如:

v

进入基于字符的可视模式 如: 相当于windows下按住shift后移动光标选取字符。

V

进入基于行的可视模式 如:

d

剪贴选择的内容到剪贴板。

y

拷贝选择的内容到剪贴板。

c

剪贴选择的内容到剪贴板并且进入插入模式。

I{string}<ESC>

选定块后按大写的I,输入字符串,再按ESC,可以在块内每一行插入相同的内容

Shell
:ctrl+z/suspend

在shell下是挂起vim; gui下是最小化窗口

:!{command}

执行shell命令

:shell

开一个新的shell

补充
shift+3 在文件中查找当前光标所在的字符,并把这些字符高亮显示
n== 在命令状态下对当前行用== (连按=两次), 或对多行用n==(n是自然数)表示自动缩进从当前行起的下面n行
gg=G 对整篇代码进行排版
n<< 使n行都向左移动一个宽度
n>> 使n行都向右移动一个宽度,例如3>>就将接下来的三行每行都向右移动一个移动宽度

vim的用户手册:
http://vimdoc.sourceforge.net/htmldoc/

vi-vim 快捷键 键位图
http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html

本文转自 http://www.machinema.cn/677
这里说说怎么让nginx的配置文件高亮

mkdir -p /root/.vim/syntax
cd /root/.vim/syntax
vi nginx.vim

加入下面这一段

?Download nginx.vim
" Vim syntax file
" Language:     Nginx configuration (nginx.conf)
" Maintainer:   Evan Miller
" Last Change:  2007 May 02
" Notes: This is a bit patchy.
if exists("b:current_syntax")
finish
end
setlocal iskeyword+=.
setlocal iskeyword+=/
setlocal iskeyword+=:
" basics
syn match ngxStringVariable "\$\w\w*" contained
syn region ngxString start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=ngxStringVariable oneline
syn region ngxString start=+'+ end=+'+ skip=+\\\\\|\\'+ contains=ngxStringVariable oneline
" Main
syn keyword ngxDirective daemon debug_points error_log lock_file master_process pid ssl_engine timer_resolution user group worker_cpu_affinity worker_priority worker_processes worker_rlimit_core worker_rlimit_nofile worker_rlimit_sigpending working_directory
syn keyword ngxDirectiveImportant include
syn keyword ngxBlockDirective http events contained
syn keyword ngxBlockDirective server contained
"Events
syn keyword ngxDirective accept_mutex accept_mutex_delay debug_connection devpoll_changes devpoll_events epoll_events kqueue_changes kqueue_events multi_accept rtsig_signo rtsig_overflow_events rtsig_overflow_test rtsig_overflow_threshold use worker_connections
" HTTP core
syn keyword ngxDirective alias client_body_in_file_only client_body_buffer_size client_body_temp_path client_body_timeout client_header_buffer_size client_header_timeout client_max_body_size default_type keepalive_timeout large_client_header_buffers limit_rate msie_padding msie_refresh optimize_server_names port_in_redirect recursive_error_pages satisfy_any send_timeout sendfile server_names_hash_max_size server_names_hash_bucket_size tcp_nodelay tcp_nopush internal
syn keyword ngxDirective output_buffers postpone_output send_lowat connections
syn keyword ngxDirectiveImportant root server server_name listen
syn keyword ngxDirectiveError error_page
syn keyword ngxBlockDirective location limit_except types contained
" Access
syn keyword ngxDirective allow deny
" Auth
syn keyword ngxDirective auth_basic auth_basic_user_file
" Auto-index
syn keyword ngxDirective autoindex
syn keyword ngxDirective autoindex_exact_size
syn keyword ngxDirective autoindex_localtime
" DAV
syn keyword ngxDirective dav_access dav_methods create_full_put_path
" FastCGI
syn keyword ngxDirective fastcgi_index fastcgi_hide_header fastcgi_intercept_errors fastcgi_param fastcgi_pass_header fastcgi_redirect_errors
syn keyword ngxDirectiveImportant fastcgi_pass
" gzip
syn keyword ngxDirective gzip gzip_buffers gzip_comp_level gzip_min_length gzip_http_version gzip_proxied gzip_types
" header
syn keyword ngxDirective add_header
syn keyword ngxDirective expires
" auto-index
syn keyword ngxDirective index
" log
syn keyword ngxDirective access_log log_format
" proxy
syn keyword ngxDirective proxy_buffer_size proxy_buffering proxy_buffers proxy_connect_timeout proxy_hide_header proxy_intercept_errors proxy_method proxy_next_upstream proxy_pass_header proxy_read_timeout proxy_redirect_errors proxy_send_timeout proxy_set_header proxy_temp_path proxy_temp_file_write_size proxy_busy_buffers_size proxy_send_lowat
syn keyword ngxDirectiveImportant proxy_pass proxy_redirect
" rewrite
syn keyword ngxDirectiveControl break return set uninitialized_variable_warn rewrite
syn keyword ngxDirective uninitialized_variable_warn
syn keyword ngxBlockDirective if contained
" SSL
syn keyword ngxDirective ssl ssl_certificate ssl_certificate_key ssl_client_certificate ssl_ciphers ssl_prefer_server_ciphers ssl_protocols ssl_verify_client ssl_verify_depth ssl_session_cache ssl_session_timeout
" Upstream
syn keyword ngxDirective ip_hash server
syn keyword ngxBlockDirective upstream contained
" Addition
syn keyword ngxDirectiveImportant add_before_body add_after_body
" Charset
syn keyword ngxDirective charset charset_map override_charset source_charset
" empty gif
syn keyword ngxDirective empty_gif
" geo
syn keyword ngxBlockDirective geo
" map
syn keyword ngxBlockDirective map
syn keyword ngxDirective map_hash_max_size map_hash_bucket_size
" realip
syn keyword ngxDirective set_real_ip_from real_ip_header
" referer
syn keyword ngxDirective valid_referers
" ssi
syn keyword ngxDirective ssi
" user id
syn keyword ngxDirective userid userid_domain userid_expires userid_name userid_p3p userid_path userid_service
" sub filter
syn keyword ngxDirective sub_filter sub_filter_once sub_filter_types
" perl
syn keyword ngxDirective perl_modules perl_require perl_set
" limit zone
syn keyword ngxDirective limit_zone limit_conn
" memcache
syn keyword ngxDirective memcached_connect_timeout memcached_send_timeout memcached_read_timeout memcached_buffer_size memcached_next_upstream
syn keyword ngxDirectiveImportant memcached_pass
" stub
syn keyword ngxDirective stub_status
" flv
syn keyword ngxDirective flv
" browser
syn keyword ngxDirective ancient_browser ancient_browser_value modern_browser modern_browser_value
syn region ngxStartBlock start=+^+ end=+{+ contains=ngxBlockDirective,ngxContextVariable oneline
syn match ngxContextVariable "\$\w\w*" contained
syn match ngxComment " *#.*$"
syn match ngxVariable "\$\w\w*"
hi link ngxBlockDirective Statement
hi link ngxStartBlock Normal
hi link ngxStringVariable Special
hi link ngxDirectiveControl Special
hi link ngxComment Comment
hi link ngxString String
hi link ngxDirective Identifier
hi link ngxDirectiveImportant Type
hi link ngxVariable Identifier
hi link ngxContextVariable Identifier
hi link ngxDirectiveError Constant
let b:current_syntax = "nginx"

然后打开/root/.vim/filetype.vim
vi /root/.vim/filetype.vim
加入下面这一段
au BufRead,BufNewFile /usr/local/nginx/conf/* set ft=nginx