Code Monkey home page Code Monkey logo

vim-crystal's Introduction

Introduction

This was originally a fork of vim-crystal that discarded many of the original's features in order to study how syntax highlighting and indentation could be improved. It turned into a complete rewrite of the original plugin and merging my changes was no longer feasible, so I decided to move it to a separate repository for anyone who wants a faster and more accurate alternative to the original vim-crystal.

This plugin includes support for embedded crystal (ECR).

Installation

This is a standard Vim plugin which can be installed using your plugin manager of choice. If you do not already have a plugin manager, I recommend vim-plug.

Configuration

g:crystal_simple_indent

The default indentation style used by this plugin is the one most commonly found in the Crystal community, which allows for "hanging" or "floating" indentation. Some examples:

x = if y
      5
    else
      10
    end

x = begin
      h["foo"]
    rescue KeyError
      "Not found"
    end

x = case y
    when :foo
      5
    when :bar
      10
    else
      1
    end

x = [:foo, :bar,
     :baz, :qux]

x = 5 + 10 +
    15 + 20 -
    5 * 3

x = y.foo
     .bar
     .baz

For those who prefer a more traditional indentation style or who desire slightly faster highlighting and indentation, set g:crystal_simple_indent to 1. The above examples will now be indented thus:

x = if y
  5
else
  10
end

x = begin
  h["foo"]
rescue KeyError
  "Not Found"
end

x = case y
when :foo
  5
when :bar
  10
else
  1
end

x = [:foo, :bar,
  :baz, :qux]
# OR
x = [
  :foo, :bar,
  :baz, :qux
]

x = 5 + 10 +
  15 + 20 -
  5 * 3
# OR
x =
  5 + 10 +
  15 + 20 -
  5 * 3

x = y.foo
  .bar
  .baz
# OR
x = y
  .foo
  .bar
  .baz

g:crystal_markdown_comments

This variable controls whether or not Markdown should be highlighted in comments; it can have three possible values:

  • 0: Disabled (default)
  • 1: Enabled
  • 2: Enabled; additionally, code lines โ€” that is, lines that begin with at least four spaces or one tab or are inside of a fenced code block (delimited with ``` or ~~~) โ€” will be highlighted as Crystal code unless the language for the block is set to anything other than crystal (good for writing documentation)

Setting to 1 or 2 may cause highlighting to become slower in files with lots of comments.

NOTE: I haven't yet been able to find an exhaustive summary of which Markdown features are supported by Crystal, so for now, only the basic features are supported in addition to fenced code blocks (delimited with ``` or ~~~).

Additionally, the only decorations that are currently allowed to span multiple lines are fenced code blocks. For example, the following will not be highlighted properly:

# `1 + 2 +
# 3`

But this will:

# ```
# 1 + 2 +
# 3
# ```

g:ecrystal_extensions

This plugin uses a dictionary of filetype extensions to determine which filetype to use when loading ECR files. For example, opening a file named foo.html.ecr will load HTML as the filetype with ECR syntax added on top.

The default recognized filetype extensions are as follows:

.html => html
.js => javascript

Each extension maps to the name of the filetype that you want to load for that extension.

To add or overwrite entries in the dictionary, set g:ecrystal_extensions to a dictionary with the entries you want to inject. For example, the following would allow the plugin to recognize *.md files as Markdown:

let g:ecrystal_extensions = #{ md: "markdown" }

If no subtype is specified in the file name itself (e.g., foo.ecr), the value of g:ecrystal_default_subtype is used as the subtype.

g:ecrystal_default_subtype

Determines the default subtype to use for ECR files when no subtype is specified in the file name itself (e.g., foo.ecr).

The default value is html. Setting this to nothing (let g:ecrystal_default_subtype = "") will cause no subtype to be used.

vim-crystal's People

Contributors

jlcrochet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vim-crystal's Issues

Error while moving to matching block

Everytime I try to navigate to matching block (i.e. when pressing %) I get a bunch of errors:

Error detected while processing function matchit#Match_wrapper[84]..<SNR>73_Wholematch:
line    5:
E866: (NFA regexp) Misplaced @
Error detected while processing function matchit#Match_wrapper:
line   85:
E866: (NFA regexp) Misplaced @
Press ENTER or type command to continue

I'm running neovim v0.5.0 and crystal 1.1.1 if that helps, if you need any more info I'll gladly provide it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.