一个比较成功的vim配置文件

创建或修改/root/.vimrc文件,常用的内容如下:


" Windows兼容 " 启用C-C,V,X "if has("gui_running") source $VIMRUNTIME/mswin.vim "endif behave mswin " 关闭VI兼容模式 set nocompatible filetype plugin indent on set modeline "set modelines=2 " 缩写 iab xdate =strftime("%Y-%m-%y") iab xdate1 =strftime("%Y-%m-%y %H:%M:%S") iab xname xue.f zhao " 打开文件后跳转到最后已知的文件位置,见帮助 au BufReadPost * if line("'\"") > 0|if line("'\"") " 自动进入二进制模式 augroup Binary au! au BufReadPre *.exe,*.dll let &bin=1 au BufReadPost *.exe,*.dll if &bin | %!xxd au BufReadPost *.exe,*.dll set ft=xxd | endif au BufWritePre *.exe,*.dll if &bin | %!xxd -r au BufWritePre *.exe,*.dll endif au BufWritePost *.exe,*.dll if &bin | %!xxd au BufWritePost *.exe,*.dll set nomod | endif augroup EN " 自动进入org模式 au! BufRead,BufWrite,BufWritePost,BufNewFile *.org au BufEnter *.org call org#SetOrgFileType() " 自动补全设置 autocmd FileType python set omnifunc=pythoncomplete#Complete autocmd FileType python set completefunc=pythoncomplete#Complete autocmd FileType c set omnifunc=ccomplete#Complete autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS autocmd FileType html set omnifunc=htmlcomplete#CompleteTags autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags autocmd FileType css set omnifunc=csscomplete#CompleteCSS " python文件使用空格缩进 "au FileType python,c set shiftwidth=4 | set tabstop=4 | set expandtab | set softtabstop=4 au FileType c set expandtab " 启用语法高亮 syntax on " 高亮当前行 set cursorline " 允许所有模式的虚拟编辑 set ve=all " 自动补全只显示匹配项目 set completeopt=menu set pumheight=10 " Shell设置 if has("unix") set shell=zsh else " under win32 set shell=cmd.exe "d:/cygwin/cygwin.bat" endif " 历史记录数 set history=400 " 当文件被外部改变时自动读取 set autoread " 总是使用鼠标 set mouse=a " 取消自动备份 set nobackup set writebackup " 设置Leader let mapleader = "," let g:mapleader = "," " 关闭IME if has("gui") "set imdisable set iminsert=2 set imsearch=0 set noimcmdline endif " vimrc编辑后自动重新加载 autocmd! BufWritePost vimrc.zhao source $VIMHOME/vimrc.zhao autocmd! BufWritePost vimrc.lang source $VIMHOME/vimrc.lang autocmd! BufWritePost vimrc.face source $VIMHOME/vimrc.face autocmd! BufWritePost vimrc.binding source $VIMHOME/vimrc.binding autocmd! BufWritePost vimrc.plugin source $VIMHOME/vimrc.plugin " 设置swapfile存放路径 set dir=$VIMTEMP " 保存撤销历史 set undofile set undodir=$VIMHOME/undo " 光标上下两侧最少保留的屏幕行数 set scrolloff=7 " 启用命令行补全 set wildmenu " 命令行区的高度 set cmdheight=2 " 显示标尺 set ruler " 显示行号 set number " 运行宏时不重画窗口 set lazyredraw " 设置退格键模式 set backspace=eol,start,indent " 设置左右移动光标的键的回绕 set whichwrap+=,h,l " 搜索 set ignorecase set hlsearch set incsearch " 启用magic set magic " 禁用错误响铃 set noerrorbells set novisualbell set t_vb= " 显示匹配括号 set showmatch " 设置自动缩进TAB数 set shiftwidth=4 " 设置TAB的空格数 set tabstop=4 " 使用空格代替TAB set expandtab " 设置软TAB的空格数 set softtabstop=4 " 自动缩进 set autoindent " 智能缩进 set smartindent " C风格的缩进 "set cindent " 禁用自动换行 "set nowrap " 设置匹配符号组 set matchpairs+= set matchpairs+==:; set matchpairs+=":" set matchpairs+=':' " 设置换行符格式 "set ffs=dos,unix,mac " 显示tab和尾部空格 "set list set listchars=tab:>-,trail:$ " 剪贴板 if has("win32") "剪贴板等同于无名寄存器(*) set clipboard=unnamed
"推荐语句
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1

endif
" Windows兼容
" 启用C-C,V,X
"if has("gui_running")
source $VIMRUNTIME/mswin.vim
"endif
behave mswin

" 关闭VI兼容模式
set nocompatible

filetype plugin indent on

set modeline
"set modelines=2

" 缩写
iab xdate =strftime("%Y-%m-%y")
iab xdate1 =strftime("%Y-%m-%y %H:%M:%S")
iab xname xue.f zhao

" 打开文件后跳转到最后已知的文件位置,见帮助
au BufReadPost * if line("'\"") > 0|if line("'\"")

" 自动进入二进制模式
augroup Binary
au!
au BufReadPre *.exe,*.dll let &bin=1
au BufReadPost *.exe,*.dll if &bin | %!xxd
au BufReadPost *.exe,*.dll set ft=xxd | endif
au BufWritePre *.exe,*.dll if &bin | %!xxd -r
au BufWritePre *.exe,*.dll endif
au BufWritePost *.exe,*.dll if &bin | %!xxd
au BufWritePost *.exe,*.dll set nomod | endif
augroup EN

" 自动进入org模式
au! BufRead,BufWrite,BufWritePost,BufNewFile *.org
au BufEnter *.org call org#SetOrgFileType()

" 自动补全设置
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType python set completefunc=pythoncomplete#Complete
autocmd FileType c set omnifunc=ccomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS

" python文件使用空格缩进
"au FileType python,c set shiftwidth=4 | set tabstop=4 | set expandtab | set softtabstop=4
au FileType c set expandtab

" 启用语法高亮
syntax on

" 高亮当前行
set cursorline

" 允许所有模式的虚拟编辑
set ve=all

" 自动补全只显示匹配项目
set completeopt=menu
set pumheight=10

" Shell设置
if has("unix")
set shell=zsh
else " under win32
set shell=cmd.exe "d:/cygwin/cygwin.bat"
endif

" 历史记录数
set history=400

" 当文件被外部改变时自动读取
set autoread

" 总是使用鼠标
set mouse=a

" 取消自动备份
set nobackup
set writebackup

" 设置Leader
let mapleader = ","
let g:mapleader = ","

" 关闭IME
if has("gui")
"set imdisable
set iminsert=2
set imsearch=0
set noimcmdline
endif

" vimrc编辑后自动重新加载
autocmd! BufWritePost vimrc.zhao source $VIMHOME/vimrc.zhao
autocmd! BufWritePost vimrc.lang source $VIMHOME/vimrc.lang
autocmd! BufWritePost vimrc.face source $VIMHOME/vimrc.face
autocmd! BufWritePost vimrc.binding source $VIMHOME/vimrc.binding
autocmd! BufWritePost vimrc.plugin source $VIMHOME/vimrc.plugin

" 设置swapfile存放路径
set dir=$VIMTEMP

" 保存撤销历史
set undofile
set undodir=$VIMHOME/undo

" 光标上下两侧最少保留的屏幕行数
set scrolloff=7

" 启用命令行补全
set wildmenu

" 命令行区的高度
set cmdheight=2

" 显示标尺
set ruler

" 显示行号
set number

" 运行宏时不重画窗口
set lazyredraw

" 设置退格键模式
set backspace=eol,start,indent

" 设置左右移动光标的键的回绕
set whichwrap+=,h,l

" 搜索
set ignorecase
set hlsearch
set incsearch

" 启用magic
set magic

" 禁用错误响铃
set noerrorbells
set novisualbell
set t_vb=

" 显示匹配括号
set showmatch

" 设置自动缩进TAB数
set shiftwidth=4

" 设置TAB的空格数
set tabstop=4

" 使用空格代替TAB
set expandtab

" 设置软TAB的空格数
set softtabstop=4

" 自动缩进
set autoindent

" 智能缩进
set smartindent

" C风格的缩进
"set cindent

" 禁用自动换行
"set nowrap

" 设置匹配符号组
set matchpairs+=
set matchpairs+==:;
set matchpairs+=":"
set matchpairs+=':'

" 设置换行符格式
"set ffs=dos,unix,mac

" 显示tab和尾部空格
"set list
set listchars=tab:>-,trail:$

" 剪贴板
if has("win32")
"剪贴板等同于无名寄存器(*)
set clipboard=unnamed
"推荐语句set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1

endif
原文地址:https://www.cnblogs.com/fengfengqingqingyangyang/p/2805483.html