介绍一下 Vim 在 Windows 平台的安装。
1) 下载并安装最新版 Git. https://git-scm.com/download/win
2) 下载并安装最新版 Vim. https://www.vim.org/download.php
3) 安装喜欢的字体(需要等宽字体,可分别设置中文和英文字体)。
4) 下载 plug.vim 插件管理器。https://github.com/junegunn/vim-plug
5) 把文件 plug.vim 放到 Vim 安装目录下 autoload 文件夹。
6) 用自己的配置文件替换 Vim 安装目录下的默认配置文件 _vimrc.
7) 打开 Vim 并安装配置文件中选用的插件。命令 :PlugInstall
注意事项:
- 字体推荐同时支持中文和英文的等宽字体 Sarasa Mono SC (更纱黑体).
https://github.com/be5invis/Sarasa-Gothic/releases
下载的字体包中有很多字体,等宽简体中文只需要安装:sarasa-mono-sc-regular.ttf
_vimrc 中配置方法如下:" Font Sarasa Mono SC
set guifont=Sarasa\ Mono\ SC:h16
set guifontwide=Sarasa\ Mono\ SC:h16 - 插件可以使用镜像网站,这样国内下载起来比较方便。
" from gitclone
Plug 'https://gitclone.com/github.com/morhetz/gruvbox'
给一个简化版的我的配置文件 _vimrc 供参考。可自行修改调整。
" Vim with all enhancements
source $VIMRUNTIME/vimrc_example.vim
" Personal settings
" winpos 800 150 " set the default location of GVIM window
" Font Sarasa Mono SC
set guifont=Sarasa\ Mono\ SC:h16
set guifontwide=Sarasa\ Mono\ SC:h16
set columns=120
set textwidth=120 " gq will use it when formating the lines
set lines=39
set fo+=mM " auto break and gq will work for multibyte character
set encoding=utf-8
set termencoding=utf-8
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936,latin1
set shiftwidth=4
set tabstop=4
set expandtab
set nowrap
set ic
set nofoldenable
" set number
" set cursorline
" set ruler
" y will use * or + register instead of " register
set clipboard=unnamed
" Needed for vimwiki
" set nocompatible
" filetype plugin on
" syntax on
" Override filetype plugin settings after filetype plugin on
" autocmd FileType vimwiki,text setlocal textwidth=120 fo+=mM
" Set the menu and the message to English
set langmenu=en_US
let $LANG='en_US'
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
" :set guioptions -=m " remove menu
:set guioptions -=T " remove toolbar
:set guioptions -=r " remove right scroll bar
" Use the internal diff if available.
" Otherwise use the special 'diffexpr' for Windows.
if &diffopt !~# 'internal'
set diffexpr=MyDiff()
endif
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg1 = substitute(arg1, '!', '\!', 'g')
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg2 = substitute(arg2, '!', '\!', 'g')
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let arg3 = substitute(arg3, '!', '\!', 'g')
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
if empty(&shellxquote)
let l:shxq_sav = ''
set shellxquote&
endif
let cmd = '"' . $VIMRUNTIME . '\diff"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
let cmd = substitute(cmd, '!', '\!', 'g')
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
if exists('l:shxq_sav')
let &shellxquote=l:shxq_sav
endif
endfunction
fun! s:ToggleGuiOption(option)
" If a:option is already set in guioptions, then we want to remove it
if match(&guioptions, "\\C" . a:option) > -1
exec "set go-=" . a:option
else
exec "set go+=" . a:option
endif
endfun
fun! s:ToggleBackgroud()
if &background ==# 'light'
exec "set bg=dark"
else
exec "set bg=light"
endif
endfun
fun! s:ToggleSpell()
if &spell ==# 0
exec "set spell"
else
exec "set nospell"
endif
endfun
call plug#begin('~/.vim/plugged')
" Plug 'morhetz/gruvbox'
" You may download plugins from gitclone without a VPN
" But the versions may not be the latest
Plug 'https://gitclone.com/github.com/morhetz/gruvbox'
Plug 'https://gitclone.com/github.com/vim-airline/vim-airline'
Plug 'https://gitclone.com/github.com/scrooloose/nerdtree'
Plug 'https://gitclone.com/github.com/tyru/open-browser.vim'
Plug 'https://gitclone.com/github.com/tpope/vim-surround'
Plug 'https://gitclone.com/github.com/tommcdo/vim-exchange'
Plug 'https://gitclone.com/github.com/tpope/vim-commentary'
Plug 'https://gitclone.com/github.com/mattesgroeger/vim-bookmarks'
Plug 'https://gitclone.com/github.com/thinca/vim-fontzoom'
" Plug 'https://gitclone.com/github.com/itchyny/calendar.vim'
" Plug 'https://gitclone.com/github.com/vimwiki/vimwiki'
" Plug 'https://gitclone.com/github.com/nathangrigg/vim-beancount'
" Plug 'https://gitclone.com/github.com/hotoo/pangu.vim'
" Plug 'https://gitclone.com/github.com/rking/ag.vim'
" Plug 'https://gitclone.com/github.com/tpope/vim-fugitive'
call plug#end()
" Gruvbox setting must be after loading the plugin
colorscheme gruvbox
" set background=light
set background=dark
" contrast can be soft, medium and hard
let g:gruvbox_contrast_dark='medium'
let g:gruvbox_contrast_light='medium'
let NERDTreeShowBookmarks = 1
let NERDTreeBookmarksSort = 0
let g:fontzoom_no_default_key_mappings = 1
let g:netrw_nogx = 1
let g:airline_theme = "gruvbox"
let g:bookmark_sign = '♥'
" let g:ag_prg = "ag --vimgrep --smart-case"
" let g:ag_highlight = 1
" let g:calendar_first_day = "sunday"
" let g:calendar_date_endian = "big"
" let g:calendar_date_separator = "-"
" let g:calendar_cache_directory = 'D:/Calendar'
" let g:vimwiki_list = [{'path': 'D:/Wiki',
" \'path_html': 'D:/Wiki/html',
" \'diary_rel_path': 'TODO/',
" \'diary_index': 'todo',
" \'auto_export': 1}]
" let g:vimwiki_folding ='list:quick'
" ca Ag Ag!
" ;; - synonym of ESC
:imap ;; <ESC>
" x - execute
:nmap gx <Plug>(openbrowser-smart-search)
" Vimwiki
" :nmap gl<Space> <Plug>VimwikiToggleListItem
" :vmap gl<Space> <Plug>VimwikiToggleListItem
" F2 ~ F12
:nmap <F2> :call <SID>ToggleSpell()<CR>
:nmap <F3> :set nu!<CR>
:nmap <F4> :call <SID>ToggleGuiOption("r")<CR>
:nmap <F5> "=strftime('%F')<CR>p
:nmap <F6> :bro ol<CR>
:nmap <F7> :diffthis<CR>
" :nmap <F8> :Calendar<CR>
:nmap <F9> :NERDTreeFind %<CR>
:nmap <F10> :Bookmark<CR>
:nmap <F11> :NERDTreeMirror<CR>
:nmap <F12> :NERDTree<CR>
" Same shortcut keys for zoom-in/out/reset in Chrome
:nmap <C-=> :Fontzoom +1<CR>
:nmap <C--> :Fontzoom -1<CR>
:nmap <C-0> :Fontzoom!<CR>
" Dark
:nmap <A-S-D> :call <SID>ToggleBackgroud()<CR>
" Redir
:nmap <A-S-R> :redir @+<CR>
" Cancel - END
:nmap <A-S-C> :redir END<CR>
" Name
:nmap <A-S-N> :let @+=@%<CR>
" Path
:nmap <A-S-P> :let @+=expand('%:p')<CR>
" O looks like the period in Chinese punctuation
" :nmap <A-S-O> :Pangu<CR>
" :vmap <A-S-O> :Pangu<CR>
" Unify
" :nmap <A-S-U> :AlignCommodity<CR>
" :vmap <A-S-U> :AlignCommodity<CR>
效果图:
