⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 complete.vim

📁 vim的自动配置文件
💻 VIM
📖 第 1 页 / 共 2 页
字号:
" Description: Omni completion script for cpp files" Maintainer:  Vissale NEANG" Last Change: 25 juin 2006if v:version < 700    echohl WarningMsg    echomsg "omni#cpp#complete.vim: Please install vim 7.0 or higher for omni-completion"    echohl None    finishendifcall omni#cpp#settings#Init()let s:OmniCpp_ShowScopeInAbbr = g:OmniCpp_ShowScopeInAbbrlet s:OmniCpp_ShowPrototypeInAbbr = g:OmniCpp_ShowPrototypeInAbbrlet s:OmniCpp_ShowAccess = g:OmniCpp_ShowAccesslet s:szCurrentWorkingDir = getcwd()" Cache datalet s:CACHE_TAG_POPUP_ITEMS = {}let s:CACHE_TAG_FILES = {}let s:CACHE_TAG_ENV = ''let s:CACHE_OVERLOADED_FUNCTIONS = {}call garbagecollect()" Has preview window?let s:hasPreviewWindow = match(&completeopt, 'preview')>=0let s:hasPreviewWindowOld = s:hasPreviewWindow" Popup item listlet s:popupItemResultList = []" May complete indicatorlet s:bMayComplete = 0" Init mappingsfunction! omni#cpp#complete#Init()    call omni#cpp#settings#Init()    set omnifunc=omni#cpp#complete#Main    inoremap <expr> <C-X><C-O> omni#cpp#maycomplete#Complete()    inoremap <expr> . omni#cpp#maycomplete#Dot()    inoremap <expr> > omni#cpp#maycomplete#Arrow()    inoremap <expr> : omni#cpp#maycomplete#Scope()endfunc" Find the start position of the completionfunction! s:FindStartPositionOfCompletion()    " Locate the start of the item, including ".", "->" and "[...]".    let line = getline('.')    let start = col('.') - 1    let lastword = -1    while start > 0        if line[start - 1] =~ '\w'            let start -= 1        elseif line[start - 1] =~ '\.'            " Searching for dot '.'            if lastword == -1                let lastword = start            endif            let start -= 1        elseif start > 1 && line[start - 2] == '-' && line[start - 1] == '>'            " Searching for '->'            if lastword == -1                let lastword = start            endif            let start -= 2        elseif start > 1 && line[start - 2] == ':' && line[start - 1] == ':'            " Searching for '::' for namespaces and class            if lastword == -1                let lastword = start            endif            let start -= 2        elseif line[start - 1] == ']'            " Skip over [...].            let n = 0            let start -= 1            while start > 0                let start -= 1                if line[start] == '['                    if n == 0                        break                    endif                    let n -= 1                elseif line[start] == ']'  " nested []                    let n += 1                endif            endwhile        else            break        endif    endwhile    if lastword==-1        " For completion on the current scope        let lastword = start    endif    return lastwordendfunc" Returns if szKey1.szKey2 is in the cache" @return"   - 0 = key not found"   - 1 = szKey1.szKey2 found"   - 2 = szKey1.[part of szKey2] foundfunction! s:IsCached(cache, szKey1, szKey2)    " Searching key in the result cache    let szResultKey = a:szKey1 . a:szKey2    let result = [0, szResultKey]    if a:szKey2 != ''        let szKey = a:szKey2        while len(szKey)>0            if has_key(a:cache, a:szKey1 . szKey)                let result[1] = a:szKey1 . szKey                if szKey != a:szKey2                    let result[0] = 2                else                    let result[0] = 1                endif                break            endif            let szKey = szKey[:-2]        endwhile    else        if has_key(a:cache, szResultKey)            let result[0] = 1        endif    endif    return resultendfunc" Extend a tag item to a popup itemfunction! s:ExtendTagItemToPopupItem(tagItem, szTypeName)    let tagItem = a:tagItem    " Add the access    let szItemMenu = ''    let accessChar = {'public': '+','protected': '#','private': '-'}    if g:OmniCpp_ShowAccess        if has_key(tagItem, 'access') && has_key(accessChar, tagItem.access)            let szItemMenu = szItemMenu.accessChar[tagItem.access]        else            let szItemMenu = szItemMenu." "        endif    endif    " Formating optional menu string we extract the scope information    let szName = substitute(tagItem.name, '.*::', '', 'g')    let szItemWord = szName    let szAbbr = szName    if !g:OmniCpp_ShowScopeInAbbr        let szScopeOfTag = omni#cpp#utils#ExtractScope(tagItem)        let szItemMenu = szItemMenu.' '.szScopeOfTag[2:]        let szItemMenu = substitute(szItemMenu, '\s\+$', '', 'g')    else        let szAbbr = tagItem.name    endif    if g:OmniCpp_ShowAccess        let szItemMenu = substitute(szItemMenu, '^\s\+$', '', 'g')    else        let szItemMenu = substitute(szItemMenu, '\(^\s\+\)\|\(\s\+$\)', '', 'g')    endif    " Formating information for the preview window    if index(['f', 'p'], tagItem.kind[0])>=0        let szItemWord .= '('        if g:OmniCpp_ShowPrototypeInAbbr && has_key(tagItem, 'signature')            let szAbbr .= tagItem.signature        else            let szAbbr .= '('        endif    endif    let szItemInfo = ''    if s:hasPreviewWindow        let szItemInfo = omni#cpp#utils#GetPreviewWindowStringFromTagItem(tagItem)    endif    " If a function is a ctor we add a new key in the tagItem    if index(['f', 'p'], tagItem.kind[0])>=0        if match(szName, '^\~') < 0 && a:szTypeName =~ '\C\<'.szName.'$'            " It's a ctor            let tagItem['ctor'] = 1        elseif has_key(tagItem, 'access') && tagItem.access == 'friend'            " Friend function            let tagItem['friendfunc'] = 1        endif    endif    " Extending the tag item to a popup item    let tagItem['word'] = szItemWord    let tagItem['abbr'] = szAbbr    let tagItem['menu'] = szItemMenu    let tagItem['info'] = szItemInfo    let tagItem['dup'] = (s:hasPreviewWindow && index(['f', 'p', 'm'], tagItem.kind[0])>=0)    return tagItemendfunc" Get tag popup item listfunction! s:TagPopupList(szTypeName, szBase)    let result = []    " Searching key in the result cache    let cacheResult = s:IsCached(s:CACHE_TAG_POPUP_ITEMS, a:szTypeName, a:szBase)    " Building the tag query, we don't forget dtors when a:szBase==''    if a:szTypeName!=''        " Scope search        let szTagQuery = '^' . a:szTypeName . '::' . a:szBase . '\~\?\w\+$'    else        " Global search        let szTagQuery = '^' . a:szBase . '\w\+$'    endif    " If the result is already in the cache we return it    if cacheResult[0]        let result = s:CACHE_TAG_POPUP_ITEMS[ cacheResult[1] ]        if cacheResult[0] == 2            let result = filter(copy(result), 'v:val.name =~ szTagQuery' )        endif        return result    endif    try        " Getting tags        let result = omni#common#utils#TagList(szTagQuery)        " We extend tag items to popup items        call map(result, 's:ExtendTagItemToPopupItem(v:val, a:szTypeName)')        " We store the result in a cache        if cacheResult[1] != ''            let s:CACHE_TAG_POPUP_ITEMS[ cacheResult[1] ] = result        endif    catch /^TagList:UserInterrupt$/    endtry    return resultendfunc" Find complete matches for a completion on the global scopefunction! s:SearchGlobalMembers(szBase)    if a:szBase != ''        let tagPopupList = s:TagPopupList('', a:szBase)        let tagPopupList = filter(copy(tagPopupList), g:omni#cpp#utils#szFilterGlobalScope)        call extend(s:popupItemResultList, tagPopupList)    endifendfunc" Search class, struct, union members" @param resolvedTagItem: a resolved tag item" @param szBase: string base" @return list of tag items extended to popup itemsfunction! s:SearchMembers(resolvedTagItem, szBase)    let result = []    if a:resolvedTagItem == {}        return result    endif    " Get type info without the starting '::'    let szTagName = omni#cpp#utils#ExtractTypeInfoFromTag(a:resolvedTagItem)[2:]    " Unnamed type case. A tag item representing an unnamed type is a variable     " ('v') a member ('m') or a typedef ('t')    if index(['v', 't', 'm'], a:resolvedTagItem.kind[0])>=0 && has_key(a:resolvedTagItem, 'typeref')        " We remove the 'struct:' or 'class:' etc...        let szTagName = substitute(a:resolvedTagItem.typeref, '^\w\+:', '', 'g')    endif    return copy(s:TagPopupList(szTagName, a:szBase))endfunc" Return if the tag env has changedfunction! s:HasTagEnvChanged()    if s:CACHE_TAG_ENV == &tags        return 0    else        let s:CACHE_TAG_ENV = &tags        return 1    endifendfunc" Return if a tag file has changed in tagfiles()function! s:HasATagFileOrTagEnvChanged()    if s:HasTagEnvChanged()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -