M README.md => README.md +19 -5
@@ 1,16 1,30 @@
Vim Markdown Preview
====================
-Vim plugin for previewing markdown files in a browser.
+A vim plugin for previewing markdown files in a browser. This plugin was designed to maintan focus on vim but use Google Chrome to preview rendered markdown. Thus, everything is done in the background so you never have to leave vim.
Installation
============
-1. With Pathogen: Place `vim-markdown-preview/` in `.vim/bundle/`
+1. With Pathogen: Place `vim-markdown-preview/` in `.vim/bundle/`.
+
+Requirements
+============
+* [Markdown](http://daringfireball.net/projects/markdown/)
+* [xdotool](https://github.com/jordansissel/xdotool)
+* [Google Chrome](https://www.google.com/chrome/browser/)
Usage
=====
+When in a *.markdown or *.md file, vim-markdown-preview maps `Ctrl-p` as follows:
+
+* If you are not previewing the current file:
+ * Open an html rendered version of your file in Google Chrome in the background.
+* Otherwise:
+ * Refresh your preview of the current markdown file in Google Chrome.
-* When the current buffer is *.markdown or *.md, Vim Markdown Preview maps `Ctrl-p` to open the buffer in the default system browser as html.
-* Vim Markdown Preview creates a temporary file vim-markdown-preview.html in /tmp/ and removes it after opening it in a browser so nothing is left behind.
-* Further, Vim Markdown Preview opens the browser in the background, which allows you to maintain focus on vim.
+Behind The Scenes
+=================
+1. First, vim-markdown-preview renders your markdown as html and creates a temporary file `vim-markdown-preview.html` in `/tmp/`.
+2. Next, vim-markdown-preview then either opens the html file or refreshes the Google Chrome tab.
+3. Lastly, vim-markdown-preview removes the temporary file so nothing left behind.
M plugin/vim-markdown-preview.vim => plugin/vim-markdown-preview.vim +15 -4
@@ 4,10 4,21 @@
"============================================================
function! Vim_Markdown_Preview()
- :let curr_file = expand('%:t')
- :call system('markdown ' . curr_file . ' > /tmp/vim-markdown-preview.html' . ' && open -g /tmp/vim-markdown-preview.html')
- :sleep 314m
- :call system('rm /tmp/vim-markdown-preview.html')
+ let curr_file = expand('%:t')
+ call system('markdown ' . curr_file . ' > /tmp/vim-markdown-preview.html')
+ let chrome_wid = system("xdotool search --name 'vim-markdown-preview.html - Google Chrome'")
+ sleep 31m
+ if !chrome_wid
+ call system('see -g /tmp/vim-markdown-preview.html')
+ else
+ let curr_wid = system('xdotool getwindowfocus')
+ call system('xdotool windowmap ' . chrome_wid)
+ call system('xdotool windowactivate ' . chrome_wid)
+ call system("xdotool key 'ctrl+r'")
+ call system('xdotool windowactivate ' . curr_wid)
+ endif
+ sleep 31m
+ call system('rm /tmp/vim-markdown-preview.html')
endfunction
autocmd Filetype markdown,md map <buffer> <C-p> :call Vim_Markdown_Preview()<CR>