Fork me on GitHub

Windows 下gvim的_vimrc 文件

" 基本配置
"
" 设置行号
set number
" 语法高亮。自动识别代码,使用多种颜色表示
syntax enable
" 选择颜色主题(已经下载好并放到$VIM/vim82/colors文件夹下) ,推荐自行下载使用solarized主题
colorscheme badwolf
" 设置gvim的字体
set guifont=Consolas:h12
" 设置gvim下和外部的复制粘贴
vmap <C-c> "+y
vmap <C-x> "+c
vmap <C-v> c<ESC>"+p
imap <C-v> <C-r><C-o>+
" 支持使用鼠标
set mouse=a
" 按下回车键后,下一行的缩进会自动跟上一行的缩进保持一致
set autoindent
" 按下Tab键后,vim显示的空格数
set tabstop=4
" normal模式下,>>增加一级缩进、<<取消一级缩进、==取消全部缩进时,每一级缩进的空格数
set shiftwidth=4
" 自动将Tab转为空格(防止Tab键在不同编辑器缩进不一致导致问题)
set expandtab
" Tab转为多少个空格
set softtabstop=4
" 光标所在行高亮
set cursorline
highlight CursorLine cterm=NONE ctermbg=black guibg=NONE guifg=NONE
" 关闭自动折行
set nowrap
" 垂直滚动时,光标距离顶部/底部的距离(单位:行)
set scrolloff=5
" 水平滚动时,光标距离行首或行尾的距离(单位:字符)
set sidescrolloff=30
" 设置行宽,即一行显示多少字符
set textwidth=1000
" 是否显示状态栏:0表示不显示,1表示只在多窗口显示,2表示显示
set laststatus=2
" 设置状态条显示的信息:文件名、光标所在字符的ASCII码、光标所在字符的ASCII码的十六进制、光标所在的位置、光标所在行之上的内容占整个文件的百分比、文件总行数
set statusline=\ %F%m%r%h%w\ \ \ \ ASCII=\%03.3b\ \ \ \ HEX=\%02.2B\ \ \ \ POS=%04l,%04v\ \ \ \ %p%%\ \ \ \ NumOfLine=%L
" 显示行尾的空格
highlight WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s\+$/
" 光标遇到括号时,自动高亮对应的另一半括号
set showmatch
" 命令行模式下,在底部显示当前键入的指令。例如键入dd删除一行时,键入第一个d,底部右侧显示d,完全键入dd时,操作完成,底部显示消失
set showcmd
" 搜索时,高亮显示搜索结果
set hlsearch
" 搜索时,每输入一个字符,自动跳到第一个匹配的结果
set incsearch
" 搜索时忽略大小写
set ignorecase
" 不创建交换文件
set noswapfile
" 保留 撤销 操作历史
set undofile
" 设置操作历史文件的保存位置
set undodir=$VIM\.undo
" vim需要记住多少次历史操作
set history=10000
" 命令模式下,底部操作指令按下 Tab 键自动补全。第一次按下 Tab,会显示所有匹配的操作指令的清单;第二次按下 Tab,会依次选择各个指令
set wildmenu
set wildmode=longest:list,full
" 定义F1快捷键为切换vim窗口
map &ltF1&gt &ltC-w&gtw
"设置文件的代码形式 utf8
set encoding=utf-8
set termencoding=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,chinese,cp936

" Python3
set pythonthreehome=C:\Users\Renhai\AppData\Local\Programs\Python\Python39\
set pythonthreedll=C:\Users\Renhai\AppData\Local\Programs\Python\Python39\python39.dll

set nocompatible " 去除VI一致性,必须
filetype off " 必须
" 插件管理
set rtp+=D:\Vim\vim82\bundle\Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'airblade/vim-gitgutter'
Plugin 'jiangmiao/auto-pairs'
Plugin 'tpope/vim-surround'
Plugin 'scrooloose/nerdcommenter'
Plugin 'scrooloose/nerdtree'
Plugin 'jistr/vim-nerdtree-tabs'
Plugin 'Xuyuanp/nerdtree-git-plugin'
Plugin 'zxqfl/tabnine-vim'
Plugin 'Valloric/YouCompleteMe'
Plugin 'preservim/tagbar'
Plugin 'haya14busa/incsearch.vim'
Plugin 'rdnetto/YCM-Generator'
call vundle#end()

" 各种插件的配置
"
" 分屏窗口移动
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-h> <c-w>h
nnoremap <c-l> <c-w>l

" tagbar
let g:tagbar_width = 30
nnoremap <silent> <leader>t :TagbarToggle<cr>

" incsearch.vim
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)

" NERD Commenter配置
" 将leader从"\"改为","
let mapleader = ","
" 在注释符后面自动添加空格
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'
" Allow commenting 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
"
"
" NERDTree配置
" 将F2设置为开关NERDTree的快捷键
map <leader>n :NERDTreeToggle<cr>
" 修改树的显示图标
" let g:NERDTreeDirArrowExpandable = '+'
" let g:NERDTreeDirArrowCollapsible = '-'
" 打开vim时如果没有文件自动打开NERDTree
" autocmd vimenter * if !argc()|NERDTree|endif
" 当NERDTree为剩下的唯一窗口时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
"
"
" nerdtree-git-plugin配置
let g:NERDTreeGitStatusIndicatorMapCustom= {
\ "Modified" : "✹",
\ "Staged" : "✚",
\ "Untracked" : "✭",
\ "Renamed" : "➜",
\ "Unmerged" : "═",
\ "Deleted" : "✖",
\ "Dirty" : "✗",
\ "Clean" : "✔︎",
\ 'Ignored' : '☒',
\ "Unknown" : "?"
\ }

" YCM
"YCM 自动补全设置
"let g:ycm_key_invoke_completion = '<c-z>'
set completeopt-=preview "关闭preview窗口
"启用基于语义的自动补全
"let g:ycm_collect_identifiers_from_tags_files=1 " 开启 YCM 基于标签引擎
let g:ycm_error_symbol = '✗'
let g:ycm_warning_symbol = '⚠'
let g:ycm_semantic_triggers = {
\ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],
\ 'cs,lua,javascript': ['re!\w{2}']
\ }
"设置白名单文件
let g:ycm_filetype_whitelist = {
\ "c":1,
\ "cpp":1,
\ "sh":1,
\ "py":1
\ }
"修改提示框颜色
"highlight Pmenu ctermfg=4 ctermbg=8 guifg=#ffffff guibg=#000000 "提示不再是粉红色(pink)
highlight PMenu ctermfg=yellow ctermbg=darkgrey guifg=#ffffff guibg=#000000
highlight PMenuSel ctermfg=white ctermbg=black guifg=#000000 guibg=#ffffff
"声明、定义跳转
nnoremap <leader>u :YcmCompleter GoToDefinitionElseDeclaration<CR>
nnoremap <leader>i :YcmForceCompileAndDiagnostics<CR>
"YCM-Generator配置
nnoremap <leader>y :YcmGenerateConfig ./<CR> "更新.ycm_extra_conf.py文件


" 重新加载vimrc文件
nnoremap <leader>s :source $MYVIMRC<cr>

" 安装、更新、删除插件
nnoremap <leader><leader>i :PlugInstall<cr>
nnoremap <leader><leader>u :PlugUpdate<cr>
nnoremap <leader><leader>c :PlugClean<cr>

" 复制当前选中到系统剪切板
vmap <leader><leader>y "+y

" 将系统剪切板内容粘贴到vim
nnoremap <leader><leader>p "+p

 

 

 

同时要想建议使用python3.9,会避免很多YouCompleteMe的问题,同时一定要使用32位的python在编译YouCompleteMe,不然。。。

posted @ 2022-06-19 23:04  kean0048  阅读(281)  评论(0编辑  收藏  举报