vim 配置

来源:互联网 发布:阿里云事业部组织架构 编辑:程序博客网 时间:2024/06/07 10:59
let mapleader = ";"    " 比较习惯用;作为命令前缀,右手小拇指直接能按到" 把空格键映射成:nmap  :" 快捷打开编辑vimrc文件的键盘绑定map  ee :e $HOME/.vimrcautocmd! bufwritepost *.vimrc source $HOME/.vimrc" ^z快速进入shellnmap  :shellinoremap n " 判断操作系统if (has("win32") || has("win64") || has("win32unix"))    let g:isWin = 1else    let g:isWin = 0endif" 判断是终端还是gvimif has("gui_running")    let g:isGUI = 1else    let g:isGUI = 0endifset nocompatible    " 关闭兼容模式syntax enable       " 语法高亮filetype plugin on  " 文件类型插件filetype indent onset shortmess=atI   " 去掉欢迎界面set autoindentautocmd BufEnter * :syntax sync fromstartset nu              " 显示行号set showcmd         " 显示命令set lz              " 当运行宏时,在命令执行完成之前,不重绘屏幕set hid             " 可以在没有保存的情况下切换bufferset backspace=eol,start,indent set whichwrap+=<,>,h,l " 退格键和方向键可以换行set incsearch       " 增量式搜索set nohlsearch"set hlsearch        " 高亮搜索set ignorecase      " 搜索时忽略大小写set magic           " 额,自己:h magic吧,一行很难解释set showmatch       " 显示匹配的括号set nobackup        " 关闭备份set nowbset noswapfile      " 不使用swp文件,注意,错误退出后无法恢复set lbr             " 在breakat字符处而不是最后一个字符处断行set ai              " 自动缩进set si              " 智能缩进set cindent         " C/C++风格缩进set wildmenu         set nofenset fdl=10" tab转化为4个字符set expandtabset smarttabset shiftwidth=4set tabstop=4" 不使用beep或flash set vb t_vb=set background=darkset t_Co=256colorscheme xoria256set history=400  " vim记住的历史操作的数量,默认的是20set autoread     " 当文件在外部被修改时,自动重新读取set mouse=n     " 在所有模式下都允许使用鼠标,还可以是n,v,i,c等"在gvim中高亮当前行if (g:isGUI)    set cursorline    colorscheme wombat    hi cursorline guibg=#333333    hi CursorColumn guibg=#333333    "set guifont=Consolas\ 10    "set guifontwide=Consolas\ 10    set guifont=DejaVu\ Sans\ Mono\ 10    set gfw=DejaVu\ Sans\ Mono\ 10    " 不显示toolbar    set guioptions-=T    " 不显示菜单栏    "set guioptions-=mendif" 设置字符集编码,默认使用utf8if (g:isWin)    let &termencoding=&encoding " 通常win下的encoding为cp936    set fileencodings=utf8,cp936,ucs-bom,latin1else    set encoding=utf8    set fileencodings=utf8,gb2312,gb18030,ucs-bom,latin1endif" 状态栏set laststatus=2      " 总是显示状态栏highlight StatusLine cterm=bold ctermfg=yellow ctermbg=blue" 获取当前路径,将$HOME转化为~function! CurDir()    let curdir = substitute(getcwd(), $HOME, "~", "g")    return curdirendfunctionset statusline=[%n]\ %f%m%r%h\ \|\ \ pwd:\ %{CurDir()}\ \ \|%=\|\ %l,%c\ %p%%\ \|\ ascii=%b,hex=%b%{((&fenc==\"\")?\"\":\"\ \|\ \".&fenc)}\ \|\ %{$USER}\ @\ %{hostname()}\ " 第80列往后加下划线"au BufWinEnter * let w:m2=matchadd('Underlined', '\%>' . 80 . 'v.\+', -1)" 根据给定方向搜索当前光标下的单词,结合下面两个绑定使用function! VisualSearch(direction) range    let l:saved_reg = @"    execute "normal! vgvy"    let l:pattern = escape(@", '\\/.*$^~[]')    let l:pattern = substitute(l:pattern, "\n$", "", "")    if a:direction == 'b'        execute "normal ?" . l:pattern . ""    else        execute "normal /" . l:pattern . ""    endif    let @/ = l:pattern    let @" = l:saved_regendfunction" 用 */# 向 前/后 搜索光标下的单词vnoremap  * :call VisualSearch('f')vnoremap  # :call VisualSearch('b')" 在文件名上按gf时,在新的tab中打开"map gf :tabnew " 用c-j,k在buffer之间切换nn  :bnnn  :bp" Bash(Emacs)风格键盘绑定imap  imap  "imap  d0i"imap  d$i  " 与自动补全中的绑定冲突"从系统剪切板中复制,剪切,粘贴map  "+ymap  "+xmap  "+p" 恢复上次文件打开位置set viminfo='10,\"100,:20,%,n~/.viminfoau BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif" 删除buffer时不关闭窗口command! Bclose call BufcloseCloseIt()function! BufcloseCloseIt()    let l:currentBufNum = bufnr("%")    let l:alternateBufNum = bufnr("#")    if buflisted(l:alternateBufNum)        buffer #    else        bnext    endif    if bufnr("%") == l:currentBufNum        new    endif    if buflisted(l:currentBufNum)        execute("bdelete! ".l:currentBufNum)    endifendfunction" 快捷输入" 自动完成括号和引号inoremap 1 ():let leavechar=")"iinoremap 2 []:let leavechar="]"iinoremap 3 {}:let leavechar="}"iinoremap 4 {o}:let leavechar="}"Oinoremap q '':let leavechar="'"iinoremap w "":let leavechar='"'i" 插件窗口的宽度,如TagList,NERD_tree等,自己设置let s:PlugWinSize = 25" taglist.vim" http://www.vim.org/scripts/script.php?script_id=273" t 打开TagList窗口,窗口在右边nmap  t :TlistToggle"let Tlist_Ctags_Cmd = '/usr/bin/ctags'let Tlist_Show_One_File = 0let Tlist_Exit_OnlyWindow = 1 let Tlist_Use_Right_Window = 1let Tlist_File_Fold_Auto_Close = 1let Tlist_GainFocus_On_ToggleOpen = 0let Tlist_WinWidth = s:PlugWinSizelet Tlist_Auto_Open = 0let Tlist_Display_Prototype = 0"let Tlist_Close_On_Select = 1" OmniCppComplete.vim" http://www.vim.org/scripts/script.php?script_id=1520set completeopt=menulet OmniCpp_ShowPrototypeInAbbr = 1 let OmniCpp_DefaultNamespaces = ["std"]     " 逗号分割的字符串let OmniCpp_MayCompleteScope = 1 let OmniCpp_ShowPrototypeInAbbr = 0 let OmniCpp_SelectFirstItem = 2 " c-j自动补全,当补全菜单打开时,c-j,k上下选择imap        pumvisible()?"\":"\"imap        pumvisible()?"\":"\"" f:文件名补全,l:行补全,d:字典补全,]:tag补全imap              imap              imap              imap               " NERD_commenter.vim" http://www.vim.org/scripts/script.php?script_id=1218" Toggle单行注释/“性感”注释/注释到行尾/取消注释map cc ,cmap cs ,csmap c$ ,c$map cu ,cu" NERD tree" http://www.vim.org/scripts/script.php?script_id=1658let NERDTreeShowHidden = 1let NERDTreeWinPos = "left"let NERDTreeWinSize = s:PlugWinSize nmap n :NERDTreeToggle" DoxygenToolkit.vim" http://www.vim.org/scripts/script.php?script_id=987" 暂时没有使用" 更新ctags和cscope索引" href: http://www.vimer.cn/2009/10/把vim打造成一个真正的ide2.html" 稍作修改,提取出DeleteFile函数,修改ctags和cscope执行命令map  :call Do_CsTag()function! Do_CsTag()    let dir = getcwd()    "先删除已有的tags和cscope文件,如果存在且无法删除,则报错。    if ( DeleteFile(dir, "tags") )         return     endif    if ( DeleteFile(dir, "cscope.files") )         return     endif    if ( DeleteFile(dir, "cscope.out") )         return     endif    if(executable('ctags'))        silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."    endif    if(executable('cscope') && has("cscope") )        if(g:isWin)            silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"        else            silent! execute "!find . -iname '*.[ch]' -o -name '*.cpp' > cscope.files"        endif        silent! execute "!cscope -b"        execute "normal :"        if filereadable("cscope.out")            execute "cs add cscope.out"        endif    endif    " 刷新屏幕    execute "redr!"endfunctionfunction! DeleteFile(dir, filename)    if filereadable(a:filename)        if (g:isWin)            let ret = delete(a:dir."\\".a:filename)        else            let ret = delete("./".a:filename)        endif        if (ret != 0)            echohl WarningMsg | echo "Failed to delete ".a:filename | echohl None            return 1        else            return 0        endif    endif    return 0endfunction" cscope 绑定if has("cscope")    set csto=1    set cst    set nocsverb    if filereadable("cscope.out")        cs add cscope.out    endif    set csverb    " s: C语言符号  g: 定义     d: 这个函数调用的函数 c: 调用这个函数的函数    " t: 文本       e: egrep模式    f: 文件     i: include本文件的文件    nmap ss :cs find s =expand(""):copen    nmap sg :cs find g =expand("")    nmap sc :cs find c =expand(""):copen    nmap st :cs find t =expand(""):copen    nmap se :cs find e =expand(""):copen    nmap sf :cs find f =expand(""):copen    nmap si :cs find i ^=expand("")$:copen    nmap sd :cs find d =expand(""):copenendif" Quick Fix 设置map  :cwmap  :cpmap  :cn" Buffers Explorer (需要genutils.vim)" http://vim.sourceforge.net/scripts/script.php?script_id=42" http://www.vim.org/scripts/script.php?script_id=197let 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 = s:PlugWinSize  " Split widthlet g:bufExplorerUseCurrentWindow=1  " Open in new window.autocmd BufWinEnter \[Buf\ List\] setl nonumbernmap  b :BufExplorer" Vimwiki配置let g:vimwiki_list = [{'path': '~/Dropbox/MyWiki/my_site/',            \ 'path-html': '~/Dropbox/MyWiki/my_site_html/',            \ 'html-header': '~/Dropbox/MyWiki/templates/header.tpl',            \ 'html-footer': '~/Dropbox/MyWiki/templates/footer.tpl'}]let g:vimwiki_camel_case=0let wiki = {}let wiki.path = '~/Dropbox/MyWiki/my_site/'let wiki.nested_syntaxes = {'python': 'python', 'c++': 'cpp'}let g:vimwiki_list = [wiki]"pythoncomplete配置autocmd filetype python set omnifunc=pythoncomplete#Complete
                                             
0 0