Skip to content

Commit

Permalink
Add <Plug> preview toggle (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
cabaalexander authored and iamcco committed Apr 29, 2019
1 parent c3b66b8 commit 3d53616
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ let g:mkdp_port = ''
let g:mkdp_page_title = '「${name}」'
```

Mappings:

```vim
" normal/insert
<Plug>MarkdownPreview
<Plug>MarkdownPreviewStop
<Plug>MarkdownPreviewToggle
" example
nmap <C-s> <Plug>MarkdownPreview
nmap <M-s> <Plug>MarkdownPreviewStop
nmap <C-p> <Plug>MarkdownPreviewToggle
```

Commands:

```vim
Expand Down
10 changes: 10 additions & 0 deletions autoload/mkdp/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,13 @@ function! mkdp#util#pre_build_version() abort
return ''
endfunction

function! mkdp#util#toggle_preview() abort
if !get(b:, 'MarkdownPreviewToggleBool')
call mkdp#util#open_preview_page()
let b:MarkdownPreviewToggleBool=1
else
call mkdp#util#stop_preview()
let b:MarkdownPreviewToggleBool=0
endif
endfunction

21 changes: 13 additions & 8 deletions plugin/mkdp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,24 @@ endif

function! s:init_command() abort
" mapping for user
map <buffer> <silent> <Plug>MarkdownPreview :call mkdp#util#open_preview_page()<CR>
imap <buffer> <silent> <Plug>MarkdownPreview <Esc>:call mkdp#util#open_preview_page()<CR>a
map <buffer> <silent> <Plug>MarkdownPreviewStop :call mkdp#util#stop_preview()<CR>
imap <buffer> <silent> <Plug>MarkdownPreviewStop <Esc>:call mkdp#util#stop_preview()<CR>a
noremap <buffer> <silent> <Plug>MarkdownPreview :call mkdp#util#open_preview_page()<CR>
inoremap <buffer> <silent> <Plug>MarkdownPreview <Esc>:call mkdp#util#open_preview_page()<CR>a
noremap <buffer> <silent> <Plug>MarkdownPreviewStop :call mkdp#util#stop_preview()<CR>
inoremap <buffer> <silent> <Plug>MarkdownPreviewStop <Esc>:call mkdp#util#stop_preview()<CR>a
nnoremap <buffer> <silent> <Plug>MarkdownPreviewToggle :call mkdp#util#toggle_preview()<CR>
inoremap <buffer> <silent> <Plug>MarkdownPreviewToggle <Esc>:call mkdp#util#toggle_preview()<CR>
endfunction

function! s:MkdpAU() abort
command! -buffer MarkdownPreview call mkdp#util#open_preview_page()
call s:init_command()
endfunction

function! s:init() abort
if g:mkdp_command_for_global
au BufEnter * command! -buffer MarkdownPreview call mkdp#util#open_preview_page()
call s:init_command()
au BufEnter * :call s:MkdpAU()
else
au BufEnter *.{md,mkd,markdown,mdown,mkdn,mdwn} command! -buffer MarkdownPreview call mkdp#util#open_preview_page()
call s:init_command()
au BufEnter *.{md,mkd,markdown,mdown,mkdn,mdwn} :call s:MkdpAU()
endif
if g:mkdp_auto_start
au BufEnter *.{md,mkd,markdown,mdown,mkdn,mdwn} call mkdp#util#open_preview_page()
Expand Down

0 comments on commit 3d53616

Please sign in to comment.