Git Product home page Git Product logo

vim-markdown-preview's Introduction

Vim Markdown Preview

Intro

A small Vim plugin for previewing markdown files in a browser.

The aim of this plugin is to be light weight with minimal dependencies. Thus, there is no polling engine or webserver involved.

Screenshot

Installation

  • With Pathogen: Place vim-markdown-preview/ in .vim/bundle/.
  • With Vundle:
    • Add Plugin 'JamshedVesuna/vim-markdown-preview' to your .vimrc.
    • Launch vim and run :PluginInstall

See more Options.

Usage

By default, when in a .markdown or .md file, and Ctrl-p is pressed, this plugin will either open a preview in your browser, or refresh your current preview (can be remapped, see Options).

Your cursor will remain in Vim.

Requirements

Mac OS X:

Unix:

It is recommended to use grip when rendering Unicode characters.

Options

All options have default values and work out of the box. If you prefer to change these, just add the following lines to your .vimrc file. Note that after changing an option, you have to restart Vim for the change to take effect.

The vim_markdown_preview_toggle option

This option does two things (to be fixed by #17):

  1. Display images in the preview
  2. Generate preview on buffer write (Example: on :w)

There are a total of four values (0, 1, 2, 3) this option can take.

Default: 0, which maps Control p (not a buffer write) to generating the preview and does not display images.

Example: To display images with the hotkey mapping (defaults to Control p).

let vim_markdown_preview_toggle=1

Example: To display images automatically on buffer write.

let vim_markdown_preview_toggle=2

Example: To disregard images and still automatically preview on buffer write.

let vim_markdown_preview_toggle=3

The vim_markdown_preview_hotkey option

By default, this plugin maps <C-p> (Control p) to activate the preview. To remap Control p to a different hotkey, change the binding. Don't forget to add the single quotation marks.

Default: '<C-p>'

Example: Mapping Control M.

let vim_markdown_preview_hotkey='<C-m>'

The vim_markdown_preview_browser option

By default, if you are using Unix, Google Chrome is the default browser. If you are on Mac OS X, Safari is the default. Note that bug #16 does not allow cross operating system and browser support. See the wiki page for more help.

Default: 'Google Chrome'

Example: Using Google Chrome.

let vim_markdown_preview_browser='Google Chrome'

The vim_markdown_preview_temp_file option

By default, this plugin keeps the rendered .html file. If you would automatically like to remove the html file after opening it in a browser, set this option to 1. Note that removing the rendered html file with a slow browser may err.

Default: 0

Example: Remove the rendered preview.

let vim_markdown_preview_temp_file=1

The vim_markdown_preview_github option

If you prefer GitHub flavoured markdown you need to install Python grip. Note that this makes a request to GitHub's API (causing latencies) and may require authentication. This option also requires a network connection.

Default: 0

Example: Use GitHub flavoured markdown.

let vim_markdown_preview_github=1

The vim_markdown_preview_perl option

If you prefer to use John Gruber's Markdown.pl to render HTML, set the following flag:

Default: 0

Example: Use Markdown.pl to render HTML.

let vim_markdown_preview_perl=1

The vim_markdown_preview_pandoc option

If you prefer to use John MacFarlane's Pandoc to render HTML, set the following flag:

Default: 0

Example: Use Pandoc to render HTML.

let vim_markdown_preview_pandoc=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.

let vim_markdown_preview_use_xdg_open=1

Behind The Scenes

  1. First, this plugin renders your markdown as html and creates a temporary html file.
  2. Next, this plugin either opens the html file or refreshes the Google Chrome or Safari tab.
    • If you are using GitHub flavoured markdown, grip will make a call to the GitHub API and retrieve the html.
  3. Lastly, if you choose, this plugin will remove the temporary file.

vim-markdown-preview's People

Contributors

bikenomad avatar devzeebo avatar gmerzu avatar jamshedvesuna avatar m4ce avatar oshybystyi avatar twsh avatar wadey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-markdown-preview's Issues

New tab opened if a different tab is active in the browser

Can you please add this info somewhere that if a tab other than vim-markdown-preview.html is active(maybe the wrong word) in the browser, then xdotool won't be able to find the browser window and the plugin will open a new tab. It might confuse some people(including me) wondering why are multiple tabs opening sometimes.

Internal Server Error

Here's my situation.
I'm on windows using MobaXterm to connect remote Ubuntu 16.04 server.
MobaXterm forward browser window to my computer with X11 forwarding .
The first press of <ctrl + p> functions normally.
However, whenever I press <ctrl + p> again trying to refresh the content, new tab opened and shows this
image

Can this be fixed?
Thank for your help.

Fix browser option + OS combinations

Currently, the workflow is routed by operating system, whereas it should be by both os and browser.

Example: on OS X and want to use Google Chrome.

Documentation update/Problem with .md files

Had a problem with this wonderful plugin.
The Ctrl-p hotkey only worked on .markdown and README.md files but never on any other .md file e.g. readme.md.
After looking around I found out that the only valid .md file is README.md according to Vim's filetypes.vim, see here.
Maybe you could update your documentation to tell users about it because it really gave me headaches why hotkey wasn't working for me:

"By default, when in a .markdown or .md file, and Ctrl-p is pressed, this plugin will either open a preview in your browser, or refresh your current preview (can be remapped, see Options). ..."

/tmp/vim-markdown-preview.html was empty

I'm sorry, my english was terrible, i hope you will understand what i saying
i have done all things what the README wants me to do, but when i press ctrl-p , the page was empty
image

i use lubuntu 16.04 and chromium

Support tag page reloading

If a relative link tag is clicked when testing, the url updates with the tag (ie blah/#some-tag). Now, when the plugin searches URLs for the path, it will mismatch.

Fix: Search for the string subset (as to not include the tag)

How do I remap to a different key besides ctrl-p

In the documentation you mention the comment below. When I checked the installation section I did not see anything about remapping the key. Thanks in advance!

When in a *.markdown or *.md file, vim-markdown-preview does the following when you type Ctrl-p (can be remapped, see Installation):

Nearly Working on Ubuntu 14.04

Hi

Continuation from previous bug report.

I am trying to use the local markdown, but it just produces empty files, no content. Web browser opens etc, just a blank page.

If I use

let vim_markdown_preview_github=1

it then works.

call system('see /tmp/vim-markdown-preview.html &> /dev/null &')

Does nothing. With the github=1 option then it works.

System info:
markdown-2.6.5
Vim 7.4.52
Zsh shell

All requirements are met (as far as I know). I have got Python 2 and 3 on this comp, not sure if that confuses anything.

Blank page on Mac OS X Sierra

Tested with VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Dec 6 2016 12:07:41) as well as VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Mar 9 2017 06:42:38). Tested with Safari and Chrome. None of these configurations works for me.

Contents of the temp file /tmp/vim-markdown-preview.html are empty for me.

page empty

Hi,
when I start the previous my file is empty no source code?
Thank you

Consider remove huge images from plugin repository.

Your plugin is huge because of images in the repository. It is the biggest plugin in my vim installation (it's more than 10 times bigger then CtrlP with 450 commits). It's not small as you write in your README.
Consider remove images. And you should clean somehow .git directory after that.

Doesn't work in zsh

At first blush, this doesn't seem to work with neovim. Would be great if it did.

File does get created in /tmp/ but is empty, resulting in blank page for preview.

OSX 10.10.5, Google Chrome, zsh shell

Ctrl-P Opens Tab, but vim-markdown-preview.html is blank (0 Bytes)

file:///tmp/vim-markdown-preview.html opens but shows nothing. Any ideas?

OS is Mac OS X.

Also, what is meant by Markdown is a requirement? What is the proper way to install Markdown.pl? Does the system path have to have the alias markdown=Markdown.pl?

Maybe I am doing something wrong and can add to the README once I figure out what.

does not work on Ubuntu GNOME 14.04.3

ubuntu gnome 14.04.3 x86
vim 7.4.52
Grip 4.0.0
using vundle.

.vimrc

Plugin 'JamshedVesuna/vim-markdown-preview'
let vim_markdown_preview_browser='Firefox'
let vim_markdown_preview_github=1

Open the markdown file in vim. Control + p does not work.
but, next command well do work.

$ grip "test.md" --export /tmp/vim-markdown-preview.html
$ see /tmp/vim-markdown-preview.html &> /dev/null &

Why does not it work? How does it work when?

Add install script

Installation in the documentation is somewhat wordy. Would be great to have an install script that has a few user prompted options, then installs all dependencies based on the system.

Blank preview

I get a blank preview.

macos sierra with safari. latest macvim

automatically removing rendering file.html causes "Your file was not found"

So using the option let vim_markdown_preview_temp_file=1 causes a "Your file was not found" in the browser.
Obviously the file was deleted a bit too soon. This may be due to my configuration. Here is what I am using atm :

" vim-markdown-preview
let vim_markdown_preview_toggle=0 " <C-p> to open preview
let vim_markdown_preview_temp_file=1 " Automatically removes rendering file.html after usage
let vim_markdown_preview_github=1 " Use github API

But if I remove the third line (Use github API), I don't get this error. I get a blank page as expected (I only have grip installed) and after refreshing I get the "File not found" error which is a normal behavior.

Vim flavour : neovim
browser : Google Chrome
OS : (X)ubuntu 16.04.2x64

Also I had some trouble installing grip. As I missed the option relative to github the first time, I tried reinstalling grip which resulted in some error I had to circumvent using pip install --user grip. I don't think this is causing the problem but I may be wrong.

I'm disabling the auto remove until then.

doesn't work if you change buffers

Most of the current code uses buffer scoped variables (b:) but it only sets them on Vim startup. This means if you switch to a new buffer and activate the plugin you get errors like:

Error detected while processing function Vim_Markdown_Preview:
line    3:
E121: Undefined variable: b:curr_file
E116: Invalid arguments for function system
line    8:
E121: Undefined variable: b:vmp_osname
E15: Invalid expression: b:vmp_osname == 'unix'
line   25:
E121: Undefined variable: b:vmp_osname
E15: Invalid expression: b:vmp_osname == 'mac'

b3894e0#commitcomment-16729207

Not working on ubuntu 16.04

First of all, I love this great plugin, and many thanks for all the work.
I've been using it for a while on my ubuntu laptop, and last week, after I went up to the new 16.04 by clean install, I found the plugin started to act weird.
Everytime I hit preview, it ends up with an error message, saying

Error detected while processing function Vim_Markdown_Preview_Local:
line   10:
E484: Can't open file /tmp/vM3gtfz/1
Press ENTER or type command to continue

Correct me if I'm wrong: from what I understand, if I have vim_markdown_preview_temp_file option turned on, the plugin will generate vim-markdown-preview.html in the temp directory, and then opens it.
However, it only manages to generate the html, then fails to open the file.
And the error message says that somehow it's trying to access /tmp/vM3gtfz/1 (name changes every time) , which does not exist.
If I turn the option off, it successfully generates html file in the working directory and successfully open it on the browser, but I'm still get the same error message.

I have installed grip and xdotool.
Here are the relevant part of my current vimrc

let vim_markdown_preview_browser='Google Chrome'
let vim_markdown_preview_hotkey='<leader>r'
let vim_markdown_preview_toggle=1
let vim_markdown_preview_github=1
let vim_markdown_preview_temp_file=0

No see command in my distribution

I'm trying to use this plugin in Slackware. I have xdotool installed and all, but the markdown never shows up in the browser. Is there any way to support distributions which do not have see in them? How about using xdg-open instead, since that is something most distros have?

Error when saving markdown file

The error I receive when saving a markdown file is below. I installed via vundle. My .vimrc

Config specific to plugin

let vim_markdown_preview_browser='Google Chrome'
let vim_markdown_preview_temp_file=1
let vim_markdown_preview_toggle=2
let vim_markdown_preview_github=1

I am also using grip

% pip list | grep grip
grip (3.3.0)
Error detected while processing function Vim_Markdown_Preview_Local:
line   17:
E121: Undefined variable: b:vim_markdown_preview_github
E15: Invalid expression: b:vim_markdown_preview_github == 1
line   41:
E121: Undefined variable: b:vim_markdown_preview_temp_file
E15: Invalid expression: b:vim_markdown_preview_temp_file == 1 

Any help would be great!

Neovim doenst work

It works perfect when opening the document with vim, but it does not renders the page when opening the document with neovim (neovim opens the web-explorer with the page ... but it is blank page).
So, i just open the *.md with vim, but (to mention that) i don't have an specific vim configuration, but the following:
ln -s ~/.config/nvim ~/.vim
ln -s ~/.config/nvim/init.vim ~/.vimrc
so, in vim i am only using the neovim configuration (case this info can be useful).
Cheers,
A.

OS X opens Chrome even when Safari is default

Hi,

Google Chrome is opened despite the default preview setting, and the resulting html file is only loaded in displayed in Safari.

It makes sure chrome is running, if chrome is already running, nothing happens, if chrome is not running, it is launched, which is unwanted behavior.

File Renders; Chromium Doesn't Open File

OS: Arch Linux
Browser: Chromium
Editor: NeoVIM

I'm glad I found your plug in, it's an excellent idea!
Installed fine on NeoVim and installed Markdown and xdotool using pacman package manager.

I checked the /tmp/ dir and I can see the rendered file there but it doesn't open Chromium.
Are there any other debugging techniques I can use to find out what is going on?

Support image loading

When I preview a Markdown document with images, they don't load.

It would be nice if the webapp had a catch-all route that checked for files relative to the markdown-being-previewed.

Clean up installation process

The process in README.md is too cluttered. VMP works out of the box, with additional features. Make a nice grid displaying what global variable maps to what feature when turned on.

xdotool windowactivate does not work in xmonad window manager

You can place this info somewhere for people facing the same problem

For xmonad window manager xdotool windowactivate gives error

Your windowmanager claims not to support _NET_ACTIVE_WINDOW, so the attempt to activate the window was aborted.

The solution is to use XMonad.Hooks.EwmhDesktops in your xmonad configuration file.

Useful links
https://mail.haskell.org/pipermail/xmonad/2008-November/006770.html
https://mail.haskell.org/pipermail/xmonad/2008-November/006773.html
http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-EwmhDesktops.html
http://www.ohspite.net/posts/keepass-global-autotype-in-xmonad/

Split preview on buffer write and image rendering

Currently, both on buffer write and image rendering are captured in the same option, vim_markdown_preview_toggle. This should be split into two separate options:

vim_markdown_preview_image and vim_markdown_preview_write.

Remove browser latency and check pid

Instead of sleeping, check if the pid of BROWSER is active and remove the tmp file accordingly. If possible, check if the new tab has been created.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.