当我在 MacVim 中编写 html 时,我会在 Web 浏览器中保持同一文件打开,以便可以检查 html 输出。我不喜欢这种方法的一件事是我经常需要离开 vim,转到浏览器,然后重新加载 html 才能看到更新。 vim 是否有更优雅的解决方案,可以在 vim 中输入时动态更新 html 输出?我记得Textmate好像可以做到这一点?谢谢。
更新:
我找到了我试图记住的视频。您可以在这里找到它:
http://files.fletcherpenney.net/TextMate-Preview.mov
When I write html in MacVim I keep the same file open in a web browser so that I can examine the html output. One of the things I dislike about this method is that I constantly have to leave vim, go to the browser, and reload the html to see the updates. Is there a more elegant solution with vim that will dynamically update html ouput as it is typed in vim? I seem to recall that Textmate could do this? Thanks.
UPDATE:
I found the video I was trying to remember. You can find it here:
http://files.fletcherpenney.net/TextMate-Preview.mov
发布评论
评论(3)
将其添加到您的 .vimrc 中:
这将创建一个映射、一个命令和一个函数。我本可以加入他们,但是
这样就更清晰了,我可以在其他地方重用该功能。
该函数调用一点 AppleScript 来再次设置最前面选项卡的 URL,
从而令人耳目一新。这将在 Safari 和 WebKit 下工作,但我不能
保证它可以与其他浏览器一起使用。如果没有,谷歌“刷新{浏览器}
applescript”并使用不同的脚本。
地图只调用命令,命令调用函数。所以你可以编写你的
文件并使用它来刷新浏览器而无需离开 Vim。同样,使用
:Refresh
执行相同的操作。请注意,您可能想要更改一些内容:
\r
,使用您觉得舒服的任何内容。功能
WebKit 本身。使用 Chrome、Firefox 或任何其他名称(带有各自的
更改)
快速说明:传递给程序的额外
-e
选项只是为了方便的可读性。按照你想要的方式去做。
还可以查看自动命令(检查 :h autocmd.txt)。这会让你
以更自动化的方式执行此操作,例如:
每次为 .html 文件编写缓冲区时,都会调用
:Refresh
。那里还有插入文本等事件。
Add this to your .vimrc:
This will create a map, a command and a function. I could have joined them, but
this way it it's more clear and I can reuse the function in other places.
The function calls a little AppleScript to set the URL of frontmost tab again,
thus refreshing it. This will work under Safari and WebKit, but I can't
guarantee that it works with other browsers. If not, google "refresh {browser}
applescript" and use a different script.
The map just calls the command, which calls the function. So you can write your
file and use it to refresh the browser without leaving Vim. Equally, use
:Refresh
to do the same.Note that you may want to change some things:
\r
, use whatever you feel comfortable with.functions
of WebKit itself. Use Chrome, Firefox, or any other name (with the respective
changes)
A quick note: the extra
-e
options passed to the program are just for the sakeof readability. Do it in the fashion you want.
Take a look also in auto-commands (check :h autocmd.txt). This will let you
do it in a more automatized way like:
This will call
:Refresh
every time you write a buffer for .html files. Thereare also events for inserted text and so on.
我已经看到了很多方法来做到这一点:
或简单的元标记:
我喜欢用低技术解决高科技问题,所以我实际上使用元标记,但 sidyll 的解决方案似乎很棒。
I've seen a bunch of ways to do that:
or a simple meta tag:
I like lo-tech solutions to hi-tech problems so I actually use the meta tag but sidyll's solution seems excellent.
我使用 (osx) kicker ruby gem 它会在文件更改时自动运行:
或者将其粘贴在 .kick 中文件以更好地控制哪些文件应该触发它和/或更多操作:
I use the (osx) kicker ruby gem which automatically runs on file changes:
Or stick it in a .kick file for more control over which files should trigger it and/or more actions: