ciplogic.com
Live with grace. Write superb software.

Do you want your editing of AsciiDoc (or Markdown) to look like this?

In order to get AsciiDoc support working nicely in VIM, you'll need a couple of things:

  • asciidoc-vim: (the syntax highlight support)
  • SyntaxRange: (to enable text ranges to be highlighted with different syntax files)
    • ingo-library: (not really documented, but this is a dependency for SyntaxRange)

Then add another syntax file for AsciiDoc, by creating another plugin, with just the /syntax folder in it. (If you use pathogen, it should look something like this). In it configure your SyntaxRange plugin for matching for various languages:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function! AsciidocEnableSyntaxRanges()
" source block syntax highlighting
if exists('g:loaded_SyntaxRange')
  for lang in ['c', 'python', 'vim', 'javascript', 'cucumber', 'xml', 'typescript', 'sh', 'java', 'cpp', 'sh']
    call SyntaxRange#Include(
          \  '\c\[source\s*,\s*' . lang . '.*\]\s*\n[=-]\{4,\}\n'
          \, '\]\@<!\n[=-]\{4,\}\n'
          \, lang, 'NonText')
  endfor
 
  call SyntaxRange#Include(
        \  '\c\[source\s*,\s*gherkin.*\]\s*\n[=-]\{4,\}\n'
        \, '\]\@<!\n[=-]\{4,\}\n'
        \, 'cucumber', 'NonText')
endif
endfunction
 
call AsciidocEnableSyntaxRanges()

The gherkin one, is there separately, since for the gherkin language, we're going to use the cucumber syntax file.

Since the SyntaxRange registration it's in the syntax file, it will only activate when editing asciidoc files.

Enjoy :)

PS: I inspired for the SyntaxRange calls from dahu's vim-asciidoc, but I just rewrote the RegExp to better match the start of the source.

PS2: For doing live html visualising of the file, you can use fast-live-reload:

1
2
3
4
5
6
fast-live-reload test.adoc -e "asciidoctor test.adoc" -nn test.html
1. Will notify the changes for clients on port 9001
2. and will serve the content from test.adoc on port 9000
3. and will monitor and execute when files change in subfolders:
   a: test.adoc -> asciidoctor test.adoc (no refresh)
   b: test.html    

Then just open the http://localhost:9000/test.html in the browser and watch it change as you save.

PS3: In the screenshot there is also vim-airline installed with the powerline fonts active.

PS4: For Markdown you need another syntax file, and different regexps for matching code blocks.

Disqus Comments

comments powered by Disqus

Germanium

The one to rule them all. The browsers that is.

SharpKnight

SharpKnight is an Android chess game.

MagicGroup

MagicGroup is an eclipse plugin.