Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit e1e0138

Browse files
committed
support key mapping and new g:mkdp_command_for_global option
1 parent b7f2a2c commit e1e0138

File tree

4 files changed

+101
-5
lines changed

4 files changed

+101
-5
lines changed

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ Use the markdown-preview.vim plugin you can preview markdown on real-time
66
through a browser
77

88
> this plugin need your vim support py2/py3 features
9-
> test on windows/ubuntu14
9+
> test on windows/ubuntu14/Mac OS X
1010
1111

1212
### screenshot
1313

14-
![screenshot](./screenshot.gif)
14+
![screenshot](https://cloud.githubusercontent.com/assets/5492542/15363504/839753be-1d4b-11e6-9ac8-def4d7122e8d.gif)
1515

1616
### Installation
1717

@@ -57,6 +57,26 @@ MarkdownPreviewStop command before using MarkdownPreview command
5757
" set to 1, the vim will just refresh markdown when save the buffer or
5858
" leave from insert mode, default 0 is auto refresh markdown as you edit or
5959
" move the cursor
60+
61+
let g:mkdp_command_for_global = 0
62+
" set to 1, the MarkdownPreview command can be use for all files,
63+
" by default it just can be use in markdown file
64+
```
65+
66+
**Key Mapping:**
67+
68+
By default this Plugin has no mapping, if you want to has your own mapping
69+
you can map the keys to `<Plug>MarkdownPreview` for opening markdown preview window and
70+
map keys to `<Plug>StopMarkdownPreview` for closing the preview window
71+
72+
Examples for mapping the `F8` key to open markdown preview window and `F9` key to
73+
close preview window:
74+
75+
```
76+
nmap <silent> <F8> <Plug>MarkdownPreview " for normal mode
77+
imap <silent> <F8> <Plug>MarkdownPreview " for insert mode
78+
nmap <silent> <F9> <Plug>StopMarkdownPreview " for normal mode
79+
imap <silent> <F9> <Plug>StopMarkdownPreview " for insert mode
6080
```
6181

6282
For **OS X** users you can set the `g:mkdp_path_to_chrome` as below (if you use chrome):
@@ -70,6 +90,7 @@ see issue[#1](https://github.com/iamcco/markdown-preview.vim/issues/1) for detai
7090

7191
### Changelog
7292

93+
* 2016/05/18: support key mapping and new `g:mkdp_command_for_global` option item
7394
* 2016/03/12: new Github like markdown styles [markdown.css](https://github.com/iamcco/markdown.css) and support task list
7495
* 2016/01/24: support display the local picture in markdown
7596

@@ -123,6 +144,25 @@ see issue[#1](https://github.com/iamcco/markdown-preview.vim/issues/1) for detai
123144
let g:mkdp_refresh_slow = 0
124145
" 设置为 1 则只有在保存文件,或退出插入模式的时候更新预览,默认为 0,实时
125146
" 更新预览
147+
148+
let g:mkdp_command_for_global = 0
149+
" 设置为 1 则所有文件都可以使用 MarkdownPreview 进行预览,默认只有 markdown
150+
" 文件可以使用改命令
151+
```
152+
153+
**键位绑定:**
154+
155+
默认情况下,插件没有进行任何的按键绑定,如果想绑定按键去预览 markdown 文件,可以绑定
156+
按键到`<Plug>MarkdownPreview`来打开预览窗口,绑定按键到`<Plug>StopMarkdownPreview`
157+
关闭预览窗口。
158+
159+
按键绑定例子(`F8`打开预览窗口,`F9`关闭预览窗口):
160+
161+
```
162+
nmap <silent> <F8> <Plug>MarkdownPreview " 普通模式
163+
imap <silent> <F8> <Plug>MarkdownPreview " 插入模式
164+
nmap <silent> <F9> <Plug>StopMarkdownPreview " 普通模式
165+
imap <silent> <F9> <Plug>StopMarkdownPreview " 插入模式
126166
```
127167

128168
**苹果** 用户如果使用chrome可以参照以下设置 `g:mkdp_path_to_chrome`:
@@ -136,6 +176,7 @@ let g:mkdp_path_to_chrome = "/Applications/Google\\ Chrome.app/Contents/MacOS/Go
136176

137177
### Changelog
138178

179+
* 2016/05/18: 支持按键绑定,并增加新的 `g:mkdp_command_for_global` 配置项
139180
* 2016/03/12: 使用新的 Github 样式 [markdown.css](https://github.com/iamcco/markdown.css),并且支持显示 todo 任务列表
140181
* 2016/01/24: 支持显示本地图片
141182

doc/mkdp.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ Defaul Setting:
4747
leave from insert mode, default 0 is auto refresh markdown as you edit or
4848
move the cursor
4949

50+
let g:mkdp_command_for_global = 0
51+
" set to 1, the MarkdownPreview command can be use for all files,
52+
" by default it just can be use in markdown file
53+
54+
Key Mapping:
55+
56+
By default this Plugin has no mapping, if you want to has your own mapping
57+
you can map the keys to <Plug>MarkdownPreview for opening markdown preview window and
58+
map keys to <Plug>StopMarkdownPreview for closing the preview window
59+
60+
Examples for mapping the F8 key to open markdown preview window and F9 key to
61+
close preview window:
62+
63+
nmap <silent> <F8> <Plug>MarkdownPreview " for normal mode
64+
imap <silent> <F8> <Plug>MarkdownPreview " for insert mode
65+
nmap <silent> <F9> <Plug>StopMarkdownPreview " for normal mode
66+
imap <silent> <F9> <Plug>StopMarkdownPreview " for insert mode
67+
5068
================================================================================
5169

5270
说明 *mkdp-introduction-zh*
@@ -87,3 +105,20 @@ Defaul Setting:
87105
g:mkdp_refresh_slow = 0
88106
" 设置为 1 则只有在保存文件,或退出插入模式的时候更新预览,默认为 0,实时
89107
更新预览
108+
109+
let g:mkdp_command_for_global = 0
110+
" 设置为 1 则所有文件都可以使用 MarkdownPreview 进行预览,默认只有 markdown
111+
" 文件可以使用改命令
112+
113+
键位绑定:
114+
115+
默认情况下,插件没有进行任何的按键绑定,如果想绑定按键去预览 markdown 文件,可以绑定
116+
按键到 <Plug>MarkdownPreview 来打开预览窗口,绑定按键到 <Plug>StopMarkdownPreview 来
117+
关闭预览窗口。
118+
119+
按键绑定例子(F8打开预览窗口,F9关闭预览窗口):
120+
121+
nmap <silent> <F8> <Plug>MarkdownPreview " 普通模式
122+
imap <silent> <F8> <Plug>MarkdownPreview " 插入模式
123+
nmap <silent> <F9> <Plug>StopMarkdownPreview " 普通模式
124+
imap <silent> <F9> <Plug>StopMarkdownPreview " 插入模式

plugin/mkdp.vim

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ if !exists('g:mkdp_refresh_slow')
3939
let g:mkdp_refresh_slow = 0
4040
endif
4141

42+
if !exists('g:mkdp_command_for_global')
43+
let g:mkdp_command_for_global = 0
44+
endif
45+
4246
let g:mkdp_server_started = 0
4347

4448
fu! s:serverStart() abort
@@ -73,19 +77,35 @@ fun! s:serverClose() abort
7377
endfor
7478
let g:mkdp_server_started = 0
7579
let g:mkdp_bufs = {}
76-
delcommand MarkdownPreviewStop
80+
if exists(':MarkdownPreviewStop')
81+
delcommand MarkdownPreviewStop
82+
endif
7783
endfu
7884

7985
if g:mkdp_auto_start
8086

8187
"if auto start, launch the server when enter the mkd buffer
8288

83-
au BufEnter *.{md,mkd,markdown,mdown,mkdn,mdwn} call s:serverStart()
89+
if g:mkdp_command_for_global
90+
au BufEnter * call s:serverStart()
91+
else
92+
au BufEnter *.{md,mkd,markdown,mdown,mkdn,mdwn} call s:serverStart()
93+
endif
8494
endif
8595

8696
"define the command to start the server when enter the mkd buffer
8797

88-
au BufEnter *.{md,mkd,markdown,mdown,mkdn,mdwn} command! -buffer MarkdownPreview call s:serverStart()
98+
if g:mkdp_command_for_global
99+
au BufEnter * command! -buffer MarkdownPreview call s:serverStart()
100+
else
101+
au BufEnter *.{md,mkd,markdown,mdown,mkdn,mdwn} command! -buffer MarkdownPreview call s:serverStart()
102+
endif
103+
104+
" mapping for user
105+
map <silent> <Plug>MarkdownPreview :call <SID>serverStart()<CR>
106+
imap <silent> <Plug>MarkdownPreview <Esc>:call <SID>serverStart()<CR>a
107+
map <silent> <Plug>StopMarkdownPreview :if exists(':MarkdownPreviewStop') \| exec 'MarkdownPreviewStop ' \| endif<CR>
108+
imap <silent> <Plug>StopMarkdownPreview <Esc>:if exists(':MarkdownPreviewStop') \| exec 'MarkdownPreviewStop ' \| endif<CR>a
89109
90110
"-------------------------------------------------------------------------------
91111
let &cpo = s:save_cpo

screenshot.gif

-2.91 MB
Binary file not shown.

0 commit comments

Comments
 (0)