/asciidoc-preview.vim

An asciidoc plugin for vim to show html file in web browser!

Primary LanguageCSSApache License 2.0Apache-2.0

Asciidoctor Preview for vim

💡
This project inspired by markdown-preview.vim.
📎

Q: The Firefox preview window didn’t close when leaving the Asciidoc file from Vim.
A: If you want the plugin to auto-close the preview window in Firefox, you have to change configuration:

1.Open Firefox.
2.Type `about:config` in the address bar and press the Enter key.
3.Search for `dom.allow_scripts_to_close_windows` and set its value to true.

Compatible OS

  • Linux

  • Mac OS

  • Windows

Description

[中文版] Preview asciidoc on your modern browser with synchronized scrolling and flexible configuration. Your asciidoc file must end with suffixes like:

Table 1. Suffixes
1 2 3

.ad

.asc

.asd

.ascd

.adoc

.asciidoc

Vim version

  • ✓ Vim >= 8.0

Main features

  1. Local images

  2. Multi-platforms

  3. Synchronised scrolling

  4. Fast asynchronous updates

  5. Flexible configuration

Installation

With vumdle:

Add Plugin QMHTMY/asciidoc-preview.vim to the ~/.vimrc or init.vim file and type :PlugInstall.

Plugin `QMHTMY/asciidoc-preview.vim`

Usage

Command

AsciidocPreview
" Open preview window in asciidoc buffer
AsciidocPreviewStaop
" Close preview window and server

Default Setting:

 let g:asdp_path_to_chrome = ""
" Path to the chrome or the command to open chrome (or other modern browsers).
" If set, g:asdp_browserfunc would be ignored.
let g:asdp_browserfunc = 'ASDP_browserfunc_default'
" Callback Vim function to open browser, the only parameter is the url to open.
let g:asdp_auto_start = 0
" Set to 1, Vim will open the preview window on entering the Asciidoc
" buffer.
let g:asdp_auto_open = 0
" Set to 1, Vim will automatically open the preview window when you edit an
" Asciidoc file.
let g:asdp_auto_close = 1
" Set to 1, Vim will automatically close the current preview window when
" switching from one Asciidoc buffer to another.
let g:asdp_refresh_slow = 0
" Set to 1, Vim will just refresh Asciidoc when saving the buffer or
" leaving from insert mode. With default 0, it will automatically refresh
" Asciidoc as you edit or move the cursor.
let g:asdp_command_for_global = 0
" Set to 1, the AsciidocPreview command can be used for all files,
" by default it can only be used in Asciidoc files.
let g:asdp_open_to_the_world = 0
" Set to 1, the preview server will be available to others in your network.
" By default, the server only listens on localhost (127.0.0.1).

Mapping

By default this plugin has no mapping: if you want to have your own mappings, you can map the keys to
<Plug>AsciidocPreview for opening the Asciidoc preview window and map keys to <Plug>StopAsciidocPreview
for closing the preview window.

Examples for mapping the F8 key to open Asciidoc preview window and F9 key to close preview window:

" for normal mode
nmap <silent> <F8> <Plug>AsciidocPreview
" for insert mode
imap <silent> <F8> <Plug>AsciidocPreview
" for normal mode
nmap <silent> <F9> <Plug>StopAsciidocPreview
" for insert mode
imap <silent> <F9> <Plug>StopAsciidocPreview

For OS X users, you can set the g:asdp_path_to_chrome as below (if you use Chrome):

let g:asdp_path_to_chrome = "open -a Google\\ Chrome"
" or
let g:asdp_path_to_chrome = "/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome"

Reference

Copyright © 2019-2020 Shieber.
See the LICENSE file for free use of this script granted under the terms of the Apache License.