現在、Vimコマンドを呼び出すことができるスクリプトを作成しようとしていますが、これは外部コマンドを呼び出します。私は、特定の拡張子を持つファイルのリスト内の結果で自動補完を有効にしたい(下記のコードを参照)。Vimスクリプトコマンド完了:タブを押してリストをリロードする
補完は実際には指定された拡張子を持つファイルのリストを巡回しますが、何かを入力してタブを押すと、実際には何が入力されているかにかかわらず、リストの先頭から補完が繰り返されます入力に与えられたファイル名の残りの部分を完成させます)。 app.component.ts、およびtest.component.tsを、私は
:EComponent test
Tabキーを押すと入力し、完了したコマンドは以下となります。私が持っている場合、例えば
call CreateEditCommand('EComponent', 'ComponentFiles')
function! CreateEditCommand(command, listFunction)
silent execute 'command! -nargs=1 -complete=customlist,'. a:listFunction . ' ' . a:command . ' call EditFile(<f-args>)'
endfunction
function! ComponentFiles(A,L,P)
return Files('component.ts')
endfunction
function! Files(extension)
let paths = split(globpath('.', '**/*.' . a:extension), "\n")
let idx = range(0, len(paths)-1)
let g:global_paths = {}
for i in idx
let g:global_paths[fnamemodify(paths[i], ':t:r')] = paths[i]
endfor
call map(paths, 'fnamemodify(v:val, ":t:r")')
return paths
endfunction
function! EditFile(file)
execute 'edit' g:global_paths[a:file]
endfunction
:コードは以下の通りであります
:EComponent test.component.ts
次
:EComponent app.component.ts
の代わりであります
これについてあなたの助けを前もってありがとう。
"コマンドファクトリコマンド"の目的は何ですか? – romainl