├── plugin ├── cssrefresh.vim └── cssrefresh.sh └── README.md /plugin/cssrefresh.vim: -------------------------------------------------------------------------------- 1 | function! s:CRefresh() 2 | let paths = substitute(escape(&runtimepath, ' '), '\(,\|$\)', '/**\1', 'g') 3 | let cmd = findfile('cssrefresh.sh', paths) 4 | 5 | let fn = expand("%:t:r") 6 | let cmdline = cmd . ' ' . fn 7 | exec '!' . cmdline . ' 2>&1 >/dev/null' 8 | endfunction 9 | 10 | function! s:CAutoRefresh() 11 | autocmd! bufwritepost *.less,*.css,*.sass,*.scss CRefresh 12 | endfunction 13 | 14 | com! CRefresh call s:CRefresh() 15 | com! CAutoRefresh call s:CAutoRefresh() 16 | 17 | " By default, autorefresh is always on. 18 | " Comment this out to disable that; you can type :CAutoRefresh to start it 19 | " again later. 20 | " 21 | call s:CAutoRefresh() 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CSS Refresher for VIM 2 | ===================== 3 | 4 | Reloads the CSS files of the current Safari tab everytime a .css file is saved. 5 | 6 | Usage 7 | ----- 8 | 9 | - Install this VIM plugin using pathogen. 10 | (alternatively, just copy the files to `~/.vim/plugin`) 11 | 12 | - Open your project in Safari. Make sure it's the front-most tab. 13 | 14 | - Open a CSS file in that project in VIM. 15 | 16 | - Make a few changes and save it. 17 | 18 | - Watch as Safari refreshes your CSS changes! 19 | 20 | Assumptions 21 | ----------- 22 | 23 | - You're using a Mac (relies on AppleScript); and 24 | 25 | - Your browser of choice is Safari. 26 | 27 | Caution: This is a quick and dirty hack, use at your own risk! 28 | 29 | -------------------------------------------------------------------------------- /plugin/cssrefresh.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | osascript -s o << END 3 | tell application "Safari" 4 | do JavaScript " 5 | (function(\$) { 6 | var spec = '$1'; 7 | var updater = { 8 | el: null, 9 | init: function () { 10 | if (this.el) { this.el.remove(); } 11 | this.el = \$('