windows10安装配置vim82

31次阅读

共计 2640 个字符,预计需要花费 7 分钟才能阅读完成。

windows10 安装配置 vim8.2

安装 64 位 vim

当 python 安装的是 64 位,那么一定要下载和安装 64 位的 vim,因为有些插件会用到 python 的 dll,否者,可能会出现问题。现在大家的电脑应该都是 64 位了,建议大家统一 64 位。

64 位 vim windows 下载路径 https://github.com/vim/vim-win32-installer/releases
选择gvim_8.2***_x64.exe

64 位 python3.8

安装 vim,假设安装在 D:\Software\Vim\

下载 vim-plug 这个插件

https://github.com/junegunn/vim-plug/blob/master/plug.vim 保存到 ~\vimfiles\autoload\ 这个目录下,如果没有就先创建

修改 vim 配置文件,windows 下是~\_vimrc

" Vim with all enhancements
source $VIMRUNTIME/vimrc_example.vim
source ~\vimfiles\autoload\plug.vim

"之后通过 vim-plug 安装的插件就会安装到 `~\vimfiles\plugged` 这个目录下" vim-plug 的 README 上说,要避免使用 `plugin` 这个目录的名称,防止和 vim 标准的插件混淆
call plug#begin('~\vimfiles\plugged') 
" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'

" Any valid git URL is allowed
Plug 'https://github.com/junegunn/vim-github-dashboard.git'

" Multiple Plug commands can be written in a single line using | separators
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'

" On-demand loading
Plug 'scrooloose/nerdtree', {'on':  'NERDTreeToggle'}

" Using a non-master branch
Plug 'rdnetto/YCM-Generator', {'branch': 'stable'}

" markdown-preview
Plug 'iamcco/markdown-preview.nvim', {'do': 'cd app & yarn install'}

call plug#end()

" 设置配色方案
colorscheme morning
" 字体类型和大小
set guifont=Consolas:h12
set nu
set relativenumber

" 换行时,自动缩进 4 列; 使用 `<` 或者 `>` 缩进时,缩进 4 列
set shiftwidth=4 

set tabstop=4

" 把输入的 tab 字符替换空格,具体空格数,跟 tabstop 设置的值有关
expandtab

" 会影响到 Backspace 键删除多个空格和删除 tab 字符的行为
set softtabstop=4

set fileencodings=utf-8,chinese,latin-1
set encoding=utf-8
set belloff=all
syntax on
if has("win32")
set fileencoding=chinese
else
set fileencoding=utf-8
endif
" 解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"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

然后执行 :PlugInstall 安装这些插件, 过程有点慢,如果等不了,可以先把插件 download 下来,
直接放在 ~\vimfiles\plugged\ 这个目录下

后期再记录一些 vim 有用的一些技巧和插件

技巧 1

vim new_dir/new_file.md
当保存文件时,提示E212: Can't open file for writing

解决方法:

  • windows 下
    :!MD -p %:h
  • linux 下
    :!mkdir -p %:h

正文完
 0