win10 gvim

前言

现有的vscode太过于繁重,notepad++也不理想,顿来心思,想在win10配置一个gvim环境。

正文

  1. 安装gvim,从releases中找一个x64的.exe下载安装即可,安装完毕,把 gvim.exe 所在文件夹路径添加到系统用户变量;

  2. 安装ctags58.zip
    解压后配置 ctags.exe 所在文件夹路径添加到系统用户环境变量;

  3. 打开powershell,输入vim,进入到vim界面。输入":"调出vim命令行,输入:echo $MYVIMRC,可以看到打印出配置文件"_vimrc"所在路径,我的是:E:\vim_vimrc

  4. 新建插件文件夹,我把文件夹命名为 MyPlugs,为方便管理,路径放在了 E:\vim\MyPlugs

  5. 修改配置文件 _vimrc
    具体可参考博客:Vim使用全指南 (环境配置,插件推荐,美化) (C++,Python,MarkDown,R...)

现在把我目前配置的 _vimrc 记录一下:
其中下载插件时,用了两个加速的网址,https://gitclone.com/github.com/
https://ghproxy.com/
即使是自己git下载到插件文件夹的插件,如果不添加下载源,也会识别不出来,因此只能在插件中都带上下载的链接

" Vim with all enhancements
source $VIMRUNTIME/vimrc_example.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

" ------ 我的配置 ------
filetype plugin indent on " 启用根据文件类型自动缩进
set autoindent " 开始新行时处理缩进
set smartindent " 智能缩进
set expandtab " 将制表符 Tab 展开为空格
set tabstop=4 " 要计算的空格数
set shiftwidth=4 " 用于自动缩进的空格数
set backspace=indent,eol,start " 开启退格跨行退格
set backspace=2 " 在多数终端上修正退格键Backspace的行为
set nu " 开启行数显示
" set relativenumber " 显示相对行数
set wrap " 自动换行
set wildmenu " 输入命令的时候Tab显示提示
set mouse=a " 启用鼠标
set nobackup  " 备份与缓存
set hlsearch      " 开启高亮显示结果
exec "nohlsearch"
set incsearch   " 显示查找匹配过程
set cursorline  "高亮显示当前
set smartcase
set showmatch  " 高亮显示匹配的括号
filetype indent on          " 针对不同的文件类型采用不同的缩进格式
filetype plugin on          " 针对不同的文件类型加载对应的插件
filetype plugin indent on
filetype on                 
set autoread " 当文件在外部被修改,自动更新该文件
set clipboard+=unnamed  " Vim 的默认寄存器和系统剪贴板共享
" 在3种模式下用3种光标
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"


" --- gui ---
syntax enable 
syntax on " 支持语法高亮显示
set showtabline=2   " 总是显示标签栏
set showcmd   " 状态栏显示目前所执行的指令
set laststatus=2 " 开启状态栏信息
set cmdheight=1    " 命令行的高度
" colorscheme murphy " 修改配色
set guifont=Consolas:h12 " 设置字体
"不显示工具/菜单栏
set guioptions-=T "工具栏
"set guioptions-=m "菜单栏
set guioptions-=L "左边滚动条
set guioptions-=r "右边滚动条
set guioptions-=b " 底部滚动条
set guioptions-=e " 使用内置 tab 样式而不是 gui
" --- gui ---

" --- 编码配置 ---
set encoding=utf-8
set fileencodings=utf-8,cp936,gb2123
if has("win32")
	set fileencoding=utf-8
else
	set fileencoding=utf-8
endif
source $VIMRUNTIME/delmenu.vim  "解决菜单乱码
source $VIMRUNTIME/menu.vim
language messages zh_CN.utf-8  "解决consle输出乱码
" --- 编码配置 ---

" --- 环境配置 ---
let &pythonthreedll='C:\Python3\python38.dll'
let &pythonthreehome='C:\Python3'
" --- 环境配置 ---

" ------ 我的配置 ------

" ------ 插件 ------
call plug#begin('E:\vim\MyPlugs')
    Plug 'https://gitclone.com/github.com/scrooloose/nerdcommenter' "注释
    Plug 'https://ghproxy.com/https://github.com/clouduan/vim-searchme'
    Plug 'https://gitclone.com/github.com/jiangmiao/auto-pairs'
    Plug 'https://gitclone.com/github.com/junegunn/vim-easy-align'  "对齐
    Plug 'https://gitclone.com/github.com/iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() } }  "markdownpreview
    Plug 'https://gitclone.com/github.com/preservim/nerdtree' "目录树
    Plug 'https://gitclone.com/github.com/majutsushi/tagbar' "标签侧边栏
    Plug 'https://ghproxy.com/https://github.com/neoclide/coc.nvim', {'branch': 'release'}  "补全
    Plug 'https://ghproxy.com/https://github.com/vim-airline/vim-airline'
    Plug 'https://ghproxy.com/https://github.com/vim-airline/vim-airline-themes'
    Plug 'https://gitclone.com/github.com/joshdick/onedark.vim' " onedark主题
    Plug 'https://gitclone.com/github.com/ervandew/supertab' "Tab插件
    Plug 'https://gitclone.com/github.com/dense-analysis/ale' " 多语言代码查错
    Plug 'https://ghproxy.com/https://github.com/luochen1990/rainbow' " 彩虹花括号
call plug#end()
" ------ 插件 ------

" ------ 插件配置 ------
" let g:plugged#enable_at_startup = 1

" --- nerdtree 目录树快捷键 ---
map <C-n> :NERDTreeToggle<CR> " Ctrl+n快速开启目录树
" --- nerdtree 目录树快捷键 ---

" --- auto-pairs 自动补括号 ---
au Filetype FILETYPE let b:AutoPairs = {"(": ")"}
au FileType php      let b:AutoPairs = AutoPairsDefine({'<?' : '?>', '<?php': '?>'})
" --- auto-pairs 自动补括号 ---

" --- nerdcommenter 配置 ---
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims=1
 
" Use compact syntax for prettified multi-line comments
let g:NERDCompactSexyComs=1
 
" Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDDefaultAlign='left'
 
" Set a language to use its alternate delimiters by default
let g:NERDAltDelims_java=1
 
" Add your own custom formats or override the defaults
let g:NERDCustomDelimiters={'c':{'left':'/**','right':'*/'}}

" Allow cddommenting and inverting empty lines (useful when commenting a region)
let g:NERDCommentEmptyLines=1
 
" Enable trimming of trailing whitespace when uncommenting
let g:NERDTrimTrailingWhitespace=1
 
" Enable NERDCommenterToggle to check all selected lines is commented or not 
let g:NERDToggleCheckAllLines=1

map <C-m> <leader>cc
map <A-m> <leader>cu
unmap <CR>
" --- nerdcommenter 配置 ---

" --- 标签侧边栏 ---
nmap <F8> :TagbarToggle<CR>
" --- 标签侧边栏 ---

colorscheme onedark " 修改配色
" --- vim-airline-themes ---
"set ambiwidth=double  " 设置为双字宽显示,否则无法完整显示如:☆
let g:airline_powerline_fonts = 1  "关于状态栏的配置
" 缺省自动匹配主题
let g:airline_theme='onedark'
let g:airline#extensions#tabline#enabled = 1  " Air-line 显示上面的buffer tab
let g:airline#extensions#ale#enabled = 1
let g:airline#extensions#coc#enabled = 1 "coc
let g:airline#extensions#tabline#left_sep = ' '   "tabline中未激活buffer两端的分隔字符
let g:airline#extensions#tabline#left_alt_sep = '|'      "tabline中buffer显示编号
let g:airline#extensions#tabline#buffer_nr_show = 1
" --- vim-airline-themes ---

" --- ale ---
"始终开启标志列
let g:ale_sign_column_always = 1
let g:ale_set_highlights = 0
"自定义error和warning图标
let g:ale_sign_error = '❌'
let g:ale_sign_warning = '🔰'
"在vim自带的状态栏中整合ale
let g:ale_statusline_format = ['✗ %d', '⚡ %d', '✔ OK']
"显示Linter名称,出错或警告等相关信息
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
"普通模式下,sp前往上一个错误或警告,sn前往下一个错误或警告
nmap sp <Plug>(ale_previous_wrap)
nmap sn <Plug>(ale_next_wrap)
"<Leader>s触发/关闭语法检查
nmap <Leader>s :ALEToggle<CR>
"<Leader>d查看错误或警告的详细信息
nmap <Leader>d :ALEDetail<CR>
"set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}\ %{ALEGetStatusLine()}
"cpp NOT C++
let g:ale_linters = {
\   'cpp': ['gcc'],
\   'c': ['gcc'],
\   'python': ['pylint'],
\}

" --- ale ---

" --- rainbow ---
" 1. vscode defult 2. author defult 3. vscode show
"	\	'guifgs': ['#B21212', '#1B9CED','#FFFC00'],
"	\	'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
"	\	'guifgs': ['#C186BF', '#268EDB','#F79318'],
	let g:rainbow_conf = {
	\	'guifgs': ['#C186BF', '#268EDB','#F79318'],
	\	'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'],
	\	'operators': '_,_',
	\	'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
	\	'separately': {
	\		'*': {},
	\		'tex': {
	\			'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
	\		},
	\		'lisp': {
	\			'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'],
	\		},
	\		'vim': {
	\			'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
	\		},
	\		'html': {
	\			'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold'],
	\		},
	\		'css': 0,
	\	}
	\}
let g:rainbow_active = 1

" --- rainbow ---


" ------ 插件配置 ------



此外,如果想要配置git加速,可以修改 C:\Users\用户名.gitconfig,添加:

[url "https://gitclone.com/github.com/"]
    insteadOf = https://github.com/
;[url "https://ghproxy.com/https://github.com/"]
    ;insteadOf = https://github.com/
;[url "https://ghproxy.com/https://github.com/"]
    ;insteadOf = https://github.com/
; [url "https://ghproxy.com/https://raw.githubusercontent.com/"]
    ; insteadOf = https:///raw.githubusercontent.com/
; [url "https://github.com.cnpmjs.org/"]
    ; insteadOf = https://github.com/
posted @ 2022-08-09 18:02  BrianSun  阅读(315)  评论(0编辑  收藏  举报