Skip to content

Instantly share code, notes, and snippets.

@cnnewjohn
Last active August 29, 2015 14:08
Show Gist options
  • Save cnnewjohn/47c7eee1573551e0603f to your computer and use it in GitHub Desktop.
Save cnnewjohn/47c7eee1573551e0603f to your computer and use it in GitHub Desktop.
VIM config file
"======================================================================
" Vimrc by Chuyinfeng.com
"======================================================================
"----------------------------------------------------------------------
" Encoding
"----------------------------------------------------------------------
" fenc(fileencoding) 当前文件编码,set fenc=utf-8 存为utf-8编码
" fencs(fileencodings) 猜测打开文件的解码 set fenc? 查看当前选择
" enc(encoding) 转为env编码来显示,win默认cp936, linux随locale
" linux console
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set fileencodings=utf-8,ucs-bom,cp936,chinese,latin-1
set fileencoding=utf-8
language messages zh_CN.utf-8
" win
if has("win32")
"set fileencoding=chinese
"解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
endif
" 显示中文帮助
if version >= 603
set helplang=cn
set encoding=utf-8
endif
"----------------------------------------------------------------------
" Display
"----------------------------------------------------------------------
set nu " 显示行号
set ruler " 显示标尺
set cursorline " 突出显示当前行
set magic " 设置魔术
set guioptions-=T " 隐藏工具栏
set guioptions-=m " 隐藏菜单栏
set cuc " 高亮当前列
set colorcolumn=81 " 81列红线
set showcmd " 显示输入命令
set laststatus=2 " 启动显示状态行(1),总是显示状态行(2)
set cmdheight=2 " 命令行高度
"状态行显示的内容
set statusline=%F%m%r%h%w\ [%{&ff}]\%{\"[\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\",B\":\"\").\"]\"}\[%Y]\ [%l,%v][%p%%]\ %{strftime(\"%Y-%m-%d\ \%H:%M:%S\")}
"set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\
"set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
"set statusline=[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%]
" GUI
if has("gui_running")
set go= " 不要图形按钮
endif
"----------------------------------------------------------------------
" Color and Font
"----------------------------------------------------------------------
colorscheme desert " 配色方案
set guifont=Courier_new:h10:b:cDEFAULT " 设置字体
autocmd InsertLeave * se nocul " 用浅色高亮当前行
autocmd InsertEnter * se cul " 用浅色高亮当前行
"----------------------------------------------------------------------
" syntax
"----------------------------------------------------------------------
syntax on " 语法高亮
" 折叠
set foldenable " 允许折叠
set foldmethod=manual " manual 手动折叠 indent 自动折叠
set foldcolumn=0
set foldmethod=indent
" 自动缩进
set autoindent
set cindent
set smartindent " 智能缩进
" Tab键的宽度
set tabstop=4
" 统一缩进为4
set softtabstop=4
set shiftwidth=4
" 用空格代替制表符
set expandtab
" 在行和段开始处使用制表符
set smarttab
filetype plugin indent on
"打开文件类型检测, 加了这句才可以用智能补全
set completeopt=longest,menu
" 侦测文件类型
filetype on
" 载入文件类型插件
filetype plugin on
" 为特定文件类型载入相关缩进文件
filetype indent on
" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set mouse=a
set selection=exclusive
set selectmode=mouse,key
" 高亮显示匹配的括号
set showmatch
" 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=1
" 光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=3
"自动补全
":inoremap ( ()<ESC>i
":inoremap ) <c-r>=ClosePair(')')<CR>
":inoremap { {<CR>}<ESC>O
":inoremap } <c-r>=ClosePair('}')<CR>
":inoremap [ []<ESC>i
":inoremap ] <c-r>=ClosePair(']')<CR>
":inoremap " ""<ESC>i
":inoremap ' ''<ESC>i
"function! ClosePair(char)
" if getline('.')[col('.') - 1] == a:char
" return "\<Right>"
" else
" return a:char
" endif
"endfunction
"----------------------------------------------------------------------
" Other
"----------------------------------------------------------------------
set nocompatible "取消vi一致性
set completeopt=preview,menu "代码补全
filetype plugin on "允许插件
set clipboard+=unnamed "共享剪贴板
set autowrite "自动保存
set confirm " 在处理未保存或只读文件的时候,弹出确认
set history=1000 " 历史记录数
"搜索忽略大小写
set ignorecase
"搜索逐字符高亮
set hlsearch
set incsearch
" 保存全局变量
set viminfo+=!
" 带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-
" 字符间插入的像素行数目
set linespace=0
" 增强模式中的命令行自动完成操作
set wildmenu
" 使回格键(backspace)正常处理indent, eol, start等
set backspace=2
" 允许backspace和光标键跨越行边界
set whichwrap+=<,>,h,l
" 不生成备份
set nobackup
autocmd! bufwritepost _vimrc source % " 自动加载配置文件
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment