Tip #127: Preview HTML files quickly
tip karma |
Rating 3/11, Viewed by 2349
|
created: |
|
October 4, 2001 8:28 |
|
complexity: |
|
basic |
author: |
|
Jamis Buck |
|
as of Vim: |
|
6.0 |
I've found while writing HTML files that it can become cumbersome when I have to switch to a web browser, load my page, and move back to VIM regularly to preview what I've written. I've come up with the following tricks.
The first one requires that you have lynx (the text-based browser) installed on your computer (available from http://lynx.isc.org/release/). If your HTML page is primarily text, with few (if any) images, you can set up the following function and mapping:
function PreviewHTML_TextOnly()
let l:fname = expand("%:p" )
new
set buftype=nofile nonumber
exe "%!lynx " . l:fname . " -dump -nolist -underscore -width " . winwidth( 0 )
endfunction
map <Leader>pt :call PreviewHTML_TextOnly()<CR>
This will open a new window and display your formatted HTML document in that window. Note that bold-face, italics, links, etc. will be lost -- all you will see is the text -- but the "-underscore" parameter to Lynx causes any text that would have been bold, italicized, or underlined to be displayed like _this_.
The other trick requires that vim be running on your current machine, and that you be running a GUI of some sort (X-Windows, Windows, etc.). You can cause vim to invoke your favorite browser and have it display the file, like this:
function PreviewHTML_External()
exe "silent !mozilla -remote \"openurl(file://"; . expand( "%:p" ) . ")\""
endfunction
map <Leader>pp :call PreviewHTML_External()<CR>
If you don't use mozilla, you will need to modify the function to use your preferred browser.
Happy vimming!
<<how do I get rid of that bold stuff with my xterm? |
grep, diff, patch, idutils, etc. for Windows systems >>
Additional Notes
|