win7下基于Vim的代码编辑器
admin 于 2017年08月12日 发表在 windows软件开发

1. vim下载

win7-vim下载(http://www.vim.org/download.php#pc)或者直接下载gvim80版本(ftp://ftp.vim.org/pub/vim/pc/gvim80-586.exe

2. vim安装 

双击安装,安装目录,D:\Vim,安装完成后看到内容,如下:

注意:为防止安装后无法解析,强烈建议路径中不要出现空格,如:Program Files等。

以下是安装方法,如果想直接使用作者配置好的文件,直接看步骤4。

3. 安装几个插件

(1) ctags下载(地址:https://sourceforge.net/projects/ctags/),将解压后的ctags58文件夹复制到 ...\Vim\vimfiles 目录下(事实上,只需要ctags.exe)。

(2) 最精简安装,只安装三个提高效的插件:neocomplcache.vim 、NERD_tree.vim、taglist.vim。

(3) 搜索以上三个插件,官网(http://www.vim.org/)中直接下载,并解压到 ...\Vim\vimfiles 目录下便可。

(4) 配置 ...\Vim 下的 _vimrc 文件,具体内容见附件。

为了快捷安装,可以下载作者已经配置的文件(点击下载附件),并直接解压到 ...\Vim 目录下,目录下内容如:

4. 最终效果

附配置文件(_vimrc):

set nocompatible          " 关闭 vi 兼容模式
syntax on                   " 自动语法高亮
colorscheme  desert         " 设定配色方案
set noeb             " 去掉输入错误的提示声音
set confirm " 在处理未保存或只读文件的时候,弹出确认
set autoindent " 自动缩进
set cindent
set wrap " 自动换行
set linebreak " 整词换行
set number                  " 显示行号
"set cursorline             " 突出显示当前行
set ruler                   " 打开状态栏标尺
set shiftwidth=4            " 设定 << 和 >> 命令移动时的宽度为 4
set softtabstop=4           " 使得按退格键时可以一次删掉 4 个空格
set tabstop=4               " 设定 tab 长度为 4
set history=1000 " 历史记录数
set ignorecase " 搜索忽略大小写
set noexpandtab " 不要用空格代替制表符
set nobackup                " 覆盖文件时不备份
set autochdir               " 自动切换当前目录为当前文件所在的目录
set backupcopy=yes          " 设置备份时的行为为覆盖
set ignorecase smartcase    " 搜索时忽略大小写,但在有一个或以上大写字母时仍保持对大小写敏感
set nowrapscan              " 禁止在搜索到文件两端时重新搜索
set wildmenu " 增强模式中的命令行自动完成操作
set whichwrap+=<,>,h,l  " 允许backspace和光标键跨越行边界
set iskeyword+=_,$,@,%,#,- " 带有如下符号的单词不要被换行分割
set incsearch               " 输入搜索内容时就显示搜索结果
set hlsearch " 搜索逐字符高亮
set incsearch
set noerrorbells            " 关闭错误信息响铃
set novisualbell            " 关闭使用可视响铃代替呼叫
set t_vb=                   " 置空错误铃声的终端代码
set showmatch               " 插入括号时,短暂地跳转到匹配的对应括号
set matchtime=2             " 短暂跳转到匹配括号的时间
set magic                   " 设置魔术
set hidden                  " 允许在有未保存的修改时切换缓冲区,此时的修改由 vim 负责保存
set smartindent             " 开启新行时使用智能自动缩进
set report=0 " 通过使用: commands命令,告诉我们文件的哪一行被改变过
set shortmess=atI   " 启动的时候不显示那个援助索马里儿童的提示
set fillchars=vert:\ ,stl:\ ,stlnc:\ " 在被分割的窗口间显示空白,便于阅读
set backspace=indent,eol,start
                            " 不设定在插入状态无法用退格键和Delete 键删除回车符
set cmdheight=1             " 设定命令行的行数为 1
set foldenable              " 开始折叠
set mouse=a "使用鼠标
set foldmethod=syntax       " 设置语法折叠
filetype plugin indent on   " 开启插件
filetype on " 侦测文件类型
set foldcolumn=1            " 设置折叠区域的宽度
setlocal foldlevel=1        " 设置折叠层数为     
nnoremap <F12> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
                            " 用空格键来开关折叠
"编码设置
set enc=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
set helplang=cn
set imcmdline

"解决菜单乱码    
source $VIMRUNTIME/delmenu.vim    
source $VIMRUNTIME/menu.vim  

"更改字体
set guifont=Consolas:h12

"调整窗口大小
set lines=45 columns=100

" 用户目录变量$VIMFILES
if has("win16") || has("win32") || has("win64") || has("win95")
    let $VIMFILES = $VIM.'/vimfiles'
else
    let $VIMFILES = $HOME.'/.vim'
endif

"我的状态行显示的内容(包括文件类型和解码)
set laststatus=2            " 显示状态栏 (默认值为 1, 无法显示状态栏)
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%m/%d/%Y\ -\ %H:%M\")}
 
 " 设定doc文档目录
let helptags=$VIMFILES.'/doc'

au FileType php setlocal dict+=$VIMFILES.'/dict/php_funclist.dict'
au FileType css setlocal dict+=$VIMFILES.'/dict/css.dict'
au FileType c setlocal dict+=$VIMFILES.'/dict/c.dict'
au FileType cpp setlocal dict+=$VIMFILES.'/dict/cpp.dict'
au FileType scale setlocal dict+=$VIMFILES.'/dict/scale.dict'
au FileType javascript setlocal dict+=$VIMFILES.'/dict/javascript.dict'
au FileType html setlocal dict+=$VIMFILES.'/dict/javascript.dict'
au FileType html setlocal dict+=$VIMFILES.'/dict/css.dict'

"markdown配置
au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn}   set filetype=mkd
au BufRead,BufNewFile *.{go}   set filetype=go
au BufRead,BufNewFile *.{js}   set filetype=javascript
"rkdown to HTML  
nmap md :!$VIMFILES.'/markdown.pl % > %.html <CR><CR>
nmap fi :!firefox %.html & <CR><CR>
nmap \ \cc
vmap \ \cc

"新建.c,.h,.sh,.java文件,自动插入文件头 
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.rb,*.java,*.py exec ":call SetTitle()" 
"定义函数SetTitle,自动插入文件头 
func SetTitle() 
    "如果文件类型为.sh文件 
    if &filetype == 'sh' 
        call setline(1,"\#!/bin/bash") 
        call append(line("."), "") 
    elseif &filetype == 'python'
        call setline(1,"#!/usr/bin/env python")
        call append(line("."),"# coding=utf-8")
        call append(line(".")+1, "") 

    elseif &filetype == 'ruby'
        call setline(1,"#!/usr/bin/env ruby")
        call append(line("."),"# encoding: utf-8")
        call append(line(".")+1, "")

"    elseif &filetype == 'mkd'
"        call setline(1,"<head><meta charset=\"UTF-8\"></head>")
    else 
        call setline(1, "/********************************************************************") 
        call append(line("."), " > File Name: ".expand("%")) 
        call append(line(".")+1, " > Author: JasonLu ") 
        call append(line(".")+2, " > Mail: 1020756702@qq.com") 
        call append(line(".")+3, " > Created Time: ".strftime("%c")) 
        call append(line(".")+4, " *******************************************************************/") 
        call append(line(".")+5, "")
    endif
    if expand("%:e") == 'cpp'
        call append(line(".")+6, "#include<iostream>")
        call append(line(".")+7, "using namespace std;")
        call append(line(".")+8, "")
    endif
    if &filetype == 'c'
        call append(line(".")+6, "#include<stdio.h>")
        call append(line(".")+7, "")
    endif
    if expand("%:e") == 'h'
        call append(line(".")+6, "#ifndef _".toupper(expand("%:r"))."_H")
        call append(line(".")+7, "#define _".toupper(expand("%:r"))."_H")
        call append(line(".")+8, "#endif")
    endif
    if &filetype == 'java'
        call append(line(".")+6,"public class ".expand("%:r"))
        call append(line(".")+7,"")
    endif
    "新建文件后,自动定位到文件末尾
endfunc 
autocmd BufNewFile * normal G

"C,C++ 按F5编译运行
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
    exec "w"
    if &filetype == 'c'
        exec "!g++ % -o %<"
        exec "!time ./%<"
    elseif &filetype == 'cpp'
        exec "!g++ % -o %<"
        exec "!time ./%<"
    elseif &filetype == 'java' 
        exec "!javac %" 
        exec "!time java %<"
    elseif &filetype == 'sh'
        :!time bash %
    elseif &filetype == 'python'
        exec "!time python2.7 %"
    elseif &filetype == 'html'
        exec "!firefox % &"
    elseif &filetype == 'go'
"        exec "!go build %<"
        exec "!time go run %"
    elseif &filetype == 'mkd'
        exec "!$VIMFILES.'/markdown.pl % > %.html &"
        exec "!firefox %.html &"
    endif
endfunc

 "-----------------------------------------------------------------
 " plugin - taglist.vim  查看函数列表,需要ctags程序
 " F3打开隐藏taglist窗口
 "-----------------------------------------------------------------
 nmap <F3> :TlistToggle<CR>
 let Tlist_Ctags_Cmd = $VIMFILES.'/ctags58/ctags.exe'
 let Tlist_Show_One_File = 1            " 不同时显示多个文件的tag,只显示当前文件的
 let Tlist_Exit_OnlyWindow = 1          " 如果taglist窗口是最后一个窗口,则退出vim
 let Tlist_Use_Right_Window = 1         " 在右侧窗口中显示taglist窗口
 let Tlist_Auto_Open = 0
 let Tlist_Auto_Update = 1
 let Tlist_Hightlight_Tag_On_BufEnter = 1
 let Tlist_Enable_Fold_Column = 0
 let Tlist_Display_Prototype = 0
 let Tlist_WinWidth = 30

 " F2 NERDTree 切换
 nmap <F2> :NERDTreeToggle<CR>
 let g:NERDTreeWinPos = "left"
 let g:NERDTreeWinPos="left"
 let g:NERDTreeWinSize=25
 let g:NERDTreeShowLineNumbers=1
 
  "source explorer
 nmap <F4> :SrcExplToggle<CR>
 nmap <C-H> <C-W>h
 nmap <C-J> <C-W>j
 nmap <C-K> <C-W>k
 nmap <C-L> <C-W>l

 let g:SrcExpl_winHeight = 8
 let g:SrcExpl_refreshTime = 100
 let g:SrcExpl_jumpKey = "<ENTER>"
 let g:SrcExpl_gobackKey = "<SPACE>"
 let g:SrcExel_isUpdateTags = 0

 let g:AutoComplPop_NotEnableAtStartup = 1
 let g:NeoComplCache_EnableAtStartup = 1
 let g:NeoComplCache_SmartCase = 1
 let g:NeoComplCache_TagsAutoUpdate = 1
 let g:NeoComplCache_EnableInfo = 1
 let g:NeoComplCache_EnableCamelCaseCompletion = 1
 let g:NeoComplCache_MinSyntaxLength = 3
 let g:NeoComplCache_EnableSkipCompletion = 1
 let g:NeoComplCache_SkipInputTime = '0.5'
 let g:NeoComplCache_SnippetsDir = $VIMFILES.'/snippets'
注意:本站所有文章除特别说明外,均为原创,转载请务必以超链接方式并注明作者出处。 标签:vim,Win7,C/C++