Vim VBScriptのEnd XXXを自動的に補完する (改)
前回の反省を踏まえて修正を行った。
オムニ補完などで表示されるポップアップメニュー上で候補を<C-n>などで選択したあとでEnterキーを押下すると、上手く補完しないという欠点はあるものの、それ以外は正常に動作する。・・・はず(--;)
今回はこだわったが、挿入モードでのEnterキーへのキーマップは、プラグインとの相性を考えてもあまりよろしくないので、今後は控えようと思う。
"VB.NETのIDEのように、If文やFor文を書いた後の改行時に自動的にEnd IfやEnd Forを自動入力する。 function AutoEndForVBScript() let line = strpart(getline('.'), 0, col('.') - 1) if strlen(line) != strlen(getline('.')) return "\<CR>" endif "ポップアップメニューが表示されているか? if pumvisible() return "\<CR>" endif "Function, If, Select-Case, While, Do-While, Do-Until, Do-Loop, For let serchWords = [ \ '^\t*Sub.*)$', \ '^\t*Function.*)$', \ '^\t*If ', \ '^\t*Select Case ', \ '^\t*While ', \ '^\t*Do While ', \ '^\t*Do Until ', \ '^\t*Do \=$', \ '^\t*For ' \ ] "End let endsStatements = [ \ "End Sub", \ "End Function", \ "End If", \ "End Select", \ "Wend", \ "Loop", \ "Loop", \ "Loop", \ "Next" \] let i = 0 for regexp in serchWords if line =~ regexp return "\<CR>" . endsStatements[i] . "\<UP>\<Esc>o" endif let i = i + 1 endfor return "\<CR>" endfunction au FileType vb inoremap <expr> <CR> AutoEndForVBScript()