Giter Club home page Giter Club logo

nvim-trevj.lua's Introduction

nvim-trevJ.lua

โš ๏ธ This plugin is in an early stage and docs is a bit sparse. Feel free to try it out though and let me know if you have any problems/suggestions.

Nvim-plugin for doing the opposite of join-line (J) of arguments, powered by treesitter. The intention of the plugin is the same as revJ. However trevJ uses treesitter to figure out the formatting and in general does everything much more efficient and better, while not polluting registers, last visual selection etc. My intention is that anyone using revJ should have a smooth transfer to trevJ but both configuration and usage will necessarily be somewhat different and instead of making a breaking change for revJ I decided to make a new plugin. Also since it's anyway a complete re-write of the code.

Installation

For example using packer:

use {
  'AckslD/nvim-trevJ.lua',
  config = 'require("trevj").setup()',  -- optional call for configurating non-default filetypes etc

  -- uncomment if you want to lazy load
  -- module = 'trevj',

  -- an example for configuring a keybind, can also be done by filetype
  -- setup = function()
  --   vim.keymap.set('n', '<leader>j', function()
  --     require('trevj').format_at_cursor()
  --   end)
  -- end,
}

Configuration

When configuring a language you should specify the treesitter node types that contains the child nodes which should be put on separate lines. For example for the default configuration for lua looks as follows:

require('trevj').setup({
  containers = {
    lua = {
      table_constructor = {final_separator = ',', final_end_line = true},
      arguments = {final_separator = false, final_end_line = true},
      parameters = {final_separator = false, final_end_line = true},,
    },
    ... -- other filetypes
  },
})

where:

  • final_separator: if truthy adds this character after the final child node if not existing.
  • final_end_line: if there should be a final line before the and character of the container node.
  • skip (optional): a table where keys correspond to children types to not put on newlines and values are truthy. For example, the default config for html is:
    html = {
      start_tag = {
        final_separator = false,
        final_end_line = true,
        skip = {tag_name = true},
      },
    }
    in order to not put the tag_name on a new line.

For existing languages you can override anything and defaults will be used for anything unspecified.

Supported Languages

Currently only the following languages are supported by default:

  • c
  • go
  • html
  • lua
  • python
  • ruby
  • rust

You can add your own, of even better submit a PR for your favorite language.

Examples

default

{final_separator = ',', final_end_line = true}

becomes

{
  final_separator = ',',
  final_end_line = true,
}

no final separator

{final_separator = false, final_end_line = true}

becomes

{
  final_separator = false,
  final_end_line = true
}

no final separator, no final line

{final_separator = false, final_end_line = false}

becomes

{
  final_separator = false,
  final_end_line = false}

Usage

Call require('trevj').format_at_cursor() or bind a key to it. Note that you need to be inside the container treesitter node, otherwise a warning will be given.

nvim-trevj.lua's People

Contributors

acksld avatar akinsho avatar davidgranstrom avatar kylechui avatar owst 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.