shenzhang 发表于 2015-11-4 08:33:40

Vim配置文件[Windows] 2012-05-01版

" -----------------   Author: Ruchee
" -----------------    Email: my@ruchee.com
" -----------------WebSite: http://www.ruchee.com
" -----------------   Date: 2012-05-01

" Ctrl + H                   --光标移当前行行首
" Ctrl + J                   --光标移下一行行首
" Ctrl + K                   --光标移上一行行尾
" Ctrl + L                   --光标移当前行行尾
" Ctrl + C                   --编译 [支持C/C++、Java、Haskll]
" Ctrl + R                   --运行 [支持C/C++、Java、Haskell、Lua、Perl、Python、Ruby]
" Ctrl + ]                   --转到函数定义
" Ctrl + T                   --返回调用函数
" Ctrl + E                   --一步加载语法模板和作者、时间信息
&quot; <C-P>                      --单词补全
&quot; <C-X><C-L>               --整行补全
&quot; Tab键                      --插入模式下的全功能语法结构补全
&quot; Shift + Insert             --向Vim中粘贴从别处复制的内容
&quot; u [小写]                   --单步复原 [非插入模式]
&quot; U [大写]                   --整行复原 [非插入模式]
&quot; jj                         --保存文件并留在插入模式 [插入模式]
&quot; kk                         --返回Normal模式 [插入模式]
&quot; nt                         --打开NERDTree [非插入模式]
&quot; tl                         --打开TagList [非插入模式]
&quot; za                         --打开或关闭当前折叠
&quot; zM                         --关闭所有折叠
&quot; zR                         --打开所有折叠
&quot; :set syntax=cpp            --手动选择语法高亮 [或 :set filetype=cpp]
&quot; :%!xxd                     --转储二进制文件,以十六进制形式显示
&quot; :%!xxd -r                  --还原二进制文件

&quot; ---------- 主要插件详细用法说明 ---------------------
&quot; :Tlist                     --呼出变量和函数列表
&quot; :LoadTemplate            --呼出语法模板
&quot; :AuthorInfoDetect          --添加作者、时间等信息
&quot; ---------- a.vim [自动切换C/C++同名头文件] ----------
&quot;
&quot; :A                         --切换同名头文件并独占整个屏幕
&quot; :AS                        --切换同名头文件并垂直分屏,头文件在上
&quot; :AV                        --切换同名头文件并水平分割,头文件在左
&quot; ---------- mark.vim [追踪高亮指定关键字] ------------
&quot;
&quot; \m                         --normal模式下,在想要高亮的单词上面敲击\m即可高亮或取消高亮该单词
&quot; :Mark                      --取消所有高亮
&quot; :Mark abc                  --指定高亮单词 abc 或取消高亮 abc
&quot; ---------- NERDTree [智能文件浏览器] ----------------
&quot;
&quot; :NERDTree                  --启动NERDTree插件
&quot; o [小写]                   --切换当前文件或目录的打开、关闭状态
&quot; u                        --打开上层目录
&quot; p [小写]                   --返回上层目录
&quot; P [大写]                   --返回根目录
&quot; K                        --转到当前目录第一个节点
&quot; J                        --转到当前目录最后的节点
&quot; m                        --显示文件系统菜单 [增、删、移]
&quot; ?                        --弹出帮助菜单
&quot; q                        --退出该插件

&quot; 将所有以.html结尾的文档以Django Template语法进行渲染
&quot; 本配置语句必须放在所有配置的最前面
au BufNewFile,BufRead *.html setf htmldjango
colorscheme blackboard       &quot; 着色模式:蓝色背景
set guifont=Monaco:h10       &quot; 字体 && 字号
set tabstop=4                &quot; 设置tab键的宽度
set shiftwidth=4             &quot; 换行时行间交错使用4个空格
set autoindent               &quot; 自动对齐
set backspace=2            &quot; 设置退格键可用
set cindent shiftwidth=4   &quot; 自动缩进4空格
set smartindent            &quot; 智能自动缩进
set ai!                      &quot; 设置自动缩进
set nu!                      &quot; 显示行号
&quot;set showmatch               &quot; 显示括号配对情况
set mouse=a                  &quot; 启用鼠标
set ruler                  &quot; 右下角显示光标位置的状态行
set incsearch                &quot; 查找book时,当输入/b时会自动找到
set hlsearch               &quot; 开启高亮显示结果
set incsearch                &quot; 开启实时搜索功能
set nowrapscan               &quot; 搜索到文件两端时不重新搜索
set nocompatible             &quot; 关闭兼容模式
set vb t_vb=               &quot; 关闭提示音
&quot;set cursorline            &quot; 突出显示当前行
set hidden                   &quot; 允许在有未保存的修改时切换缓冲区
set list                     &quot; 显示Tab符,使用一高亮竖线代替
set listchars=tab:\|\ ,
syntax enable                &quot; 打开语法高亮
syntax on                  &quot; 开启文件类型侦测
filetype indent on         &quot; 针对不同的文件类型采用不同的缩进格式
filetype plugin on         &quot; 针对不同的文件类型加载对应的插件
filetype plugin indent on    &quot; 启用自动补全

if has(&quot;gui_running&quot;)
au GUIEnter * simalt ~x&quot; 窗口启动时自动最大化
&quot;winpos 20 20            &quot; 指定窗口出现的位置,坐标原点在屏幕左上角
&quot;set lines=20 columns=90 &quot; 指定窗口大小,lines为高度,columns为宽度
&quot;set guioptions-=m       &quot; 隐藏菜单栏
&quot;set guioptions-=T       &quot; 隐藏工具栏
&quot;set guioptions-=L       &quot; 隐藏左侧滚动条
&quot;set guioptions-=r       &quot; 隐藏右侧滚动条
&quot;set guioptions-=b       &quot; 隐藏底部滚动条
&quot;set showtabline=0       &quot; 隐藏Tab栏
endif
set writebackup            &quot; 设置无备份文件
set nobackup
set autochdir                &quot; 设定文件浏览器目录为当前目录
&quot;set nowrap                  &quot; 设置不自动换行
set foldmethod=syntax      &quot; 选择代码折叠类型
set foldlevel=100            &quot; 禁止自动折叠
set laststatus=2             &quot; 开启状态栏信息
set cmdheight=2            &quot; 命令行的高度,默认为1,这里设为2
&quot; 每行超过80个的字符用下划线标示
au BufRead,BufNewFile *.s,*.asm,*.h,*.c,*.cpp,*.cc,*.java,*.cs,*.erl,*.hs,*.sh,*.lua,*.pl,*.pm,*.php,*.py,*.rb,*.erb,*.vim,*.js,*.css,*.xml,*.html,*.xhtml 2match Underlined /.\%81v/

&quot; 设置编码
set fenc=utf-8
set encoding=utf-8
set fileencodings=utf-8,gbk,cp936,latin-1
&quot; 解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
&quot; 解决consle输出乱码
language messages zh_CN.utf-8

&quot; For Haskell
:let hs_highlight_delimiters=1            &quot; 高亮定界符
:let hs_highlight_boolean=1               &quot; 把True和False识别为关键字
:let hs_highlight_types=1               &quot; 把基本类型的名字识别为关键字
:let hs_highlight_more_types=1            &quot; 把更多常用类型识别为关键字
:let hs_highlight_debug=1               &quot; 高亮调试函数的名字
:let hs_allow_hash_operator=1             &quot; 阻止把#高亮为错误

&quot; ======= 引号 && 括号自动匹配 ======= &quot;
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {}<ESC>i
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
&quot;:inoremap < <><ESC>i
&quot;:inoremap > <c-r>=ClosePair('>')<CR>
:inoremap &quot; &quot;&quot;<ESC>i
:inoremap ' ''<ESC>i
:inoremap ` ``<ESC>i
function ClosePair(char)
if getline('.') == a:char
return &quot;\<Right>&quot;
else
return a:char
endif
endf

&quot; MiniBufExplorer   多个文件切换 可使用鼠标双击相应文件名进行切换
let g:miniBufExplMapWindowNavVim=1
let g:miniBufExplMapWindowNavArrows=1
let g:miniBufExplMapCTabSwitchBufs=1
let g:miniBufExplModSelTarget=1
&quot; :Tlist            调用TagList
let Tlist_Show_One_File=1                  &quot; 只显示当前文件的tags
let Tlist_Exit_OnlyWindow=1                  &quot; 如果Taglist窗口是最后一个窗口则退出Vim
let Tlist_Use_Right_Window=1               &quot; 在右侧窗口中显示
let Tlist_File_Fold_Auto_Close=1             &quot; 自动折叠
&quot; TxtBrowser          高亮TXT文本文件
au BufRead,BufNewFile *.txt setlocal ft=txt
&quot; :LoadTemplate       根据文件后缀自动加载模板
let g:template_path='D:/Apps/Gvim/vimfiles/template/'
&quot; :AuthorInfoDetect   自动添加作者、时间等信息,本质是NERD_commenter && authorinfo的结合
let g:vimrc_author='Ruchee'
let g:vimrc_email='my@ruchee.com'
let g:vimrc_homepage='http://www.ruchee.com'
&quot; Ctrl + H            将光标移到当前行的行首
imap <c-h> <ESC>I
&quot; Ctrl + J            将光标移到下一行的行首
imap <c-j> <ESC>jI
&quot; Ctrl + K            将光标移到上一行的末尾
imap <c-k> <ESC>kA
&quot; Ctrl + L            将光标移到当前行的行尾
imap <c-l> <ESC>A
&quot; Ctrl + E            一步加载语法模板和作者、时间信息
map <c-e> <ESC>:LoadTemplate<CR><ESC>:AuthorInfoDetect<CR><ESC>Gi
imap <c-e> <ESC>:LoadTemplate<CR><ESC>:AuthorInfoDetect<CR><ESC>Gi
vmap <c-e> <ESC>:LoadTemplate<CR><ESC>:AuthorInfoDetect<CR><ESC>Gi
&quot; jj                  保存文件并留在插入模式 [插入模式]
imap jj <ESC>:w<CR>li
&quot; kk                  返回Normal模式 [插入模式]
imap kk <ESC>l
&quot; nt                  打开NERDTree [非插入模式]
map nt :NERDTree<CR>
&quot; tl                  打开Taglist [非插入模式]
map tl :Tlist<CR><c-l>

&quot; ======= 编译 && 运行 ======= &quot;
&quot; 编译源文件
func! CompileCode()
exec &quot;w&quot;
if &filetype == &quot;c&quot;
exec &quot;!gcc -Wall -std=c99 %<.c -o %<&quot;
elseif &filetype == &quot;cpp&quot;
exec &quot;!g++ -Wall -std=c++98 %<.cpp -o %<&quot;
elseif &filetype == &quot;java&quot;
exec &quot;!javac %<.java&quot;
elseif &filetype == &quot;haskell&quot;
exec &quot;!ghc --make %<.hs -o %<&quot;
elseif &filetype == &quot;lua&quot;
exec &quot;!lua %<.lua&quot;
elseif &filetype == &quot;perl&quot;
exec &quot;!perl %<.pl&quot;
elseif &filetype == &quot;python&quot;
exec &quot;!python %<.py&quot;
elseif &filetype == &quot;ruby&quot;
exec &quot;!ruby %<.rb&quot;
endif
endfunc
&quot; 运行可执行文件
func! RunCode()
exec &quot;w&quot;
if &filetype == &quot;c&quot; || &filetype == &quot;cpp&quot; || &filetype == &quot;haskell&quot;
exec &quot;! %<.exe&quot;
elseif &filetype == &quot;java&quot;
exec &quot;!java %<&quot;
elseif &filetype == &quot;lua&quot;
exec &quot;!lua %<.lua&quot;
elseif &filetype == &quot;perl&quot;
exec &quot;!perl %<.pl&quot;
elseif &filetype == &quot;python&quot;
exec &quot;!python %<.py&quot;
elseif &filetype == &quot;ruby&quot;
exec &quot;!ruby %<.rb&quot;
endif
endfunc
&quot; Ctrl + C 一键保存、编译
map <c-c> :call CompileCode()<CR>
imap <c-c> <ESC>:call CompileCode()<CR>
vmap <c-c> <ESC>:call CompileCode()<CR>
&quot; Ctrl + R 一键保存、运行
map <c-r> :call RunCode()<CR>
imap <c-r> <ESC>:call RunCode()<CR>
vmap <c-r> <ESC>:call RunCode()<CR>
页: [1]
查看完整版本: Vim配置文件[Windows] 2012-05-01版