Giter VIP home page Giter VIP logo

indent-o-matic's Introduction

indent-o-matic

Dumb automatic fast indentation detection for Neovim written in Lua

How it works

Instead of trying to be smart about detecting an indentation using statistics, it will find the first thing that looks like a standard indentation (tab or 8/4/2 spaces) and assume that's what the file's indentation is

This has the advantage of being fast and very often correct while being simple enough that most people will understand what it will do predictably

Requirements

  • Neovim >= 0.4.4

Installation

Can be installed through any standard Vim package manager, configuration is optional

E.g. through vim-plug:

call plug#begin()
    Plug 'Darazaki/indent-o-matic'
call plug#end()

Then restart Neovim and run :PlugInstall

Configuration

Configuration is done in Lua:

require('indent-o-matic').setup {
    -- The values indicated here are the defaults

    -- Number of lines without indentation before giving up (use -1 for infinite)
    max_lines = 2048,

    -- Space indentations that should be detected
    standard_widths = { 2, 4, 8 },

    -- Skip multi-line comments and strings (more accurate detection but less performant)
    skip_multiline = true,
}

You can also directly configure it from a Vim file by using the lua instruction:

lua <<EOF
require('indent-o-matic').setup {
    -- ...
}
EOF

Optionally you can define language-specific settings using the filetype_$ft tables:

require('indent-o-matic').setup {
    -- Global settings (optional, used as fallback)
    max_lines = 2048,
    standard_widths = { 2, 4, 8 },

    -- Disable indent-o-matic for LISP files
    filetype_lisp = {
        max_lines = 0,
    },

    -- Only detect 4 spaces and tabs for Rust files
    filetype_rust = {
        standard_widths = { 4 },
    },

    -- Don't detect 8 spaces indentations inside files without a filetype
    filetype_ = {
        standard_widths = { 2, 4 },
    },
}

If a preference hasn't been set in the language-specific settings, it'll be retrieved from the global settings

:IndentOMatic is also made available to detect the current buffer's indentation on demand

If you want this plugin to only be invoked manually through :IndentOMatic, you can add autocmd! indent_o_matic to your init file

Alternatives

Contributing

I've made this little plugin as a fun side-project to learn how Lua works with Neovim as a beginner so, if you've an idea, feel free to write a PR to improve this project!

The only rules to follow are:

  • PRs should go to the testing branch (for, well, testing if everything still works)
  • The detection algorithm should stay dumb
  • The plugin itself should work with Lua & Vim code only
  • No configuration required
  • System requirements shouldn't be restricted
  • Break the rules within reason

Note: Forking or taking part of the code without asking is also a-ok, this is libre MIT-licensed stuff!

indent-o-matic's People

Contributors

darazaki avatar andrewmustea avatar axelvc avatar thehunmonkgroup avatar jandamm avatar rstacruz avatar wuelnerdotexe avatar

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.