" Configuration file for vim
set modelines=0 " CVE-2007-2438
" Normally we use vim-extensions. If you want true vi-compatibility
" remove change the following statements
set nocompatible " Use Vim defaults instead of 100% vi compatibility
set backspace=2 " more powerful backspacing
" Don’t write backup file if vim is being called by “crontab -e”
au BufWrite /private/tmp/crontab.* set nowritebackup nobackup
" Don’t write backup file if vim is being called by “chpass”
au BufWrite /private/etc/pw.* set nowritebackup nobackup
let skip_defaults_vim=1
" set by MuDaDa, chenguangyu@bilibili.com
" # ---------------------- Begin , Let’s config vim ----------------------
" make .vimrc file take effect immediatelty 让vimrc 文件保存立刻生效,这样方便我们立刻查看vim效果
autocmd BufWritePost $MYVIMRC source $MYVIMRC
" # Display line number 显示行号
set nu
" 语法高亮
syntax on
" 配置多语言环境
if has(“multi_byte”)
" UTF-8 编码
set encoding=utf-8
set termencoding=utf-8
set formatoptions+=mM
set fencs=utf-8,gbk
if v:lang =~? ‘^(zh)|(ja)|(ko)’
set ambiwidth=double
endif
if has(“win32”)
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
language messages zh_CN.utf-8
endif
else
echoerr “Sorry, this version of (g)vim was not compiled with +multi_byte”
endif
" # about saving and exiting files 关于保存和退出文件
" 设置当文件被改动时自动载入
set autoread
" ## set my own Leader 设置自己的“”
let mapleader=“,”
nmap w :w
nmap q :q!
" # set copy and paste
vnoremap y "+y
nmap p "+p
" # 跳转window
noremap h
noremap k
noremap j
noremap l
" 定义快捷键到行尾或者行首
nmap H ^
nmap L $
" 设置自动换行的字符数
set textwidth=100
" 快速跳转
nmap J 3j
nmap K 3k
" 文件类型检测,自动识别是.c, .cpp, .py …
filetype on
" 根据不同文件类型家在不同插件的功能
filetype plugin on
"开启实时搜索
set incsearch
" 开启大小写不敏感,方便搜索
set ignorecase
" 清除当前搜索内容的高亮
noremap :nohlsearch
" 开启vim自身命令行模式智能补全
set wildmenu
" 高亮显示对应的括号
set showmatch
" 自动对齐
set autoindent
" 在处理未保存或只读文件的时候,弹出确认
set confirm
" Tab键的宽度
set tabstop=4
" 统一缩进为4
set shiftwidth=4
" 在编辑模式的时候按退格键的时候退回缩进的长度
set softtabstop=4
" 当设置成 expandtab 时,缩进用空格来表示,noexpandtab 则是用制表符表示一个缩进
set expandtab
" 搜索高亮
set hlsearch
" 十字架高亮
" set cuc cul "简单设置十字架
" hi CursorColumn cterm=NONE ctermbg=darkyellow ctermfg=white guibg=darkred guifg=white " 配置简单十字架颜色
set bg=dark
set cursorline
set cursorcolumn
highlight CursorLine cterm=none ctermbg=236
highlight CursorColumn cterm=none ctermbg=236
" 搜索逐字符高亮
set incsearch
" quickfix模式
autocmd FileType c,cpp map :w:make
"代码补全
set completeopt=preview,menu
" 自动对齐
set autoindent
"关于编译
" 编译和运行C程序
map :call CompileRunGcc()
func! CompileRunGcc()
exec “w”
exec “!gcc % -o %<”
exec “! ./%<”
endfunc
" 编译和运行C++程序
map :call CompileRunGpp
func! CompileRunGpp()
exec “w”
exec “!g++ % -o %<”
exec “! ./<”
endfunc
map :call CompileRunAll()
func! CompileRunAll()
exec “w”
if &filetype == ‘c’
exec ‘!g++ % -o %<’
exec ‘!time ./%<’
elseif &filetype == ‘cpp’
exec ‘!g++ % -o %<’
exec ‘!time ./%<’
elseif &filetype == ‘python’
exec ‘!time python %’
elseif &filetype == ‘go’
exec ‘!time go run %’
elseif &filetype == ‘sh’
:!time bash %
endif
endfunc
" ---------------------- End , config vim ---------------------
"MuDaDaSettingVimrcVars
set nu
set hlsearch
set encoding=utf-8
set cuc cul
syntax on
hi CursorColumn cterm=NONE ctermbg=darkyellow ctermfg=white guibg=darkred guifg=white