将文件转换为html到位

时间:2015-08-28 04:06:36

标签: linux vim

TOHtml可用于将文件转换为html,但它也会创建一个新文件。例如,如果原始文件名是test,则vim将创建一个名为test.html的新文件。

是否有方法可以修改文件,即只将test转换为html,而不是创建新文件?

1 个答案:

答案 0 :(得分:4)

:TOhtml创建一个新的缓冲区。它不保存它,因此它不会创建新的文件。你可以利用这个事实:

" create test.html buffer
:TOhtml
" change back to test buffer
:b test
" destroy it, because we can't save another buffer with this name
" while this one is open
:bd
" switch back to test.html (if you had no other buffers, this is likely unnecessary)
:b test.html
" save it, overwriting the original
:w test

编辑:我认为这样做会更短,但仍然会这样做:

:TOhtml
:bd test
:w test