JamshedVesuna / vim-markdown-preview

A light Vim plugin for previewing markdown files in a browser - without leaving Vim.
577 stars 91 forks source link

Opens new tab when called on Ubuntu 16 with firefox #68

Open Vitruvia opened 7 years ago

Vitruvia commented 7 years ago

I have firefox as the standard browser (it is what came installed in the distro), and whenever I do a new tab opens. How can I fix this?

JamshedVesuna commented 7 years ago

We still need to add Firefox as a supported browser. If you are on linux, xdotool should be refreshing the tab instead of creating a new one. You can try manually creating the html file then calling xdotool to see if its a system problem.

Vitruvia commented 7 years ago

Calling xdotool by hand using the way you pointed doesn't cause anything to happen (I was inside the folder with the markdown-preview.html.

I have installed chrome and I still get a new tab when using . Addionally, both in chrome and firefox my code blocks and bullet points don't render (they appear raw, as typed in the document).

pylipp commented 7 years ago

The issue is that xdotool does not find the browser window that already displays the html file because it searches for the wrong title.

I implemented a workaround by setting the html title when creating the html and make xdotool explicitely search for it when updating/displaying the html. Check out the fork here. I can submit a PR if it works for you.

Remember to set vim_markdown_preview_browser='firefox' in your vimrc.

HTH :)!

JamshedVesuna commented 7 years ago

@pylipp a PR for firefox would be great!

Vitruvia commented 7 years ago

@pylipp How can I test your version of the plugin using Vundle? I copied Plugin 'https://github.com/pylipp/vim-markdown-preview/tree/bugfix/firefox' into my plugin section at .vimrc but it won't install.

pylipp commented 7 years ago

@Vitruvia Maybe this helps? I'm using vim-plug myself for plugin management.

Vitruvia commented 7 years ago

@pylipp Thanks! Unfortunately, following the steps you pointed out didn't fix the issue for me.

pylipp commented 7 years ago

Mmh a hack I can think of is to leave your vimrc untouched and go to the plugin directory instead (something like ~/.vim/bundle/vim-markdown-preview). There you add my fork as a new remote and checkout the firefox branch:

git remote add pylipp https://github.com/pylipp/vim-markdown-preview
git checkout -b bugfix/firefox pylipp/bugfix/firefox

Then you should be on the correct branch. However, this is probably going to be overwritten when you update the original plugin from within vim.

gundamlh commented 6 years ago

Dear friends,

Problem Solved, I missed the following setting:

let vim_markdown_preview_github=1

Many thanks!


Dear friends,

Although I've installed

the plug-in, yet, doesn't work. I am a bit frustrated. Could you be kind to lend me a hand? Any tip are highly appreciated.

➜ vim-markdown-preview git:(master) ✗ ls plugin README.md ➜ vim-markdown-preview git:(master) ✗ ls plugin applescript vim-markdown-preview.vim vim-markdown-preview.vim.bak ➜ vim-markdown-preview git:(master) ✗ xdotool --version xdotool version 3.+20171213.1 ➜ vim-markdown-preview git:(master) ✗ sudo update-alternatives --config x-www-browser [sudo] password for lh: There is only one alternative in link group x-www-browser (providing /usr/bin/x-www-browser): /usr/bin/firefox Nothing to configure. ➜ vim-markdown-preview git:(master) ✗ sudo update-alternatives --config gnome-www-browser There is only one alternative in link group gnome-www-browser (providing /usr/bin/gnome-www-browser): /usr/bin/firefox Nothing to configure. ➜ vim-markdown-preview git:(master) ✗ pwd /home/lh/.vim/bundle/vim-markdown-preview ➜ vim-markdown-preview git:(master) ✗ lsb_release -r Release: 14.04

copyme commented 6 years ago

@pylipp I also did not manage to use firefox with your modifications. In my init.vim I have

Plug 'pylipp/vim-markdown-preview', { 'branch': 'bugfix/firefox' } let g:vim_markdown_preview_perl = 1 let g:vim_markdown_preview_browser = 'firefox'

pylipp commented 6 years ago

Can you specify the system you are running? Is the plugin installed correctly (can you check the installation folder and run git remote -v)? Is see installed on your system and configured correctly (to use firefox as default browser - side note: this kinda makes the vim_markdown_preview_browser setting redundant, still have to change that on my branch)? Is xdotool installed? Does it work with a different browser? Is it that your mapping does not work? What happens if you run :call Vim_Markdown_Preview() in an open markdown file?

pylipp commented 6 years ago

Are you using NeoVim? I never tested the plugin or the firefox-branch there. Maybe that's an issue.

copyme commented 6 years ago

@pylipp One thing before I will answer. To which project exactly do you refer by see? Are we talking about the Python module or what? Google is not so helpful here.

pylipp commented 6 years ago

see is a program provided by the mime-support package. Can you manually open the html file generated by vim-markdown-preview with see /tmp/vim-markdown-preview.html?

pylipp commented 6 years ago

I think this also requires a ~/.mailcap file with the contents like

    text/html; /usr/bin/firefox %s; description=HTML Text; test=test -n "$DISPLAY";  nametemplate=%s.html

And maybe setting the environment variable $BROWSER=/usr/bin/firefox. Sorry for not being specific here, I think I once added a bunch of stuff to my system config and at some point it worked and has been ever since ;)... HTH!

copyme commented 6 years ago

@pylipp Well, but this is a Debian related package, and as I see it is an alias on mailcap. Cannot you simply drop see in favor of something standard like xdg-open? As I see Fedora still provides mailcap but right now it internally calls xdg-open, while openSUSE which I use does not provide anymore mailcap.

I set thevim-markdown-preview option to use xdg-open but then it does not really work as it should i.e., a new tab is open each time I want to refresh a markdown file preview.

pylipp commented 6 years ago

Regarding the new tab being opened: Did the browser tab displaying the preview lose focus between two calls to Vim_Markdown_Preview()? xdotool is then unable to find the browser tab and asks the browser to open the preview html again, resulting in a new tab.

If you don't want to use xdg-open or mailcap, you could hardcode the browser executable in the source code.

DmitrySandalov commented 6 years ago

I was able to get tabs refreshing on Ubuntu 16 with firefox with the following steps:

  1. sudo apt install markdown xdotool
  2. Launch the command below and make your browser's window active (just click on your browser after launching) $ sleep 3; xdotool getwindowfocus getwindowname Output: Opens new tab when called on Ubuntu 16 with firefox · Issue #68 · JamshedVesuna/vim-markdown-preview - Mozilla Firefox
  3. Use the exact browser name in .vimrc let vim_markdown_preview_browser='Mozilla Firefox'
pylipp commented 6 years ago

@DmitrySandalov Thanks for investigating :) What version of firefox are you using? I think that makes a difference in how Firefox builds the tab title.

DmitrySandalov commented 6 years ago

@pylipp

pylipp commented 6 years ago

@DmitrySandalov let vim_markdown_preview_browser='Mozilla Firefox' is the key. (on master, with a recent version of firefox). This also makes #70 unnecessary. Though I can remember that back at that time my firefox was not appending 'Mozilla Firefox' to the browser tab title. Anyways I mostly use qutebrowser these days^^