Emprego.curitiba (talk | contribs) No edit summary |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 15: | Line 15: | ||
===The bad old way=== |
===The bad old way=== |
||
You are probably all too familiar with this annoying mini-workflow: |
You are probably all too familiar with this annoying mini-workflow: |
||
− | *Edit your HTML/ |
+ | *Edit your HTML/CSS file. |
*Hit save in Vim. |
*Hit save in Vim. |
||
− | * |
+ | *CMD/CNTRL/ALT + TAB over to Firefox. |
*Press Ctrl-R in Firefox to refresh. |
*Press Ctrl-R in Firefox to refresh. |
||
− | * |
+ | *CMD/CNTRL/ALT + TAB back to Vim. |
*Do it again and again, wincing a little bit each time. |
*Do it again and again, wincing a little bit each time. |
||
Line 88: | Line 88: | ||
==Comments== |
==Comments== |
||
+ | Excellent! Needed something to replace LiveReload on my Linux workstation at work. This did the trick. Thanks. |
||
− | <div style="margin-left:-9999px;">[http://www.vipsexshop.com.br Sex Shop][http://www.requintesexshop.com.br Sex Shop][http://www.sexshop.com.vc Sex Shop][http://www.belasexshop.com.br Sex Shop][http://www.belasexshop.com Sex Shop][http://blog.vipsexshop.com.br Dicas de Sexo][http://www.viplingerie.com.br Lingerie][http://www.vipcalcinhas.com.br Calcinhas][http://www.uniformesbr.com Uniformes Profissionais][http://www.uniformesbr.com Uniformes]</div> |
Revision as of 16:38, 27 November 2013
created June 15, 2010 · complexity basic · author A generic person · version 7.0
Editing HTML in Vim is a lot nicer if you can see updates in Firefox without needing to remove your hands from the keyboard. With MozRepl and a little vimrc script, you can do just that!
The bad old way
You are probably all too familiar with this annoying mini-workflow:
- Edit your HTML/CSS file.
- Hit save in Vim.
- CMD/CNTRL/ALT + TAB over to Firefox.
- Press Ctrl-R in Firefox to refresh.
- CMD/CNTRL/ALT + TAB back to Vim.
- Do it again and again, wincing a little bit each time.
The joyful new Vim + MozRepl way
With the little vimrc + MozRepl hack shown below, all you need to do is:
- Edit your HTML/css file.
- Hit save in Vim – Firefox will refresh automatically, preserving its scroll offsets!
This integration is no where near as fancy as the Emacs MozRepl binding, but this one feature makes it super useful.
Vim + MozRepl
When editing an .html,.css, or .gtpl file, make Firefox refresh after the buffer is saved, preserving the current scroll offset.
Requires
- MozRepl must be installed and running in Firefox
- Netcat (nc) must be on your path.
- Firefox and Vim are both on the same machine (localhost).
How it works
I use echo + netcat (nc) to send a dopey little MosRepl script (see below) to Firefox. All the output is tossed away (2>&1 > /dev/null) because MozRepl is chatty.
Global variables are used (vimXo, vimYo) to capture the X,Y offset of the web page for Vim. Maybe there's a way to not use a global, but I don't know what that might be. After saving the buffer and reloading the browser, scroll to the X,Y offset.
See also:
- http://wiki.github.com/bard/mozrepl/tutorial
- http://forums.whirlpool.net.au/forum-replies-archive.cfm/495300.html
Code for vimrc
autocmd BufWriteCmd *.html,*.css,*.gtpl :call Refresh_firefox() function! Refresh_firefox() if &modified write silent !echo 'vimYo = content.window.pageYOffset; \ vimXo = content.window.pageXOffset; \ BrowserReload(); \ content.window.scrollTo(vimXo,vimYo); \ repl.quit();' | \ nc -w 1 localhost 4242 2>&1 > /dev/null endif endfunction
- added "-w 1" flag to netcat to solve occasional hung connections
A few additions
To put in vimrc:
command! -nargs=1 Repl silent !echo \ "repl.home(); \ content.location.href = '<args>'; \ repl.enter(content); \ repl.quit();" | \ nc localhost 4242 nmap <leader>mh :Repl http:// " mnemonic is MozRepl Http nmap <silent> <leader>ml :Repl file:///%:p<CR> " mnemonic is MozRepl Local nmap <silent> <leader>md :Repl http://localhost/ " mnemonic is MozRepl Development
Now, when working on local html files, if you switch files often then just press <leader>ml and the file is shown in Firefox. Also, <leader>mh will bring you to ex mode where you can type in a URL and go there in Firefox etc.
See also
Comments
Excellent! Needed something to replace LiveReload on my Linux workstation at work. This did the trick. Thanks.