From 6f05ab3cf602ac31a3ece575509a704b32406560 Mon Sep 17 00:00:00 2001 From: Jamshed Vesuna Date: Tue, 26 Aug 2014 16:47:31 -0700 Subject: [PATCH] Added on write to buffer trigger --- README.md | 6 ++++-- plugin/vim-markdown-preview.vim | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b791a6c..77b23e2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Vim Markdown Preview ==================== -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. +A Vim plugin for previewing markdown files in a browser. This plugin was designed to maintain 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 ============ @@ -16,13 +16,15 @@ Requirements Usage ===== -When in a *.markdown or *.md file, vim-markdown-preview maps `Ctrl-p` as follows: +When in a *.markdown or *.md file, vim-markdown-preview does the following on a write to the buffer: * 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. +Uncomment the last line in `plugin/vim-markdown-preview.vim` to map `Ctrl-p` to the above instead of on write. + Behind The Scenes ================= 1. First, vim-markdown-preview renders your markdown as html and creates a temporary file `vim-markdown-preview.html` in `/tmp/`. diff --git a/plugin/vim-markdown-preview.vim b/plugin/vim-markdown-preview.vim index 53df45f..77e1bc4 100644 --- a/plugin/vim-markdown-preview.vim +++ b/plugin/vim-markdown-preview.vim @@ -7,7 +7,7 @@ function! Vim_Markdown_Preview() 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 + sleep 300m if !chrome_wid call system('see -g /tmp/vim-markdown-preview.html') else @@ -21,4 +21,5 @@ function! Vim_Markdown_Preview() call system('rm /tmp/vim-markdown-preview.html') endfunction -autocmd Filetype markdown,md map :call Vim_Markdown_Preview() +autocmd BufWritePost *.markdown,*.md :call Vim_Markdown_Preview() +"autocmd Filetype markdown,md map :call Vim_Markdown_Preview() -- 2.45.2