From 956b15428acbf93687e9e1f464b7a2c7ed4e4a03 Mon Sep 17 00:00:00 2001 From: JamshedVesuna Date: Sun, 13 Dec 2015 13:28:03 -0800 Subject: [PATCH] Added xdg-open support --- README.md | 13 +++++++++++++ plugin/vim-markdown-preview.vim | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 37c5a41..0e2c13b 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Vim Markdown Preview - [Browser](#browser) - [Temp File](#temp) - [Github Flavoured Markdown](#github) + - [Use xdg-open](#xdg) - [Behind the Scenes](#behind-the-scenes) Intro @@ -137,6 +138,18 @@ Example: Use GitHub flavoured markdown. let vim_markdown_preview_github=1 ``` + +### The `vim_markdown_preview_use_xdg_open` option + +If your system does not come with `see`, and you would like to use `xdg-open` to view your rendered html in the browser, set the following flag: + +Default: `0` + +Example: Use `xdg-open`. +```vim +let vim_markdown_preview_use_xdg_open=1 +``` + Behind The Scenes ----------------- diff --git a/plugin/vim-markdown-preview.vim b/plugin/vim-markdown-preview.vim index 6129d38..622b774 100644 --- a/plugin/vim-markdown-preview.vim +++ b/plugin/vim-markdown-preview.vim @@ -19,6 +19,10 @@ if !exists("g:vim_markdown_preview_github") let g:vim_markdown_preview_github = 0 endif +if !exists("g:vim_markdown_preview_use_xdg_open") + let g:vim_markdown_preview_use_xdg_open = 0 +endif + if !exists("g:vim_markdown_preview_hotkey") let g:vim_markdown_preview_hotkey='' endif @@ -49,7 +53,11 @@ function! Vim_Markdown_Preview() if OSNAME == 'unix' let chrome_wid = system("xdotool search --name 'vim-markdown-preview.html - " . g:vim_markdown_preview_browser . "'") if !chrome_wid - call system('see /tmp/vim-markdown-preview.html &> /dev/null &') + if g:vim_markdown_preview_use_xdg_open == 1 + call system('xdg-open /tmp/vim-markdown-preview.html &> /dev/null &') + else + call system('see /tmp/vim-markdown-preview.html &> /dev/null &') + endif else let curr_wid = system('xdotool getwindowfocus') call system('xdotool windowmap ' . chrome_wid) @@ -98,7 +106,11 @@ function! Vim_Markdown_Preview_Local() if OSNAME == 'unix' let chrome_wid = system("xdotool search --name '". curr_file . ".html - " . g:vim_markdown_preview_browser . "'") if !chrome_wid - call system('see ' . curr_file . '.html &> /dev/null &') + if g:vim_markdown_preview_use_xdg_open == 1 + call system('xdg-open /tmp/vim-markdown-preview.html &> /dev/null &') + else + call system('see /tmp/vim-markdown-preview.html &> /dev/null &') + endif else let curr_wid = system('xdotool getwindowfocus') call system('xdotool windowmap ' . chrome_wid) -- 2.45.2