~dricottone/vim-markdown-preview

ref: 4e0925333c54ebf9666bfbe452d666a356585060 vim-markdown-preview/README.md -rw-r--r-- 6.1 KiB
4e092533 — Torben Add preview browser name to OSX open call 8 years ago
                                                                                
906c7a8f Jamshed Vesuna
ad69b9ce JamshedVesuna
956b1542 JamshedVesuna
ad69b9ce JamshedVesuna
1135b27a JamshedVesuna
ad69b9ce JamshedVesuna
1135b27a JamshedVesuna
ad69b9ce JamshedVesuna
cf2cc781 JamshedVesuna
ad69b9ce JamshedVesuna
cf2cc781 JamshedVesuna
ad69b9ce JamshedVesuna
cf2cc781 JamshedVesuna
ad69b9ce JamshedVesuna
b51ecf2c JamshedVesuna
cf2cc781 JamshedVesuna
ad69b9ce JamshedVesuna
2d5e5346 Jamshed Vesuna
ad69b9ce JamshedVesuna
b51ecf2c JamshedVesuna
2d5e5346 Jamshed Vesuna
5ab8e9af Oleksandr Shybystyi
906c7a8f Jamshed Vesuna
ad69b9ce JamshedVesuna
bba8b829 JamshedVesuna
ad69b9ce JamshedVesuna
2d5e5346 Jamshed Vesuna
ad69b9ce JamshedVesuna
906c7a8f Jamshed Vesuna
ad69b9ce JamshedVesuna
538ea4f8 JamshedVesuna
bba8b829 JamshedVesuna
ad69b9ce JamshedVesuna
6f05ab3c Jamshed Vesuna
956b1542 JamshedVesuna
2d5e5346 Jamshed Vesuna
ad69b9ce JamshedVesuna
538ea4f8 JamshedVesuna
ad69b9ce JamshedVesuna
538ea4f8 JamshedVesuna
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
Vim Markdown Preview
====================

- [Intro](#intro)
- [Installation](#installation)
- [Usage](#usage)
- [Requirements](#requirements)
    - [Max OS X](#mac-os-x)
    - [Unix](#unix)
- [Options](#options)
    - [Image rendering & save on buffer write](#toggle)
    - [Hotkey](#hotkey)
    - [Browser](#browser)
    - [Temp File](#temp)
    - [Github Flavoured Markdown](#github)
    - [Use xdg-open](#xdg)
- [Behind the Scenes](#behind-the-scenes)

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](images/screenshot.gif?raw=true "Preview on buffer write using Unix")

Installation
------------

* With [Pathogen](https://github.com/tpope/vim-pathogen): Place `vim-markdown-preview/` in `.vim/bundle/`.
* With [Vundle](https://github.com/VundleVim/Vundle.vim):
    * Add `Plugin 'JamshedVesuna/vim-markdown-preview'` to your `.vimrc`.
    * Launch `vim` and run `:PluginInstall`

See more [Options](#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](#options)).

Your cursor will remain in Vim.

Requirements
------------

### Mac OS X:

* [Markdown](http://daringfireball.net/projects/markdown/) or [grip](https://github.com/joeyespo/grip) (for [GitHub flavoured markdown](#github))
    * If using Grip, put `let vim_markdown_preview_github=1` in your `.vimrc` file
* [Safari](https://www.apple.com/safari/)

### Unix:

* [Markdown](http://daringfireball.net/projects/markdown/) or [grip](https://github.com/joeyespo/grip) (for [GitHub flavoured markdown](#github))
    * If using Grip, put `let vim_markdown_preview_github=1` in your `.vimrc` file
* [xdotool](https://github.com/jordansissel/xdotool)
* [Google Chrome](https://www.google.com/chrome/browser/) or [other browser](https://github.com/JamshedVesuna/vim-markdown-preview/wiki/Use-other-browser-to-preview-markdown#ubuntu-or-debian)

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](http://vim.wikia.com/wiki/Open_vimrc_file) file.
Note that after changing an option, you have to restart Vim for the change to take effect.

<a name='toggle'></a>
### The `vim_markdown_preview_toggle` option

This option does two things (to be fixed by [#17](https://github.com/JamshedVesuna/vim-markdown-preview/issues/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](#hotkey) mapping (defaults to Control p).
```vim
let vim_markdown_preview_toggle=1
```

Example: To display images automatically on buffer write.
```vim
let vim_markdown_preview_toggle=2
```

Example: To disregard images and still automatically preview on buffer write.
```vim
let vim_markdown_preview_toggle=3
```

<a name='hotkey'></a>
### 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.
```vim
let vim_markdown_preview_hotkey='<C-m>'
```

<a name='browser'></a>
### The `vim_markdown_preview_browser` option

By default, if you are using Unix, [Google Chrome](https://www.google.com/chrome/) is the default browser. If you are on Mac OS X, [Safari](https://www.apple.com/safari/) is the default.
Note that bug [#16](https://github.com/JamshedVesuna/vim-markdown-preview/issues/16) does not allow cross operating system and browser support. See the [wiki page](https://github.com/JamshedVesuna/vim-markdown-preview/wiki/Use-other-browser-to-preview-markdown) for more help.

Default: `'Google Chrome'`

Example: Using Google Chrome.
```vim
let vim_markdown_preview_browser='Google Chrome'
```

<a name='temp'></a>
### 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.
```vim
let vim_markdown_preview_temp_file=1
```

<a name='github'></a>
### The `vim_markdown_preview_github` option

If you prefer [GitHub flavoured markdown](https://help.github.com/articles/github-flavored-markdown/) you need to install [Python grip](https://github.com/joeyespo/grip). Note that this makes a request to [GitHub's API](https://developer.github.com/v3/markdown/) (causing latencies) and may require [authentication](https://github.com/joeyespo/grip#access). This option also requires a network connection.

Default: `0`

Example: Use GitHub flavoured markdown.
```vim
let vim_markdown_preview_github=1
```

<a name='xdg'></a>
### 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
-----------------

1. First, this plugin renders your markdown as html and creates a temporary html file.
    * If [image rendering](#toggle) is on, the html file will be in your [working directory](https://en.wikipedia.org/wiki/Working_directory).
    * Otherwise, it will be in `/tmp/`.
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.

![Screenshot](images/screenshot-with-images.gif?raw=true "Render images and preview on buffer write using Mac OS X")