Skip to content

Instantly share code, notes, and snippets.

@iheitlager
Last active August 29, 2015 14:12
Show Gist options
  • Save iheitlager/46cb7cb3d7e0d30fc98b to your computer and use it in GitHub Desktop.
Save iheitlager/46cb7cb3d7e0d30fc98b to your computer and use it in GitHub Desktop.
Refresh Chrome from vi

In osx, there is a scripted way to refresh Chrome:

osascript -e 'tell application "Google Chrome" to reload active tab of window 1';

You can use this to refresh Chrome from vi, by mapping it to e.g. <F4>. Put this in your .vimrc

:map <F4> :! osascript -e 'tell application "Google Chrome" to reload active tab of window 1';<CR><CR>

The ! after the colon is to execute a shell script. The <CR><CR> is to automate vi further. If you do this you might find there is still an annoying "Press ENTER or type command to continue" message when closing the browser. Just add a silent and a redraw (somehow the screen screws up after a silent) and you are good to go.

:map <F4> :silent !osascript -e 'tell application "Google Chrome" to reload active tab of window 1';<CR><CR> :redraw!<CR>

Now you never have to leave the keyboard again! The inspiration came from here: http://www.dragdropsite.com/tutorials/auto-refresh-browser-after-code-change-using-automator/ and it is now part of my dotfiles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment