用户 vimrc 文件: "$HOME/.vimrc"
" vimrc by [email protected] " last update 2013-10-29 " 判断操作系统 if (has("win32")||has("win64")||has("win32unix")) let g:isWin=1 else let g:isWin=0 endif " ---------------------------------------------------------- " 常用格式 " ---------------------------------------------------------- " 习惯用“:”作为命令前缀 " let mapleader="," " 快捷加载vimrc文件 " map <leader>ss :source $HOME/.vimrc<cr> " 快捷打开编辑vimrc文件 " map <silent> <leader>ee :e $HOME/.vimrc<cr> " autocmd! bufwritepost *.vimrc source $HOME/.vimrc " 设置行号 set nu " tab转化为4个字符 set expandtab set smarttab set shiftwidth=4 set tabstop=4 set softtabstop=4 " 恢复上次文件打开位置 " set viminfo='10,\"100,:20,%,n~/.viminfo if has("autocmd") autocmd BufReadPost * \ if line("'\"") > 0 | if line("'\"") <= line("$") | \ exe("norm '\"") | else|exe "norm $"| \ endif | endif endif " 关闭兼容模式 set nocompatible " 语法高亮 syntax enable " syntax off " 文件类型插件 filetype plugin on filetype indent on set autoindent autocmd BufEnter * :syntax sync fromstart " 显示命令 set showcmd " 高亮搜索 set hlsearch " 设置当前行高亮 set nocursorline " 不使用swp文件 set noswapfile " 设置记录历史条数 set history=200 " ---------------------------------------------------------- " 断行设置 " ---------------------------------------------------------- " 设置光标超过80时折行 " set tw=80 " 第80列往后加下划线 au BufWinEnter * let w:m2=matchadd('Underlined', '\%>' . 80 . 'v.\+', -1) " ---------------------------------------------------------- " C/C++ 编码设置 " ---------------------------------------------------------- " 设置VIM对文件类型敏感 filetype on " 设置c缩进风格 autocmd FileType c,cpp,h :setlocal cindent cinoptions=:0,g0,t0 " 设置一次缩进的距离是4个空格 autocmd FileType c,cpp,h :setlocal et sta sw=4 sts=4 tabstop=4 " 设置自动缩进 set autoindent " 设置智能缩进 set smartindent " 显示括号配对情况 set sm " 打开C/C++风格的自动缩进 "autocmd FileType c,cpp,cc " 设置注释格式 set cindent comments=sr:/*,mb:*,el:*/,:// set cin " 设置缩进风格 " t0 表示函数返回值与函数名不在同一行,0表示返回值前空一格 set cinoptions=>4,n-2,{4,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1 " ---------------------------------------------------------- " 状态条总是显示:字节数、列数、行数、当前行等信息 " ---------------------------------------------------------- set laststatus=2 set ruler set statusline=\ %{HasPaste()}%<%-15.25(%f%)%m%r%h\ %w\ \ set statusline+=\ \ \ [%{&ff}/%Y] set statusline+=\ \ \ %<%20.30(%{hostname()}:%{CurDir()}%)\ set statusline+=%=%-10.(%l,%c%V%)\ %p%%/%L function! CurDir() let curdir = substitute(getcwd(), $HOME, "~", "") return curdir endfunction function! HasPaste() if &paste return '[PASTE]' else return '' endif endfunction " ----------------------------------------------------------- " 设置字符集 " ----------------------------------------------------------- set encoding=utf8 set termencoding=utf8 set fileencoding=gb19030 set fileencodings=utf8,utf16,gb2312,gb18030,ucs-bom,big5,latin1 fun! ViewUTF8() set encoding=utf8 set termencoding=gb19030 endfun fun! UTF8() set encoding=utf8 set termencoding=utf8 set fileencoding=gb18030 set fileencodings=utf8,utf16,gb2312,gb18030,ucs-bom,big5,latin1 endfun