"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 一般设定
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 设定默认解码
set fenc=utf-8
set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936
" 设置不与之前版本兼容
set nocompatible
" 查找结果高亮度显示
set hlsearch
" 配色
colorscheme desert
" 显示行号
set nu
" 检测文件的类型
filetype on
" 设置当文件被改动时自动载入
set autoread
" 记录历史的行数
set history=80
" 设置语法高亮度
syntax on
" 在处理未保存或只读文件的时候,弹出确认
set confirm
" 与windows共享剪贴板
set clipboard+=unnamed
" 载入文件类型插件
filetype plugin on
" 为特定文件类型载入相关缩进文件
filetype indent on
" 保存全局变量
set viminfo+=!
" 带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-
" 设置鼠标一直可用
set mouse=a
" 高亮当前行
set cursorline
" 命令行高度
set cmdheight=1
" 启动的时候不显示那个援助索马里儿童的提示
set shortmess=atI
" 设置帮助语言
if version >= 603
set helplang=cn
set encoding=utf-8
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文件设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 不要备份文件(根据自己需要取舍)
set nobackup
" 不要生成swap文件,当buffer被丢弃的时候隐藏它
setlocal noswapfile
set bufhidden=hide
" 字符间插入的像素行数目
set linespace=0
" 增强模式中的命令行自动完成操作
set wildmenu
" 在状态行上显示光标所在位置的行号和列号
set ruler
" 不让vim发出讨厌的滴滴声
set noerrorbells
" 在被分割的窗口间显示空白,便于阅读
set fillchars=vert:\ ,stl:\ ,stlnc:\
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 搜索和匹配
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 高亮显示匹配的括号
set showmatch
" 不要高亮被搜索的句子(phrases)
"set nohlsearch
" 在搜索时,输入的词句的逐字符高亮(类似firefox的搜索)
set incsearch
" 搜索时忽略大小写
set ignorecase
" 不要闪烁
set novisualbell
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文本格式和排版
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 自动格式化
set formatoptions=tcrqn
" 继承前一行的缩进方式,特别适用于多行注释
set autoindent
" 为C程序提供自动缩进
set smartindent
" 使用C样式的缩进
set cindent
" 制表符为4
set tabstop=4
" 统一缩进为4
set softtabstop=4
set shiftwidth=4
" 不要用空格代替制表符
set noexpandtab
" 设置每行80个字符自动换行
set textwidth=80
" -------------------------------------------------------------------------------------------------
" set mapleader
let mapleader = ","
" platform
function! MySys()
if has("win32")
return "windows"
else
return "linux"
endif
endfunction
" if file not opened, create a new tab, or switch to the opened file
function! SwitchToBuf(filename)
" find in current tab
let bufwinnr = bufwinnr(a:filename)
if bufwinnr != -1
exec bufwinnr . "wincmd w"
return
else
" search each tab
tabfirst
let tb = 1
while tb <= tabpagenr("$")
let bufwinnr = bufwinnr(a:filename)
if bufwinnr != -1
exec "normal " . tb . "gt"
exec bufwinnr . "wincmd w"
return
endif
tabnext
let tb = tb +1
endwhile
" not exist, new tab
exec "tabnew " . a:filename
endif
endfunction
" fast edit .vimrc
if MySys() == 'linux'
" fast reloading of the .vimrc
map <silent> <leader>ss :source ~/.vimrc<cr>
" fast editing of the .vimrc
map <silent> <leader>ee :call SwitchToBuf("~/.vimrc")<cr>
" when .vimrc is edited, reload it
autocmd! bufwritepost .vimrc source ~/.vimrc
elseif MySys() == 'windows'
" Set helplang
set helplang=cn
"Fast reloading of the _vimrc
map <silent> <leader>ss :source ~/_vimrc<cr>
"Fast editing of _vimrc
map <silent> <leader>ee :call SwitchToBuf("~/_vimrc")<cr>
"When _vimrc is edited, reload it
autocmd! bufwritepost _vimrc source ~/_vimrc
endif
if MySys() == 'windows'
source $VIMRUNTIME/mswin.vim
behave mswin
endif
" quickfix模式
autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr>
nmap <leader>cn :cn<cr>
nmap <leader>cp :cp<cr>
nmap <leader>cw :cw 10<cr>
" vimgrep/lvimgrep(lv)
" 在当前文件中快速查找光标下的单词, 并在窗口的位置列表中显示
" 好像该功能有mark插件可以代劳:)
nmap <leader>lv :lv /<c-r>=expand("<cword>")<cr>/ %<cr>:lw<cr>
" omni completion(全能补全)
" 为支持C++的全能补全,需安装插件: OmniCppComplete
" 并且生成tag文件的命令是(src为源文件目录): ctags -R --c++-kinds=+p --fields=+iaS --extra=+q src
" 因为在对C++文件进行补全时,OmniCppComplete插件需要tag文件中包含C++的额外信息
" C++的补全连”CTRL-X CTRL-O“都不必输入呵呵,测试通过
set completeopt=longest,menu " 只在下拉菜单中显示匹配项目,并且会自动插入所有匹配项目的相同文本
inoremap <C-J> <C-X><C-O>
" generic completion(其他补全方式)
" 文件名补全
inoremap <C-F> <C-X><C-F>
" 宏定义补全
inoremap <C-D> <C-X><C-D>
" 整行补全
inoremap <C-L> <C-X><C-L>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CTags
set tags=tags " 当前目录, 不知道为什么写成./tags就无效
set tags+=../tags
" 为/usr/include目录生成tags文件,缺点可能会导致自动完成的速度减慢,必要时去除
" 更好的办法是需要时才加,例如/usr/include/gtk2.0/tags
" set tags+=/usr/include/tags
" Cscope
if has("cscope")
set csprg=/usr/bin/cscope
set csto=1
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
endif
set csverb
endif
nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>
" Tag List
" 按照名称排序
let Tlist_Sort_Type = "name"
" 在右侧显示窗口
let Tlist_Use_Right_Window = 1
" 如果只有一个buffer,kill窗口也kill掉buffer
let Tlist_Exist_OnlyWindow = 1
" 使taglist只显示当前文件tag,其它文件的tag都被折叠起来(同时显示多个文件中的tag时)
let Tlist_File_Fold_Auto_Close = 1
" 不要显示折叠树
let Tlist_Enable_Fold_Column = 1
"不同时显示多个文件的tag,只显示当前文件的
let Tlist_Show_One_File = 1
" 键盘映射
nmap tl :TlistToggle<cr>
" Buf Explorer
let g:bufExplorerDefaultHelp=0 " Do not show default help.
let g:bufExplorerShowRelativePath=1 " Show relative paths.
let g:bufExplorerSortBy='mru' " Sort by most recently used.
let g:bufExplorerSplitRight=0 " Split left.
let g:bufExplorerSplitVertical=1 " Split vertically.
let g:bufExplorerSplitVertSize = 30 " Split width
let g:bufExplorerUseCurrentWindow=1 " Open in new window.
autocmd BufWinEnter \[Buf\ List\] setl nonumber
" Win Manager
let g:winManagerWindowLayout = "BufExplorer,FileExplorer|TagList"
let g:persistentBehaviour = 0
let g:winManagerWidth = 30
let g:defaultExplorer = 0
nmap <C-W><C-F> :FirstExplorerWindow<cr>
nmap <C-W><C-B> :BottomExplorerWindow<cr>
nmap wm :WMToggle<cr>
" Lookupfile
let g:LookupFile_MinPatLength = 2 "最少输入2个字符才开始查找
let g:LookupFile_PreserveLastPattern = 0 "不保存上次查找的字符串
let g:LookupFile_PreservePatternHistory = 1 "保存查找历史
let g:LookupFile_AlwaysAcceptFirst = 1 "回车打开第一个匹配项目
let g:LookupFile_AllowNewFiles = 0 "不允许创建不存在的文件
" 通过shell脚本: lookupfile_tag.sh生成当前目录的filenametags文件
" 该脚本在~/.vim目录下有备份
if filereadable("./filenametags") "设置tag文件的名字
let g:LookupFile_TagExpr = '"./filenametags"'
endif
nmap <silent> <leader>lk <Plug>LookupFile
nmap <silent> <leader>lb :LUBufs<cr>
nmap <silent> <leader>lw :LUWalk<cr>
" lookup file with ignore case
function! LookupFile_IgnoreCaseFunc(pattern)
let _tags = &tags
try
let &tags = eval(g:LookupFile_TagExpr)
let newpattern = '\c' . a:pattern
let tags = taglist(newpattern)
catch
echohl ErrorMsg | echo "Exception: " . v:exception | echohl NONE
return ""
finally
let &tags = _tags
endtry
" Show the matches for what is typed so far.
let files = map(tags, 'v:val["filename"]')
return files
endfunction
let g:LookupFile_LookupFunc = 'LookupFile_IgnoreCaseFunc'
" Mark
nmap <silent> <leader>hl <Plug>MarkSet
vmap <silent> <leader>hl <Plug>MarkSet
nmap <silent> <leader>hh <Plug>MarkClear
vmap <silent> <leader>hh <Plug>MarkClear
nmap <silent> <leader>hr <Plug>MarkRegex
vmap <silent> <leader>hr <Plug>MarkRegex
" SuperTab
" 记住上次的补全方式,直到按ESC退出插入模式为止
let g:SuperTabRetainCompletionType = 2
" 缺省的补全方式(设置为全能补全)
let g:SuperTabDefaultCompletionType = "<C-X><C-O>"
" DoxygenToolkit
let g:DoxygenToolkit_authorName="simplyzhao"
nmap da :DoxAuthor<cr>
nmap dx :Dox<cr>
nmap db :DoxBlock<cr>
2009年5月06日 19:13
赞,我的Emacs还没配置得那么到位呢
论文快搞定了,终于可以有点时间做我的事了