Python与C的GVIM配置,Windows、Gvim8.2
安装配置文件中的插件:将Plug.vim放在.\vim82\autoload文件夹中,再进入Gvim,运行PlugInstall后重启。设置的插件安装位置D:/Program/vim/plugged
可自由修改。
let &pythonthreedll = 'D:/Program/Anaconda3/python38.dll'
set confirm " 在处理未保存或只读文件的时候,弹出确认
set history=100 " 历史记录数
set fillchars=vert:\ ,stl:\ ,stlnc:\ " 在被分割的窗口间显示空白,便于阅读
"set helplang=cn " 显示中文帮助
"set viminfo+=! " 保存全局变量
"----------------编码设置---------------------"
set encoding=utf-8 "Vim 在与屏幕/键盘交互时使用的编码(取决于实际的终端的设定)
set fileencodings=utf-8,cp936,gb2123,chinese,ucs-bom
set fileencoding=utf-8
source $VIMRUNTIME/delmenu.vim "解决菜单乱码
source $VIMRUNTIME/menu.vim
language messages zh_CN.utf-8 "解决consle输出乱码
"----------------插件-------------------------"
call plug#begin('D:/Program/vim/plugged')
Plug 'junegunn/vim-easy-align'
Plug 'scrooloose/nerdcommenter' "注释
Plug 'junegunn/vim-easy-align' "对齐
Plug 'dense-analysis/ale' "语法检查
Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() } } "markdownpreview
Plug 'vim-airline/vim-airline' "状态栏
Plug 'vim-airline/vim-airline-themes'
Plug 'rakr/vim-one' "语法高亮
Plug 'joshdick/onedark.vim'
Plug 'preservim/nerdtree',{'on':'NERDTreeFind'} "文件树
Plug 'lervag/vimtex',{'for':'tex'} "latex
Plug 'honza/vim-snippets' "代码片段
Plug 'Yggdroot/indentLine' "代码缩进参考线
Plug 'yianwillis/vimcdoc' "中文帮助文档
Plug 'sbdchd/neoformat' "格式化
"Plug 'neoclide/coc.nvim', {'branch': 'release'} "补全
"Plug 'Shougo/neocomplcache.vim'
call plug#end()
let g:plugged#enable_at_startup = 1
let g:acp_enableAtStartup = 0
"let g:neocomplcache_enable_at_startup = 1 " 作用:在系统启动的时候启动neo
"let g:neocomplcache_enable_auto_select = 1 "作用:提示的时候默认选择地一个,如果设置为0,每次输入都需要用上下键选择
"-----------vim自身设置----------------------"
set magic " 设置魔术
set mouse=a " 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set scrolloff=5 " 在光标接近底端或顶端时,自动下滚或上滚
set autochdir " 自动设置当前目录为正在编辑的目录
filetype on " 侦测文件类型
filetype indent on " 针对不同的文件类型采用不同的缩进格式
filetype plugin on " 针对不同的文件类型加载对应的插件
filetype plugin indent on
set nobackup " 备份与缓存,禁止生成临时文件
set autoread " 当文件在外部被修改,自动更新该文件
set completeopt=longest,menu
"set novb " 取消响铃
set vb t_vb="<Esc>|0f"
au GuiEnter * set t_vb=
set backspace=2 " 使回格键(backspace)正常处理indent, eol, start等
set whichwrap+=<,>,h,l " 允许backspace和光标键跨越行边界
set nocompatible " 不要使用vi的键盘模式,而是vim自己的
set noswapfile
set nowritebackup
set noundofile
set softtabstop=4 " 统一缩进为4
set shiftwidth=4
set noexpandtab " 不要用空格代替制表符
set tabstop=4
set autoindent " 设置自动缩进.智能缩进
set smarttab " 在行和段开始处使用制表符
set cindent
set smartindent " 为C程序提供自动缩进
set hlsearch " 开启高亮显示结果
set incsearch " 显示查找匹配过程
set cursorline " 高亮显示当前
set showmatch " 高亮显示匹配的括号
"set gdefault " 行内替换
set number " 显示行号
"set relativenumber " 相对行号
set selection=exclusive
set selectmode=mouse,key
set wrap " 自动换行
set linebreak " 整词换行,与自动换行搭配使用
set iskeyword+=_,$,@,%,#,- " 带有如下符号的单词不要被换行分割
set clipboard+=unnamed " Vim 的默认寄存器和系统剪贴板共享
set foldenable " 允许折叠
set foldmethod=manual " 手动折叠
"set wildmenu " 增强模式中的命令行自动完成操作
"set linespace=0 " 字符间插入的像素行数目
autocmd FileType c map <buffer> <leader><space> :w<cr>:make<cr> " quickfix模式
"---------------------------gui设置-------------------------------"
syntax enable
set syntax=on " 语法高亮
set background=dark " for the light version
let g:one_allow_italics = 1 " I love italic for comments
colorscheme one
set showtabline=2 " 总是显示标签栏
set showcmd " 状态栏显示目前所执行的指令
set laststatus=2 " 开启状态栏信息
set cmdheight=1 " 命令行的高度
"set guifont=Consolas\ NF:h14 " gui字体"
set guifont=楷体:h14
"oiset guioptions-=T " 不显示工具栏
"set guioptions-=m " 不显示菜单栏
set guioptions-=L " 左边滚动条
set guioptions-=r " 右边滚动条
set guioptions-=b " 底部滚动条
set guioptions-=e " 使用内置 tab 样式而不是 gui
let g:airline_powerline_fonts = 1 " 关于状态栏的配置
" 缺省自动匹配主题
let g:airline_theme='one'
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
"------------自动匹配括号---------------------"
inoremap ( ()<Esc>i
inoremap [ []<Esc>i
inoremap { {}<Esc>i
autocmd Syntax html,vim inoremap < <lt>><Esc>i| inoremap > <c-r>=ClosePair('>')<CR>
inoremap ) <c-r>=ClosePair(')')<CR>
inoremap ] <c-r>=ClosePair(']')<CR>
inoremap } <c-r>=CloseBracket()<CR>
inoremap " <c-r>=QuoteDelim('"')<CR>
inoremap ' <c-r>=QuoteDelim("'")<CR>
function ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf
function CloseBracket()
if match(getline(line('.') + 1), '\s*}') < 0
return "\<CR>}"
else
return "\<Esc>j0f}a"
endif
endf
function QuoteDelim(char)
let line = getline('.')
let col = col('.')
if line[col - 2] == "\\"
return a:char
elseif line[col - 1] == a:char
return "\<Right>"
else
return a:char.a:char."\<Esc>i"
endif
endf
"------新建文件,自动插入文件头 -----------"
autocmd BufNewFile *.py exec ":call SetTitle()"
" 加入注释
func SetTitle()
call append(line(".")," #-*- coding: utf-8 -*-")
call append(line(".")+1, "''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''")
call append(line(".")+2, " Copyright (C) ".strftime("%Y")." Sangfor Ltd. All rights reserved.")
call append(line(".")+3, "")
call append(line(".")+4, " 文件名称:".expand("%:t"))
call append(line(".")+5, " 创 建 者:LittleTree")
call append(line(".")+6, " 创建日期:".strftime("%Y年%m月%d日"))
call append(line(".")+7, " 描 述:")
call append(line(".")+8, "''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''")
call append(line(".")+9, "")
endfunc
"----------------键盘命令-------------------"
let mapleader="\\" "Leader 快捷键
nmap <leader>v :tabnew<cr>:e $HOME/vimfiles/vimrc<cr>
nmap <leader>c :tabnew<cr>:e $HOME/vimfiles/coc-settings.json<cr>
nmap <leader>fp :let @+=expand('%')<cr>
"切换buff"
nmap <leader>t :tabnew<cr>
nmap <leader>bn :bn<cr>
nmap <leader>w :w!<cr>
nmap <leader>f :find<cr>
map <C-s> :w<CR>
imap <C-s> <ESC>:w<CR>a
vmap <C-s> <ESC>:w<CR>
nmap <leader>w :w<cr>
imap <leader>w <ESC>:w<cr>a
map <C-A> ggVGY " 映射全选+复制 ctrl+a
map! <C-A> <Esc>ggVGY
map <F12> gg=G
vmap <C-c> "+y " 选中状态下 Ctrl+c 复制
nnoremap <F2> :g/^\s*$/d<CR> " 去空行
nnoremap <C-F2> :vert diffsplit " 比较文件
map <M-F2> :tabnew<CR> " 新建标签
map <F3> :tabnew .<CR> " 列出当前目录文件
map <C-F3> \be " 打开树状文件目录
set report=0 " 通过使用: commands命令,显示文件的哪一行被改过
" ---------------------编译、运行-------------------------"
func! RunResult() " 运行可执行文件
exec "w"
if &filetype == "c"
"exec "!g++ % -o %<"
exec "!start cmd /c \"\"%<.exe\" & pause & del *.exe\""
"exec "!%<"
elseif &filetype == "py"
"exec "!start cmd /c \"python %<.py & pause\"
exec "!python %"
exec "!python %<"
elseif &filetype == "markdown"
exec "MarkdownPreview"
endif
endfunc
" Ctrl + b 一键保存、编译、运行
map <C-b> :call RunResult()<CR>
imap <C-b> <ESC>:call RunResult()<CR>
vmap <C-b> <ESC>:call RunResult()<CR>
"C,C++的调试
map <F8> :call Rungdb()<CR>
func! Rungdb()
exec "w"
exec "!g++ % -g -o %<"
exec "!gdb %<"
endfunc
"--------------NERDtee设定-------------"
let NERDChristmasTree=1
let NERDTreeAutoCenter=1
let NERDTreeBookmarksFile=$VIM.'\Data\NerdBookmarks.txt'
let NERDTreeMouseMode=2
" 显示书签列表
let NERDTreeShowBookmarks=1
let NERDTreeShowFiles=1
" 是否显示隐藏文件
let NERDTreeShowHidden=1
" 显示行号
let NERDTreeShowLineNumbers=1
let NERDTreeWinPos='left'
let NERDTreeWinSize=31
nnoremap f :NERDTreeToggle
map <F7> :NERDTree<CR>