http://blog.csdn.net/wh_luosangnanka5/article/details/7779139
首先找到配置文件位置, 我的系统是Ubuntu 12.04, 安装的vim是vim 7.3, 如果你不知道你的配置文件在哪里的话,就随便使用vim打开一个文件vim test, 输入:version即可看到你的vimrc位置,然后使用命令
- cp /usr/share/vim/vimrc /home/root
- mv ~/vimrc ~/.vimrc
你的主目录下的.vimrc文件即是你的配置文件
如果你使用插件, 下载后插件放置位置即在~/.vim/plugin下(没有即可则新建), 帮助文档放在~/.vim/doc下(没有即可则新建)
我使用的插件有:
Ctags、Taglist、a.vim、c.vim、minibufexpl.vim、perdirvimrc.vim、php-doc.vim、php.vim、projtags.vim
配置文件如下,如果有补充欢迎邮件交流:jiangyeziwh@gmail.com:
- " 在处理未保存或只读文件的时候,弹出确认
- set confirm
- " 带有如下符号的单词不要被换行分割
- set iskeyword+=_,$,@,%,#,-
- " 不使用vi默认键盘布局
- set nocompatible
- "设置编码
- set encoding=utf-8
- set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
- set fileencodings=utf-8,ucs-bom,chinese
- "语言设置
- set langmenu=zh_CN.UTF-8
- " 显示行号
- set number
- " 智能对齐
- set smartindent
- " 括号匹配模式
- set showmatch
- " 显示状态行
- set ruler
- "设置配色方案
- colorscheme torte
- "可以在buffer的任何地方使用鼠标
- set mouse=a
- set selection=exclusive
- set selectmode=mouse,key
- set incsearch
- " tab键为4个空格
- set tabstop=4
- set shiftwidth=4
- set softtabstop=4
- " 自动对齐
- set autoindent
- if &term=="xterm"
- set t_Co=8
- set t_Sb=^[[4%dm
- set t_Sf=^[[3%dm
- endif
- " C语言格式对齐
- set cindent
- " 不要备份文件
- set nobackup
- " 与windows共享剪贴板
- set clipboard+=unnamed
- syntax on
- "打开文件类型自动检测功能
- filetype on
- "设置taglist
- "显示多个文件的tags
- let Tlist_Show_One_File=0
- "非当前文件,函数列表折叠隐藏
- let Tlist_File_Fold_Auto_Close=1
- "在taglist是最后一个窗口时退出vim
- let Tlist_Exit_OnlyWindow=1
- "单击时跳转
- let Tlist_Use_SingleClick=1
- "打开taglist时获得输入焦点
- let Tlist_GainFocus_On_ToggleOpen=1
- "不管taglist窗口是否打开,始终解析文件中的tag
- let Tlist_Process_File_Always=1
- nmap <F7> :TlistToggle <CR>
- " 配置cvim
- filetype plugin on
- " C的编译和运行
- map <F5> :call CompileRunGcc()<CR>
- func! CompileRunGcc()
- exec "w"
- exec "!gcc % -o %<"
- exec "! ./%<"
- endfunc
- " C++的编译和运行
- map <F6> :call CompileRunGpp()<CR>
- func! CompileRunGpp()
- exec "w"
- exec "!g++ % -o %<"
- exec "! ./%<"
- endfunc
- " =====================================================
- " PHP
- " =====================================================
- " The php doc plugin
- " source ~/.vim/php-doc.vim
- inoremap <C-P> <ESC>:call PhpDocSingle()<CR>i
- nnoremap <C-P> :call PhpDocSingle()<CR>
- vnoremap <C-P> :call PhpDocRange()<CR>
- " run file with PHP CLI (CTRL-M)
- :autocmd FileType php noremap <C-M> :w!<CR>:!/usr/bin/php %<CR>
- " PHP parser check (CTRL-L)
- :autocmd FileType php noremap <C-L> :!/usr/bin/php -l %<CR>
- " Do use the currently active spell checking for completion though!
- " (I love this feature :-)
- set complete+=kspell
- " disable tabs
- set expandtab
- set shiftwidth=4
- set softtabstop=4
- " highlt matches
- set hlsearch
- " Taken from http://peterodding.com/code/vim/profile/vimrc
- " Make Vim open and close folded text as needed because I can't be bothered to
- " do so myself and wouldn't use text folding at all if it wasn't automatic.
- set foldmethod=marker foldopen=all,insert foldclose=all
- " Enable enhanced command line completion.
- set wildmenu wildmode=list:full
- " Ignore these filenames during enhanced command line completion.
- set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
- set wildignore+=*.jpg,*.bmp,*.gif " binary images
- set wildignore+=*.luac " Lua byte code
- set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
- set wildignore+=*.pyc " Python byte code
- set wildignore+=*.spl " compiled spelling word lists
- set wildignore+=*.sw? " Vim swap files
- " Enable completion dictionaries for PHP buffers.
- autocmd FileType php set complete+=k~/.vim/dict/PHP.dict
- " PHP Autocomplete
- autocmd FileType php set omnifunc=phpcomplete#CompletePHP
- set ofu=syntaxcomplete#Complete
- " You might also find this useful
- " PHP Generated Code Highlights (HTML & SQL)
- let php_sql_query=1
- let php_htmlInStrings=1
- let g:php_folding=2
- set foldmethod=syntax
- " --------------------
- " Project
- " --------------------
- map <A-S-p> :Project<CR>
- map <A-S-o> :Project<CR>:redraw<CR>/
- nmap <silent> <F3> <Plug>ToggleProject
- "let g:proj_window_width = 30
- "let g:proj_window_increment = 150
- nnoremap <silent> <F8> :TlistToggle<CR>
- let Tlist_Exit_OnlyWindow = 1 " exit if taglist is last window open
- let Tlist_Show_One_File = 1 " Only show tags for current buffer
- let Tlist_Enable_Fold_Column = 0 " no fold column (only showing one file)
- let tlist_sql_settings = 'sql;P:package;t:table'
- let tlist_ant_settings = 'ant;p:Project;r:Property;t:Target'
- " auto change directory from: http://vim.wikia.com/wiki/Set_working_directory_to_the_current_file
- autocmd BufEnter * if expand("%:p:h") !~ '^/tmp' | lcd %:p:h | endif
- " when we reload, tell vim to restore the cursor to the saved position
- augroup JumpCursorOnEdit
- au!
- autocmd BufReadPost *
- \ if expand("<afile>:p:h") !=? $TEMP |
- \ if line("'\"") > 1 && line("'\"") <= line("$") |
- \ let JumpCursorOnEdit_foo = line("'\"") |
- \ let b:doopenfold = 1 |
- \ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
- \ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
- \ let b:doopenfold = 2 |
- \ endif |
- \ exe JumpCursorOnEdit_foo |
- \ endif |
- \ endif
- " Need to postpone using "zv" until after reading the modelines.
- autocmd BufWinEnter *
- \ if exists("b:doopenfold") |
- \ exe "normal zv" |
- \ if(b:doopenfold > 1) |
- \ exe "+".1 |
- \ endif |
- \ unlet b:doopenfold |
- \ endif
- augroup END
- " PHP code sniffer
- " If code sniffer is installed you can run it on current php file by running
- " :Phpcs
- function! RunPhpcs()
- let l:filename=@%
- let l:phpcs_output=system('phpcs --report=csv --standard=YMC '.l:filename)
- " echo l:phpcs_output
- let l:phpcs_list=split(l:phpcs_output, "\n")
- unlet l:phpcs_list[0]
- cexpr l:phpcs_list
- cwindow
- endfunction
- set errorformat+=\"%f\"\\,%l\\,%c\\,%t%*[a-zA-Z]\\,\"%m\"
- command! Phpcs execute RunPhpcs()
F1:打开帮助
F3:打开项目管理
F5:编译C
F6:编译C++
F7:打开文件目录
F8:打开标签目录
Ctrl + L:PHP语法检查
Ctrl + N:PHP代码自动补全
Ctrl + P:添加PHP风格的代码注释