当我在MacVim中编写html时,我会在网页浏览器中打开同一文件,以便检查html输出。我不喜欢这种方法的其中一个原因是我不得不经常离开vim,去到浏览器中重新加载html才能看到更新。有没有更优雅的vim解决方案,可以在输入vim时动态更新html输出?我记得Textmate可以做到这一点?谢谢。
更新: 我找到了我想要记住的视频。您可以在此处找到它:
更新: 我找到了我想要记住的视频。您可以在此处找到它:
" Refresh WebKit
nnoremap \r :Refresh<CR>
command! Refresh call RefreshWebKit()
function! RefreshWebKit()
silent !osascript -e 'tell application "WebKit"'
\ -e ' set p_url to URL of current tab of front window'
\ -e ' set URL of current tab of front window to p_url'
\ -e 'end tell'
endfunction
:Refresh
来完成相同的操作。\r
,请使用您感到舒适的任何内容。-e
选项只是为了可读性。按照您想要的方式执行即可。
还可以查看自动命令(请参阅:h autocmd.txt)。这将让您以更自动化的方式完成操作,例如:
:autocmd BufWrite *.html Refresh
:Refresh
。还有插入文本等事件。<meta http-equiv="refresh" content="15" />
我喜欢使用低技术方案解决高技术问题,所以我实际上使用了meta标签,但sidyll的解决方案似乎非常出色。
我使用 (osx) kicker ruby gem,它会在文件更改时自动运行:
kicker -e "osascript -e 'tell application \"WebKit\" to do JavaScript \"window.location.reload()\" in first document'"
或者将其放入 .kick 文件中,以便更好地控制哪些文件应该触发它和/或执行更多操作:
process do |files|
unless files.grep(/\.(html|css|js)$/).empty?
execute("osascript -e 'tell application \"WebKit\"
do JavaScript \"window.location.reload()\" in first document
end tell'")
end
end