[英]List @ tag auto completes in vim
在vim中進行編輯時,我@models
在markdown文件中@tags
許多@tags
(例如@sea_ice
, @models
)。 目前,我正在使用SuperTab來制表完整的普通單詞。 但是,如果我在@
符號后打<tab>
,它不會給我所有@tags
的列表,而是一整個當前上下文中所有單詞的長列表。
我注意到SuperTab允許自定義上下文定義,但是,由於我對vim腳本一無所知,並且該文檔僅包含兩個示例,因此我無法自己編寫腳本。
經過一番搜索之后,我認為我可能需要定義一個新的自定義omni完整功能,特別是該功能的第二部分:
function! TagComplete(findstart, base) if a:findstart " locate the start of the word let line = getline('.') let start = col('.') - 1 while start > 0 && line[start - 1] != '@' let start -= 1 endwhile return start else " find @tag let res = [] ???? ???? endif return res endif endfun
這是我正在處理的代碼。 但是我不知道如何測試它或在正確的位置放置它。 請幫忙
謝謝
經過大量的努力和尋求幫助之后,我找到了一個解決方案。
首先創建一個completefunc
,搜索@tags
在當前文件(學分cherryberryterry: https://www.reddit.com/r/vim/comments/4dg1rx/how_to_define_custom_omnifunc_in_vim_seeking/ ):
function! CompleteTags(findstart, base)
if a:findstart
return match(matchstr(getline('.'), '.*\%' . col('.') . 'c'), '.*\(^\|\s\)\zs@')
else
let matches = []
" position the cursor on the last column of the last line
call cursor(line('$'), col([line('$'), '$']))
" search backwards through the buffer for all matches
while searchpos('\%(^\|\s\)\zs' . (empty(a:base) ? '@' : a:base) . '[[:alnum:]_]*', 'bW') != [0, 0]
let matches += [matchstr(getline('.'), '\%' . col('.') . 'c@[[:alnum:]_]*')]
endwhile
return filter(matches, "v:val != '@'")
endif
endfunction
set completefunc=CompleteTags
將以下內容放在.vimrc
以使用SuperTab設置制表符完成:
function! TagCompleteContext()
let line = getline('.')
if line[col('.') - 2] == '@'
return "\<c-x>\<c-u>"
endif
endfunction
let g:SuperTabDefaultCompletionType = "context"
let g:SuperTabCompletionContexts = ['TagCompleteContext', 's:ContextText']
let g:SuperTabContextDefaultCompletionType = "<c-p>"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.