2016-08-02 7 views

答えて

2

が安全にこれを行うには、レジスタの内容だけでなく、復元する必要があるが、また、その種類:あなたの中finally`ゾーン:

let old_reg = getreg("a")    " Save the current content of register 'a' 
let old_reg_type = getregtype("a")  " Save the type of the register as well 

" <Use the register 'a' as a temporary scratch pad here> 

call setreg("a", old_reg, old_reg_type) " Restore register 'a' 
+2

は 'から' setreg'を呼び出すことを忘れないでください。失敗する可能性のある操作を呼び出す場合に備えて機能します。 –

+0

ありがとうございます。私が見つけた最良の例は、コードの最後の部分です:http://vimhelp.appspot.com/usr_41.txt.html#41.9 あなたがもっと良いものを見つけたら教えてください! –

+0

さて、私は本当に「何か良い」とは言えませんが、ちょうどその場合には、[lh-vim-lib](https://github.com/LucHermitte/lh-vim-lib)で、 ['lh#on exit()'](https://github.com/LucHermitte/lh-vim-lib/blob/74e378709c558c1a5b54f1e8d811dcd386f3109a/doc/lh-vim-lib.txt#L283)は、クリーンアップと復元を目的とした機能ですセミオートマチックしかし、 'getregtype()'は使用しません。なぜなら、私はその(最近の)存在を認識していなかったからです。 –

関連する問題