私は少し時間をかけてvimプラグインの開発に取り組んでいますが、数週間はロードブロッキングで立ち往生しています。私はvimscriptで書かれており、()
、{}
、[]
、""
、''
のペアのための簡単な自動ペアリングプログラムです。私は終了時に終了文字()
、}
、]
)の右にスキップするようにしようとしています。今私の焦点は、)
、]
、}
文字のためだけに機能するようになっています。vimscriptの終了文字をスキップする
私の問題は、閉じた文字入力が入力されたときに関数を実行するのに問題があることです。ここで
は、私がこれまで試してみましたものです: 最初の試行:inoremap (()
inoremap (h()<LEFT>
inoremap (l();<RETURN>
inoremap (" ("")<LEFT><LEFT>
inoremap (' ('')<LEFT><LEFT>
inoremap (;();<DOWN>
inoremap) call CloseChar()
inoremap [ []
inoremap [h []<LEFT>
inoremap ] call CloseChar()
inoremap { {}
inoremap {h {}<LEFT>
inoremap {<RETURN> {<RETURN><TAB><RETURN><BACKSPACE>}<UP><TAB>
inoremap } call CloseChar()
inoremap " ""
inoremap "h ""<LEFT>
inoremap "l "";<RETURN>
inoremap ' ''
inoremap 'h ''<LEFT>
inoremap 'l '';<RETURN>
function CloseChar()
if matchstr(getline('.'), '\%' . col('.') . 'c.') == '}'
return <RIGHT>
elseif matchstr(getline('.'), '\%' . col('.') . 'c.') == ')'
return <RIGHT>
elseif matchstr(getline('.'), '\%' . col('.') . 'c.') == ']'
return <RIGHT>
elseif matchstr(getline('.'), '\%' . col('.') . 'c.') == '"'
return <RIGHT>
elseif matchstr(getline('.'), '\%' . col('.') . 'c.') == '''
return <RIGHT>
endif
endfunction
第二の試み:
inoremap (()
inoremap (h()<LEFT>
inoremap (l();<RETURN>
inoremap (" ("")<LEFT><LEFT>
inoremap (' ('')<LEFT><LEFT>
inoremap (;();<DOWN>
inoremap) :call CloseChar()
inoremap [ []
inoremap [h []<LEFT>
inoremap ] :call CloseChar()
inoremap { {}
inoremap {h {}<LEFT>
inoremap {<RETURN> {<RETURN><TAB><RETURN><BACKSPACE>}<UP><TAB>
inoremap } :call CloseChar()
inoremap " ""
inoremap "h ""<LEFT>
inoremap "l "";<RETURN>
inoremap ' ''
inoremap 'h ''<LEFT>
inoremap 'l '';<RETURN>
function CloseChar()
if matchstr(getline('.'), '\%' . col('.') . 'c.') == '}'
return <RIGHT>
elseif matchstr(getline('.'), '\%' . col('.') . 'c.') == ')'
return <RIGHT>
elseif matchstr(getline('.'), '\%' . col('.') . 'c.') == ']'
return <RIGHT>
elseif matchstr(getline('.'), '\%' . col('.') . 'c.') == '"'
return <RIGHT>
elseif matchstr(getline('.'), '\%' . col('.') . 'c.') == '''
return <RIGHT>
endif
endfunction
3回目の試み:
inoremap (()
inoremap (h()<LEFT>
inoremap (l();<RETURN>
inoremap (" ("")<LEFT><LEFT>
inoremap (' ('')<LEFT><LEFT>
inoremap (;();<DOWN>
inoremap <silent>) :call CloseChar()
inoremap [ []
inoremap [h []<LEFT>
inoremap <silent>] :call CloseChar()
inoremap { {}
inoremap {h {}<LEFT>
inoremap {<RETURN> {<RETURN><TAB><RETURN><BACKSPACE>}<UP><TAB>
inoremap <silent>} :call CloseChar()
inoremap " ""
inoremap "h ""<LEFT>
inoremap "l "";<RETURN>
inoremap ' ''
inoremap 'h ''<LEFT>
inoremap 'l '';<RETURN>
function CloseChar()
if matchstr(getline('.'), '\%' . col('.') . 'c.') == '}'
return <RIGHT>
elseif matchstr(getline('.'), '\%' . col('.') . 'c.') == ')'
return <RIGHT>
elseif matchstr(getline('.'), '\%' . col('.') . 'c.') == ']'
return <RIGHT>
elseif matchstr(getline('.'), '\%' . col('.') . 'c.') == '"'
return <RIGHT>
elseif matchstr(getline('.'), '\%' . col('.') . 'c.') == '''
return <RIGHT>
endif
endfunction
最後の試み:
inoremap (()
inoremap (h()<LEFT>
inoremap (l();<RETURN>
inoremap (" ("")<LEFT><LEFT>
inoremap (' ('')<LEFT><LEFT>
inoremap (;();<DOWN>
inoremap [ []
inoremap [h []<LEFT>
inoremap { {}
inoremap {h {}<LEFT>
inoremap {<RETURN> {<RETURN><TAB><RETURN><BACKSPACE>}<UP><TAB>
inoremap " ""
inoremap "h ""<LEFT>
inoremap "l "";<RETURN>
inoremap ' ''
inoremap 'h ''<LEFT>
inoremap 'l '';<RETURN>
function CloseChar()
if matchstr(getline('.'), '\%' . col('.') . 'c.') == '}'
return <RIGHT>
elseif matchstr(getline('.'), '\%' . col('.') . 'c.') == ')'
return <RIGHT>
elseif matchstr(getline('.'), '\%' . col('.') . 'c.') == ']'
return <RIGHT>
elseif matchstr(getline('.'), '\%' . col('.') . 'c.') == '"'
return <RIGHT>
elseif matchstr(getline('.'), '\%' . col('.') . 'c.') == '''
return <RIGHT>
endif
endfunction
call CloseChar()
CloseChar()
の代わりに、)
,]
,}
が挿入されます。私が参照したソリューションのソースはlearnvimscriptthehardwayとFive Minute Vimscriptです。いくつかのstackoverflow投稿(私は、関連するすべてのフォーラムや記事をリンクするには十分な評判がありません。申し訳ありません)。
本質的に、私は立ち往生しており、プラグインを修正して動作するように頼んでいます。
注: 大きな違いがあるかどうかわかりませんが、Linux用のWindowsサブシステム(wsl)からvimを使用しています。
inoremap (()
inoremap (h()<LEFT>
inoremap (l();<RETURN>
inoremap (" ("")<LEFT><LEFT>
inoremap (' ('')<LEFT><LEFT>
inoremap (;();<DOWN>
inoremap) <Esc><RIGHT>:call CloseChar()<cr>i
inoremap [ []
inoremap [h []<LEFT>
inoremap ] <Esc><RIGHT>:call CloseChar()<cr>i
inoremap { {}
inoremap {h {}<LEFT>
inoremap {<RETURN> {<RETURN><TAB><RETURN><BACKSPACE>}<UP><TAB>
inoremap } <Esc><RIGHT>:call CloseChar()<cr>i
inoremap " ""
inoremap "h ""<LEFT>
inoremap "l "";<RETURN>
inoremap ' ''
inoremap 'h ''<LEFT>
inoremap 'l '';<RETURN>
function! CloseChar()
if matchstr(getline('.'), '\%' . col('.') . 'c.') =~# '\v\)|]|"|''|}'
normal! l
endif
endfunction
ありがとうございました。これは私にとって完璧に機能します。 – CMason8856
お手伝いします! –