这几天突然兴致来了,准备学习一下传说中的神级编辑器VIM,于是花了很长时间进行学习,我只能说百度太坑了……,搞得我筋疲力竭,心力憔悴啊。但是工欲善其事,必先利其器,因此坚持了下来,将这几天学到的东西写成博客。一是希望大家能够少走一些弯路,二是作为自己的备份,以后兴许还可以用到。
我的系统是windows,用到gvim7.4,链接:gvim官网
我的安装路径:D:\Program Files (x86)\Vim
安装完成后配置文件路径:D:\Program Files (x86)\Vim_vimrc
source $VIMRUNTIME/setting.vim
,"=============================常用设置================================ let mapleader = "," set nocp " 设置备份时的行为为覆盖
set backupcopy=yes
" 禁止在搜索到文件两端时重新搜索 "set nowrapscan
" 输入搜索内容时就显示搜索结果 " set incsearch
" 搜索时高亮显示被找到的文本 set hlsearch set noerrorbells " 关闭错误信息响铃
set novisualbell " 关闭使用可视响铃代替呼叫 set t_vb= " 置空错误铃声的终端代码
set magic " 设置魔术 set hidden " 允许在有未保存的修改时切换缓冲区,此时的修改由 vim 负责保存
set guioptions-=T " 隐藏工具栏 set guioptions-=m " 隐藏菜单栏
"设置C/C++方式自动对齐 set autoindent set cindent " 不设定在插入状态无法用退格键和 Delete 键删除回车符
set backspace=indent,eol,start
"设置按退格键时可以一次删除4个空格 set softtabstop=4 "禁止生成备份文件
set nobackup
set noswapfile
set nowb
"指定配色方案为256色 set t_Co=256 "设置匹配模式 类似当输入一个左括号时会匹配相应的那个右括号
set showmatch
"搜索逐字符高亮 set incsearch "行内替换
set gdefault
"显示光标的坐标 set ruler "这里是为了php的编码规范需求,所以也可以将文件只限定为php生效
" autocmd FileType php set expandtab "根据编辑模式更改输入法光标颜色,同时禁用IME自动切换
if has('multi_byte_ime')
hi Cursor guifg=bg guibg=Orange gui=NONE
hi CursorIM guifg=NONE guibg=Skyblue gui=NONE
set iminsert=0 imsearch=0
endif
"与Windows共享剪贴板 set clipboard+=unnamed "编辑vimrc之后,重新加载
autocmd! bufwritepost _vimrc source $VIM/_vimrc
"==============================常用设置end===================================== "==============================基本设置========================================
"----------------------------------------------------------------- " 获取当前系统类型
"------------------------------------------------------------------ function! MySys() if has("win16") || has("win32") || has("win64") || has("win95") return "windows" elseif has("unix") return "linux" endif endfunction " -----------------------------------------------------------------------------
" < 判断操作系统是否是 Windows 还是 Linux > " -----------------------------------------------------------------------------
let g:iswindows = 0
let g:islinux = 0
if(has("win32") || has("win64") || has("win95") || has("win16"))
let g:iswindows = 1
else
let g:islinux = 1
endif
" ----------------------------------------------------------------------------- " < 判断是终端还是 Gvim >
" ----------------------------------------------------------------------------- if has("gui_running") let g:isGUI = 1 else let g:isGUI = 0 endif " 用户目录变量$VIMFILES
if g:iswindows
let $VIMFILES = $VIM.'/vimfiles'
" set backupdir=D://Program Files (x86)/Vim/tmp else let $VIMFILES = $HOME.'/.vim' " set backupdir=/tmp
endif
"---------------------------------------------------------------- "编码设置
"---------------------------------------------------------------- "Vim 在与屏幕/键盘交互时使用的编码(取决于实际的终端的设定)
set termencoding=utf-8
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,gbk,default,latin1
if has("win32")
set fileencoding=chinese
else
set fileencoding=utf-8
endif
"解决菜单乱码 source $VIMRUNTIME/delmenu.vim source $VIMRUNTIME/menu.vim "解决consle输出乱码
language messages zh_CN.utf-8
"设置中文帮助 set helplang=cn " -----------------------------------------------------------------------------
" < 编写文件时的配置 > " -----------------------------------------------------------------------------
filetype on "启用文件类型侦测 filetype plugin on "针对不同的文件类型加载对应的插件
filetype plugin indent on "启用缩进 set smartindent "启用智能对齐方式
set expandtab "将Tab键转换为空格 set tabstop=4 "设置Tab键的宽度,可以更改,如:宽度为2
set shiftwidth=4 "换行时自动缩进宽度,可更改(宽度同tabstop) set smarttab "指定按一次backspace就删除shiftwidth宽度
" 当文件在外部被修改,自动更新该文件 set autoread " 常规模式下输入 cS 清除行尾空格
nmap cS :%s/\s\+$//g<CR>:noh<CR>
" 常规模式下输入 cM 清除行尾 ^M 符号 nmap cM :%s/\r$//g<CR>:noh<CR> set ignorecase "搜索模式里忽略大小写
set smartcase "如果搜索模式包含大写字符,不使用 'ignorecase' 选项,只有在输入搜索模式并且打开 'ignorecase' 选项时才会使用 " set noincsearch "在输入要搜索的文字时,取消实时匹配 " Ctrl + K 插入模式下光标向上移动
imap <c-k> <Up>
" Ctrl + J 插入模式下光标向下移动 imap <c-j> <Down> " Ctrl + H 插入模式下光标向左移动
imap <c-h> <Left>
" Ctrl + L 插入模式下光标向右移动 imap <c-l> <Right> " 自动把内容写回文件: 如果文件被修改过,在每个 :next、:rewind、:last、:first、:previous、:stop、:suspend、:tag、:!、:make、CTRL-] 和 CTRL-^命令时进行;
" 用 :buffer、CTRL-O、CTRL-I、'{A-Z0-9} 或 `{A-Z0-9} 命令转到别的文件时亦然。 set autowrite "自定义关联文件类型
au BufNewFile,BufRead *.less set filetype=css
au BufNewFile,BufRead *.phtml set filetype=php
au BufRead,BufNewFile *.js set ft=javascript.jquery
" 启用每行超过80列的字符提示(字体变蓝并加下划线),不启用就注释掉 "au BufWinEnter * let w:m2=matchadd('Underlined', '\%>' . 80 . 'v.\+', -1)
" ----------------------------------------------------------------------------- " < 界面配置 >
" ----------------------------------------------------------------------------- set nu! "显示行号
set laststatus=2 "启用状态栏信息 set cmdheight=1 "设置命令行的高度为2,默认为1
set cursorline "突出显示当前行 "set cursorcolumn
" set guifont=YaHei_Consolas_Hybrid:h10 "设置字体:字号(字体名称空格用下划线代替)
set guifont=Consolas:h12
set nowrap "设置不自动换行 set shortmess=atI "去掉欢迎界面
" 设置 gVim 窗口初始位置及大小 if g:isGUI au GUIEnter * simalt ~x "窗口启动时自动最大化
winpos 100 10 "指定窗口出现的位置,坐标原点在屏幕左上角 " set lines=38 columns=120 "指定窗口大小,lines为高度,columns为宽度 endif " 设置代码配色方案
if g:isGUI
colorscheme molokai "设置配色方案 else colorscheme Tomorrow-Night-Eighties "终端配色方案
endif
" 设置在状态行显示的信息 set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\ set errorformat=%m\ in\ %f\ on\ line\ %l " 显示/隐藏菜单栏、工具栏、滚动条,可用 Ctrl + F11 切换
if g:isGUI
let g:show_bar=0
set guioptions-=m
set guioptions-=T
set guioptions-=r
set guioptions-=L
nmap <silent> <c-F11> :call Show_bar()<CR>
func! Show_bar()
if g:show_bar==1
let g:show_bar = 0
set guioptions-=m
set guioptions-=T
set guioptions-=r
set guioptions-=L
else
let g:show_bar=1
set guioptions+=m
set guioptions+=T
set guioptions+=r
set guioptions+=L
endif
endfunc
endif
"------------------------------------------------------- "括号自动补全
"------------------------------------------------------- :inoremap ( ()<ESC>i :inoremap ) <c-r>=ClosePair(')')<CR> :inoremap { {<CR>}<ESC>O :inoremap } <c-r>=ClosePair('}')<CR> :inoremap [ []<ESC>i :inoremap ] <c-r>=ClosePair(']')<CR> :inoremap " ""<ESC>i
:inoremap ' ''<ESC>i function! ClosePair(char) if getline('.')[col('.') - 1] == a:char return "\<Right>" else return a:char endif endfunction "------------------------------------------------------------------------ "拼写检查 "------------------------------------------------------------------------ map <leader>sn ] map <leader>sp [ map <leader>sa zg map <leader>s? z= "设置工作目录为当前编辑文件的目录 set bsdir=buffer set autochdir "关闭vi的一致性模式 避免以前版本的一些Bug和局限 set nocompatible "在状态栏显示正在输入的命令 set showcmd "设置历史记录条数 set history=1000 "------------------------------------------------------------- " 光标到上方窗口,需要<c-w><c-w>k,非常麻烦,现在重映射为<c-k> " ------------------------------------------------------------ nnoremap <C-h> <C-w>h nnoremap <C-j> <C-w>j nnoremap <C-k> <C-w>k nnoremap <C-l> <C-w>l "-------------------------------------------------------------- "一些不错的映射转换语法(如果在一个文件中混合了不同语言时有用) "--------------------------------------------------------------- nnoremap <leader>1 :set filetype=xhtml<CR> nnoremap <leader>2 :set filetype=css<CR> nnoremap <leader>3 :set filetype=javascript<CR> nnoremap <leader>4 :set filetype=php<CR> " Python 文件的一般设置,比如不要 tab 等 " autocmd FileType python set tabstop=4 shiftwidth=4 expandtab " autocmd FileType python map <F12> :!python %<CR> " 设置数据字典 ~/.vim/dict/文件的路径 set complete-=k complete+=k " autocmd filetype javascript set dictionary=$VIMFILES/dict/javascript.dict " autocmd filetype css set dictionary=$VIMFILES/dict/css.dict au FileType php setlocal dict+=$VIMFILES/dict/php.dict
- 配置vundle(我的vundle路径是在D:\Program Files (x86)\Vim\vimfiles\bundle)
- github地址 https://github.com/gmarik/vundle.git
- 直接在刚才的这个文件夹中clone 到本地
- 在setting.vim文件中加入
set rtp+=$VIM/vimfiles/bundle/vundle/
"此处规定插件的安装路径 call vundle#rc('$VIM/vimfiles/bundle/') Bundle 'gmarik/vundle'
"===============================================================================================================
"插件设置
"===============================================================================================================
"此处规定Vundle的路径
set rtp+=$VIM/vimfiles/bundle/vundle/
"此处规定插件的安装路径
call vundle#rc('$VIM/vimfiles/bundle/')
Bundle 'gmarik/vundle'
"---------------------------------------------------------
"---NeoComplCache 启动
"---------------------------------------------------------
Bundle 'neocomplete.vim'
"Note: This option must set it in .vimrc(_vimrc). NOT IN .gvimrc(_gvimrc)!
" Disable AutoComplPop.
let g:acp_enableAtStartup = 0
" Use neocomplete.
let g:neocomplete#enable_at_startup = 1
" Use smartcase.
let g:neocomplete#enable_smart_case = 1
" Set minimum syntax keyword length.
let g:neocomplete#sources#syntax#min_keyword_length = 3
let g:neocomplete#lock_buffer_name_pattern = '\*ku\*'
" Define dictionary.
"let g:neocomplete#sources#dictionary#dictionaries = {
" \ 'default' : '',
" \ 'vimshell' : $HOME.'/.vimshell_hist',
" \ 'scheme' : $HOME.'/.gosh_completions'
" \ }
" Define keyword.
if !exists('g:neocomplete#keyword_patterns')
let g:neocomplete#keyword_patterns = {}
endif
let g:neocomplete#keyword_patterns['default'] = '\h\w*'
" Plugin key-mappings.
inoremap <expr><A-g> neocomplete#undo_completion()
inoremap <expr><A-l> neocomplete#complete_common_string()
" Recommended key-mappings.
" <CR>: close popup and save indent.
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
return (pumvisible() ? "\<C-y>" : "" ) . "\<CR>"
" For no inserting <CR> key.
"return pumvisible() ? "\<C-y>" : "\<CR>"
endfunction
" <TAB>: completion.
inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
" <C-h>, <BS>: close popup and delete backword char.
inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>"
" Close popup by <Space>.
"inoremap <expr><Space> pumvisible() ? "\<C-y>" : "\<Space>"
" AutoComplPop like behavior.
"let g:neocomplete#enable_auto_select = 1
" Shell like behavior(not recommended).
"set completeopt+=longest
"let g:neocomplete#enable_auto_select = 1
"let g:neocomplete#disable_auto_complete = 1
"inoremap <expr><TAB> pumvisible() ? "\<Down>" : "\<C-x>\<C-u>"
" Enable omni completion.
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete
" Enable heavy omni completion.
if !exists('g:neocomplete#sources#omni#input_patterns')
let g:neocomplete#sources#omni#input_patterns = {}
endif
"let g:neocomplete#sources#omni#input_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
"let g:neocomplete#sources#omni#input_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
"let g:neocomplete#sources#omni#input_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'
" For perlomni.vim setting.
" https://github.com/c9s/perlomni.vim
let g:neocomplete#sources#omni#input_patterns.perl = '\h\w*->\h\w*\|\h\w*::'
"---------------------------------------------------------
"---neosnippet
"---------------------------------------------------------
"Bundle 'neosnippet.vim'
" Plugin key-mappings.
"imap <C-k> <Plug>(neosnippet_expand_or_jump)
"smap <C-k> <Plug>(neosnippet_expand_or_jump)
"xmap <C-k> <Plug>(neosnippet_expand_target)
" SuperTab like snippets behavior.
"imap <expr><TAB>
" \ pumvisible() ? "\<C-n>" :
" \ neosnippet#expandable_or_jumpable() ?
" \ "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
"smap <expr><TAB> neosnippet#expandable_or_jumpable() ?
"\ "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
" For conceal markers.
"if has('conceal')
" set conceallevel=2 concealcursor=niv
"endif
" Enable snipMate compatibility feature.
"let g:neosnippet#enable_snipmate_compatibility = 1
" Tell Neosnippet about the other snippets
"let g:neosnippet#snippets_directory='~/.vim/bundle/vim-snippets/snippets'
"---------------------------------------------------------
"taglist快捷键设置
"---------------------------------------------------------
Bundle 'taglist.vim'
"let Tlist_Ctags_Cmd="D:/Program\ Files\ (x86)/tools/ctags"
" 按下F8重新生成tag文件,并更新taglist
map <C-F7> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
set tags=tags; "这是告诉vim在当前目录找不到tags文件时请到上层目录查找。
set tags+=.tags "add current directory's generated tags file
"set tags+=~/Vim_Tags/tags "add new tags file(刚刚生成tags的路径,在ctags -R 生成tags文件后,不要将tags移动到别的目录,否则ctrl+]时,会提示找不到源码文件)
nnoremap <silent><F7> :TlistToggle<CR>
let Tlist_Ctags_Cmd='ctags' "因为我们放在环境变量里,所以可以直接执行
let Tlist_Use_Right_Window=1 "让窗口显示在右边,0的话就是显示在左边
let Tlist_Show_One_File=1 "让taglist可以同时展示多个文件的函数列表
let Tlist_File_Fold_Auto_Close=1 "非当前文件,函数列表折叠隐藏
let Tlist_Exit_OnlyWindow=1 "当taglist是最后一个分割窗口时,自动推出vim
let Tlist_Auto_Open = 0
let Tlist_Auto_Update = 1
let Tlist_Hightlight_Tag_On_BufEnter = 1
let Tlist_Enable_Fold_Column = 0
"是否一直处理tags.1:处理;0:不处理
let Tlist_Process_File_Always=1 "实时更新tags
let Tlist_Inc_Winwidth=0
let Tlist_Show_Menu=1 "显示taglist菜单
let Tlist_Close_On_Select=1 "在选择了tag后自动关闭taglist窗口
let Tlist_WinWidth=25 "设置宽度
"-----------------------------------------------------------------
" plugin - NERDTree 配置
"-----------------------------------------------------------------
Bundle 'The-NERD-tree'
let NERDTreeWinPos="left"
let NERDTreeWinSize=20
map <silent><F6> :NERDTreeToggle<CR>
let NERDTreeChDirMode=2 "选中root即设置为当前目录
let NERDTreeQuitOnOpen=1 "打开文件时关闭树
let NERDTreeShowBookmarks=1 "显示书签
let NERDTreeMinimalUI=1 "不显示帮助面板
let NERDTreeDirArrows=1 "目录箭头 1 显示箭头 0传统+-|号
" let NERDTreeChDirMode=1 " 改变tree目录的同时改变工程的目录
"-----------------------------------------------------------------
" plugin - doxygen toolkit 配置
"-----------------------------------------------------------------
Bundle 'DoxygenToolkit.vim'
let g:DoxygenToolkit_briefTag_pre="@brief "
let g:DoxygenToolkit_paramTag_pre="@Param "
let g:DoxygenToolkit_returnTag="@return "
let s:licenseTag = "Copyright(C)\<enter>"
let s:licenseTag = s:licenseTag . "For free\<enter>"
let s:licenseTag = s:licenseTag . "All right reserved\<enter>"
let g:DoxygenToolkit_licenseTag = s:licenseTag
let g:DoxygenToolkit_authorName="Changzhi <[email protected]>"
let g:DoxygenToolkit_briefTag_funcName="yes"
let g:doxygen_enhanced_color=1
let g:DoxygenToolkit_maxFunctionProtoLines = 30
let g:DoxygenToolkit_blockHeader="--------------------------------------------------------------------------"
let g:DoxygenToolkit_blockFooter="----------------------------------------------------------------------------"
map ff : Dox<cr>
"按下ff就会对函数进行注释
map fa : DoxAuthor<cr>
"会对文件加上文档注释
map fl : Doxlic<cr>
"进行授权注释
"-----------------------------------------------------------------
"grep在工程中查找
"-----------------------------------------------------------------
Bundle 'grep.vim'
nnoremap <silent> <F3> :Grep<CR>
"-----------------------------------------------------------------
"Visual-Mark高亮书签 ctrl+F2或mm添加书签,F2在书签之间切换,shift+F2反向切换
"-----------------------------------------------------------------
Bundle 'Visual-Mark'
"-----------------------------------------------------------------
"安装phpcomplete插件
"-----------------------------------------------------------------
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
"-----------------------------------------------------------------
"安装emmet
"-----------------------------------------------------------------
Bundle 'Emmet.vim'
let g:user_emmet_settings = {
\ 'indentation' : ' ',
\ 'perl' : {
\ 'aliases' : {
\ 'req' : 'require '
\ },
\ 'snippets' : {
\ 'use' : "use strict\nuse warnings\n\n",
\ 'warn' : "warn \"|\";",
\ }
\ }
\}
let g:user_emmet_expandabbr_key = '<c-e>'
let g:use_emmet_complete_tag = 1
"-----------------------------------------------------------------
"NerdCommenter注释插件
"-----------------------------------------------------------------
Bundle 'The-NERD-Commenter'
let NERDShutUp=1
"支持单行和多行的选择,//格式
map <c-/> ,c<space>
let NERDSpaceDelims=1 " 让注释符与语句之间留一个空格
let NERDCompactSexyComs=1 " 多行注释时样子更好看
"-----------------------------------------------------------------
"ctrlp
"-----------------------------------------------------------------
Bundle 'ctrlp.vim'
"nnoremap <silent> <C-p> :ClearAllCtrlPCache<CR>\|:CtrlP<CR>
let g:ctrlp_map = '<leader>f'
let g:ctrlp_cmd = 'CtrlP'
map <leader>m :CtrlPMRU<CR>
map <leader>a :CtrlPMixed<CR>
set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe " Windows
"let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn)$',
\ 'file': '\v\.(exe|so|dll)$',
\ 'link': 'some_bad_symbolic_links',
\ }
"let g:ctrlp_working_path_mode=0
"let g:ctrlp_match_window_bottom=1
"let g:ctrlp_max_height=15
"let g:ctrlp_match_window_reversed=0
"let g:ctrlp_mruf_max=500
"let g:ctrlp_follow_symlinks=1
"vim-airline
Bundle 'vim-airline'
let g:airline_theme="luna"
"这个是安装字体后 必须设置此项"
let g:airline_powerline_fonts = 1
"打开tabline功能,方便查看Buffer和切换,这个功能比较不错"
"我还省去了minibufexpl插件,因为我习惯在1个Tab下用多个buffer"
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_nr_show = 1
"设置切换Buffer快捷键"
nnoremap <C-tab> :bn<CR>
nnoremap <C-s-tab> :bp<CR>
" 关闭状态显示空白符号计数,这个对我用处不大"
let g:airline#extensions#whitespace#enabled = 0
let g:airline#extensions#whitespace#symbol = '!'
" 设置consolas字体"
set guifont=Consolas\ for\ Powerline\ FixedD:h11
"设置状态栏符号显示,下面编码用双引号"
let g:Powerline_symbols="fancy"
let g:airline_symbols = {}
let g:airline_left_sep = "\u2b80"
let g:airline_left_alt_sep = "\u2b81"
let g:airline_right_sep = "\u2b82"
let g:airline_right_alt_sep = "\u2b83"
let g:airline_symbols.branch = "\u2b60"
let g:airline_symbols.readonly = "\u2b64"
let g:airline_symbols.linenr = "\u2b61"
"设置顶部tabline栏符号显示"
let g:airline#extensions#tabline#left_sep = "\u2b80"
let g:airline#extensions#tabline#left_alt_sep = "\u2b81"
" -----------------------------------------------------------------------------
" < 在浏览器中预览 Html 或 PHP 文件 >
" -----------------------------------------------------------------------------
" 修改前请先通读此模块,明白了再改以避免错误
" F5 加浏览器名称缩写调用浏览器预览,启用前先确定有安装相应浏览器,并在下面的配置好其安装目录
if g:iswindows
"以下为只支持Windows系统的浏览器
" 调用系统IE浏览器预览,如果已卸载可将其注释
" nmap <F5>ie :call ViewInBrowser("ie")<cr>
" imap <F5>ie <ESC>:call ViewInBrowser("ie")<cr>
" 调用IETester(IE测试工具)预览,如果有安装可取消注释
" nmap <F5>ie6 :call ViewInBrowser("ie6")<cr>
" imap <F5>ie6 <ESC>:call ViewInBrowser("ie6")<cr>
" nmap <F5>ie7 :call ViewInBrowser("ie7")<cr>
" imap <F5>ie7 <ESC>:call ViewInBrowser("ie7")<cr>
" nmap <F5>ie8 :call ViewInBrowser("ie8")<cr>
" imap <F5>ie8 <ESC>:call ViewInBrowser("ie8")<cr>
" nmap <F5>ie9 :call ViewInBrowser("ie9")<cr>
" imap <F5>ie9 <ESC>:call ViewInBrowser("ie9")<cr>
" nmap <F5>ie10 :call ViewInBrowser("ie10")<cr>
" imap <F5>ie10 <ESC>:call ViewInBrowser("ie10")<cr>
" nmap <F5>iea :call ViewInBrowser("iea")<cr>
" imap <F5>iea <ESC>:call ViewInBrowser("iea")<cr>
elseif g:islinux
"以下为只支持Linux系统的浏览器
"暂未配置,待有时间再弄了
endif
"以下为支持Windows与Linux系统的浏览器
" 调用Firefox浏览器预览,如果有安装可取消注释
" nmap <F5>ff :call ViewInBrowser("ff")<cr>
" imap <F5>ff <ESC>:call ViewInBrowser("ff")<cr>
" 调用Maxthon(遨游)浏览器预览,如果有安装可取消注释
" nmap <F5>ay :call ViewInBrowser("ay")<cr>
" imap <F5>ay <ESC>:call ViewInBrowser("ay")<cr>
" 调用Opera浏览器预览,如果有安装可取消注释
" nmap <F5>op :call ViewInBrowser("op")<cr>
" imap <F5>op <ESC>:call ViewInBrowser("op")<cr>
" 调用Chrome浏览器预览,如果有安装可取消注释
nmap <F5> :call ViewInBrowser("cr")<cr>
imap <F5> <ESC>:call ViewInBrowser("cr")<cr>
" 浏览器调用函数
function! ViewInBrowser(name)
if expand("%:e") == "php" || expand("%:e") == "html"
exe ":update"
if g:iswindows
"获取要预览的文件路径,并将路径中的'\'替换为'/',同时将路径文字的编码转换为gbk(同cp936)
let file = iconv(substitute(expand("%:p"), '\', '/', "g"), "utf-8", "gbk")
"浏览器路径设置,路径中使用'/'斜杠,更改路径请更改双引号里的内容
"下面只启用了系统IE浏览器,如需启用其它的可将其取消注释(得先安装,并配置好安装路径),也可按需增减
"let SystemIE = "C:/progra~1/intern~1/iexplore.exe" "系统自带IE目录
"let IETester = "F:/IETester/IETester.exe" "IETester程序目录(可按实际更改)
let Chrome = "C:/Users/chang/AppData/Local/Google/Chrome/Application/chrome.exe" "Chrome程序目录(可按实际更改)
" let Firefox = "F:/Firefox/Firefox.exe" "Firefox程序目录(可按实际更改)
" let Opera = "F:/Opera/opera.exe" "Opera程序目录(可按实际更改)
" let Maxthon = "C:/Progra~2/Maxthon/Bin/Maxthon.exe" "Maxthon程序目录(可按实际更改)
"本地虚拟服务器设置,我测试的是phpStudy2014,可根据自己的修改,更改路径请更改双引号里的内容
let www ="E:/www/" "虚拟服务器地址或目录(可按实际更改)
let url = "localhost:8080" "虚拟服务器网址(可按实际更改)
elseif g:islinux
"暂时还没有配置,有时间再弄了。
endif
"浏览器调用缩写,可根据实际增减,注意,上面浏览器路径中没有定义过的变量(等号右边为变量)不能出现在下面哟(可将其注释或删除)
let l:browsers = {} "定义缩写字典变量,此行不能删除或注释
let l:browsers["cr"] = Chrome "Chrome浏览器缩写
" let l:browsers["ff"] = Firefox "Firefox浏览器缩写
" let l:browsers["op"] = Opera "Opera浏览器缩写
" let l:browsers["ay"] = Maxthon "遨游浏览器缩写
"let l:browsers["ie"] = SystemIE "系统IE浏览器缩写
" let l:browsers["ie6"] = IETester."-ie6" "调用IETESTER工具以IE6预览缩写(变量加参数)
" let l:browsers["ie7"] = IETester."-ie7" "调用IETESTER工具以IE7预览缩写(变量加参数)
" let l:browsers["ie8"] = IETester."-ie8" "调用IETESTER工具以IE8预览缩写(变量加参数)
" let l:browsers["ie9"] = IETester."-ie9" "调用IETESTER工具以IE9预览缩写(变量加参数)
" let l:browsers["ie10"] = IETester."-ie10" "调用IETESTER工具以IE10预览缩写(变量加参数)
" let l:browsers["iea"] = IETester."-al" "调用IETESTER工具以支持的所有IE版本预览缩写(变量加参数)
if stridx(file, www) == -1 "文件不在本地虚拟服务器目录,则直接预览(但不能解析PHP文件)
exec ":silent !start ". l:browsers[a:name] ." file://". file
else "文件在本地虚拟服务器目录,则调用本地虚拟服务器解析预览(先启动本地虚拟服务器)
let file = substitute(file, www, "http://".url."/", "g") "转换文件路径为虚拟服务器网址路径
exec ":silent !start ". l:browsers[a:name] file
endif
else
echohl WarningMsg | echo " please choose the correct source file"
endif
endfunction
" -----------------------------------------------------------------------------
" < vimtweak 工具配置 > 请确保以已装了工具, 这里只用于窗口透明与置顶
" -----------------------------------------------------------------------------
" 常规模式下 Ctrl + Up(上方向键) 增加不透明度,Ctrl + Down(下方向键) 减少不透明度,<Leader>t 窗口置顶与否切换
Bundle 'VimTweak'
if (g:iswindows && g:isGUI)
let g:Current_Alpha = 255
let g:Top_Most = 0
func! Alpha_add()
let g:Current_Alpha = g:Current_Alpha + 10
if g:Current_Alpha > 255
let g:Current_Alpha = 255
endif
call libcallnr("vimtweak.dll","SetAlpha",g:Current_Alpha)
endfunc
func! Alpha_sub()
let g:Current_Alpha = g:Current_Alpha - 10
if g:Current_Alpha < 155
let g:Current_Alpha = 155
endif
call libcallnr("vimtweak.dll","SetAlpha",g:Current_Alpha)
endfunc
func! Top_window()
if g:Top_Most == 0
call libcallnr("vimtweak.dll","EnableTopMost",1)
let g:Top_Most = 1
else
call libcallnr("vimtweak.dll","EnableTopMost",0)
let g:Top_Most = 0
endif
endfunc
"快捷键设置
nmap <c-up> :call alpha_add()<cr>
nmap <c-down> :call alpha_sub()<cr>
nmap <leader>t :call top_window()<cr>
endif
"===========================================================
"多行编辑vim-multipe-cursors
"===========================================================
Bundle 'vim-multiple-cursors'
部分功能只是安装了,但是有些还是不会用,我会慢慢地补充,以后要逐渐转向这个神级编辑器了!